public void generate() { scanMethodAnnotation(); scanMethodParameters(); scanResponse(); checkBodyParameter(); copyToSwaggerParameters(); operation.setParameters(swaggerParameters); correctOperation(); }
private static void hoistParameter(Parameter pathParameter, Operation operation) { if (pathParameter instanceof RefParameter) { return; // can't hoist unresolvable ref parameter } List<Parameter> parameters = operation.getParameters(); if (parameters != null) { for (Parameter parameter : parameters) { if (parameter instanceof RefParameter) { continue; // can't compare to unresolvable ref parameter } if (parameter.getName().equals(pathParameter.getName()) && parameter.getIn().equals(pathParameter.getIn())) { return; } } } else { parameters = Lists.newArrayList(); operation.setParameters(parameters); } parameters.add(pathParameter); } }
operation.setParameters(parameters);
private io.swagger.models.Operation opCreateInstance(ServiceDocument doc) { io.swagger.models.Operation op = new io.swagger.models.Operation(); op.addTag(this.currentTag.getName()); op.setParameters(Collections.singletonList(paramBody(doc))); op.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(doc) )); return op; }
public void processOperation(Operation operation) { final List<Parameter> processedOperationParameters = parameterProcessor.processParameters(operation.getParameters()); operation.setParameters(processedOperationParameters); final Map<String, Response> responses = operation.getResponses(); if (responses != null) { for (String responseCode : responses.keySet()) { Response response = responses.get(responseCode); if(response != null) { if (response instanceof RefResponse) { RefResponse refResponse = (RefResponse) response; responseProcessor.processResponse(response); Response resolvedResponse = cache.loadRef(refResponse.get$ref(), refResponse.getRefFormat(), Response.class); if (resolvedResponse != null) { response = resolvedResponse; responses.put(responseCode, resolvedResponse); } } responseProcessor.processResponse(response); } } } } }
private Map<String, Path> getPaths() { Map<String, Path> paths = new HashMap<>(); Path path = new Path(); Operation post = new Operation(); post.setOperationId("configure"); post.setConsumes(Arrays.asList("application/json", "application/xml")); post.setProduces(Arrays.asList("application/json", "application/xml")); List<Parameter> parameters = new ArrayList<>(); Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); in.setRequired(true); in.setName(INPUTS); parameters.add(in); post.setParameters(parameters); Map<String, Response> responses = new HashMap<>(); Response response = new Response().description("Success"); responses.put("200", response); Response failureResponse = new Response().description("Failure"); responses.put("400", failureResponse); post.setResponses(responses); path.setPost(post); paths.put("/operations/config-selfservice-api:configure", path); return paths; }
public void generate() { scanMethodAnnotation(); scanMethodParameters(); scanResponse(); checkBodyParameter(); copyToSwaggerParameters(); operation.setParameters(swaggerParameters); correctOperation(); }
@Override public void operation(HttpMethod httpMethod, Operation operation) { operation.setTags(fillList(operation.getTags())); operation.setParameters(fillList(operation.getParameters())); operation.setResponses(fillMap(operation.getResponses())); operation.setSchemes(fillList(operation.getSchemes())); }
operation.setParameters(parameterList); operation.setOperationId(uriTemplate.getTemplateId()); operation.addResponse("200", getDefaultResponse());
operation.setParameters(parameterList); operation.setOperationId(uriTemplate.getTemplateId()); operation.addResponse("200", getDefaultResponse());
private Path path2Instance(ServiceDocument doc) { Path path = new Path(); path.setParameters(Collections.singletonList(paramId())); path.setGet(opDefault(doc)); if (doc.documentDescription != null && doc.documentDescription.serviceRequestRoutes != null && !doc.documentDescription.serviceRequestRoutes.isEmpty()) { Path pathByRoutes = pathByRoutes(doc.documentDescription.serviceRequestRoutes.values()); path.setPost(pathByRoutes.getPost()); path.setPut(pathByRoutes.getPut()); path.setPatch(pathByRoutes.getPatch()); } else { io.swagger.models.Operation op = new io.swagger.models.Operation(); op.addTag(this.currentTag.getName()); op.setParameters(Collections.singletonList(paramBody(ServiceDocument.class))); op.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(doc), Operation.STATUS_CODE_NOT_FOUND, responseGenericError() )); // service definition should be introspected to better // describe which actions are supported path.setPost(op); path.setPut(op); path.setPatch(op); } return path; }
op.setDescription(route.description); if (route.requestType != null) { op.setParameters(Collections.singletonList(paramBody(route.requestType)));
put.setParameters(Arrays.asList( paramNamedBody(template(ServiceStats.class)), paramNamedBody(ServiceStats.ServiceStat.class) post.setParameters(Collections.singletonList(paramBody(ServiceStat.class)));
private Path path2UtilConfig(Parameter idParam) { Path path = new Path(); if (idParam != null) { path.setParameters(Collections.singletonList(paramId())); } io.swagger.models.Operation op = new io.swagger.models.Operation(); op.addTag(this.currentTag.getName()); op.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(template(ServiceConfiguration.class)), Operation.STATUS_CODE_NOT_FOUND, responseGenericError() )); path.setGet(op); op = new io.swagger.models.Operation(); op.addTag(this.currentTag.getName()); op.setParameters( Collections.singletonList(paramBody(ServiceConfigUpdateRequest.class))); op.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(template(ServiceConfiguration.class)), Operation.STATUS_CODE_NOT_FOUND, responseGenericError() )); path.setPatch(op); return path; }
private Path path2UtilAvailable(Parameter idParam) { Path path = new Path(); if (idParam != null) { path.setParameters(Collections.singletonList(paramId())); } io.swagger.models.Operation get = new io.swagger.models.Operation(); get.addTag(this.currentTag.getName()); get.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(), Operation.STATUS_CODE_UNAVAILABLE, responseNoContent(), Operation.STATUS_CODE_NOT_FOUND, responseGenericError() )); path.setGet(get); io.swagger.models.Operation patchOrPut = new io.swagger.models.Operation(); patchOrPut.addTag(this.currentTag.getName()); patchOrPut.setParameters(Collections.singletonList(paramBody(ServiceStat.class))); patchOrPut.setResponses(responseMap( Operation.STATUS_CODE_OK, responseOk(template(ServiceStats.class)), Operation.STATUS_CODE_NOT_FOUND, responseGenericError() )); path.put(patchOrPut); path.patch(patchOrPut); return path; }
protected Operation generateQueryCountOperation(RestQueriesConfiguration.QueryInfo query, RequestMethod method) { Operation operation = new Operation() .tag(query.getEntityName() + " Queries") .produces(APPLICATION_JSON_VALUE) .summary("Return a number of entities in query result") .description("Returns a number of entities that matches the query. You can use the all keyword for " + "the queryNameParam to get the number of all available entities.") .response(200, new Response() .description("Success. Entities count is returned") .schema(new IntegerProperty().description("Entities count"))) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to read the entity.")) .response(404, getErrorResponse("MetaClass not found or query with the given name not found")); operation.setParameters(generateQueryOpParams(query, method, false)); return operation; }
protected Operation generateServiceMethodOp(String service, RestMethodInfo methodInfo, RequestMethod requestMethod) { Operation operation = new Operation() .tag(service) .produces(APPLICATION_JSON_VALUE) .summary(service + "#" + methodInfo.getName()) .description("Executes the service method. This request expects query parameters with the names defined " + "in services configuration on the middleware.") .response(200, new Response() .description("Returns the result of the method execution. It can be of simple datatype " + "as well as JSON that represents an entity or entities collection.") .schema(new StringProperty())) .response(204, new Response().description("No content. This status is returned when the service " + "method was executed successfully but returns null or is of void type.")) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to invoke the service method.")); operation.setParameters(generateServiceMethodParams(service, methodInfo, requestMethod)); return operation; }
protected Operation generateQueryOperation(RestQueriesConfiguration.QueryInfo query, RequestMethod method) { Operation operation = new Operation() .tag(query.getEntityName() + " Queries") .produces(APPLICATION_JSON_VALUE) .summary(query.getName()) .description("Executes a predefined query. Query parameters must be passed in the request body as JSON map.") .response(200, new Response() .description("Success") .schema(new ArrayProperty(new RefProperty(ENTITY_DEFINITION_PREFIX + query.getEntityName())))) .response(403, getErrorResponse("Forbidden. A user doesn't have permissions to read the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); operation.setParameters(generateQueryOpParams(query, method, true)); return operation; }
protected Operation generateEntityBrowseOperation(ModelImpl entityModel) { Operation operation = new Operation() .tag(entityModel.getName()) .produces(APPLICATION_JSON_VALUE) .summary("Gets a list of entities: " + entityModel.getName()) .description("Gets a list of entities") .response(200, new Response() .description("Success. The list of entities is returned in the response body.") .schema(new ArrayProperty(new RefProperty(ENTITY_DEFINITION_PREFIX + entityModel.getName())))) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to read the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); operation.setParameters(generateEntityOptionalParams(false)); return operation; }
/** * This method will convert ballerina @Resource to ballerina @OperationAdaptor. * * @param resource Resource array to be convert. * @return Operation Adaptor object of given resource */ private OperationAdaptor convertResourceToOperation(BLangFunction resource, String httpMethod, int idIncrement) { OperationAdaptor op = new OperationAdaptor(); if (resource != null) { op.setHttpOperation(httpMethod); op.setPath('/' + resource.getName().getValue()); Response response = new Response() .description("Successful") .example(MediaType.APPLICATION_JSON, "Ok"); op.getOperation().response(200, response); // Replacing all '_' with ' ' to keep the consistency with what we are doing in swagger -> bal // @see BallerinaOperation#buildContext String resName = resource.getName().getValue().replaceAll("_", " "); op.getOperation().setOperationId(getOperationId(idIncrement, resName)); op.getOperation().setParameters(null); // Parsing annotations. this.parseResourceConfigAnnotationAttachment(resource, op); this.parseResourceInfo(resource, op.getOperation(), httpMethod); this.addResourceParameters(resource, op); this.parseResponsesAnnotationAttachment(resource, op.getOperation()); } return op; }