Refine search
operation.summary(apiOperation.value()).description(apiOperation.notes()); Property responseProperty = RESPONSE_CONTAINER_CONVERTER.withResponseContainer(responseContainer, property); operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) .headers(defaultResponseHeaders)); if (models.isEmpty()) { Property p = ModelConverters.getInstance().readAsProperty(responseClassType); operation.response(responseCode, new Response() .description("successful operation") .schema(p) .headers(defaultResponseHeaders)); Property responseProperty = RESPONSE_CONTAINER_CONVERTER.withResponseContainer(responseContainer, new RefProperty().asDefault(key)); operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) .headers(defaultResponseHeaders)); swagger.model(key, models.get(key)); swagger.model(entry.getKey(), entry.getValue()); if (operation.getResponses() == null) { operation.defaultResponse(new Response().description("successful operation"));
protected void convertToInterface() { if (interfaceCls != null) { return; } ClassConfig classConfig = new ClassConfig(); classConfig.setClassName(interfaceName); classConfig.setIntf(true); if (swagger.getPaths() != null) { for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY); JavaType resultJavaType = swaggerObjectMap.get(result.getSchema()); MethodConfig methodConfig = new MethodConfig(); methodConfig.setName(operation.getOperationId()); methodConfig.setResult(resultJavaType); for (Parameter parameter : operation.getParameters()) { String paramName = parameter.getName(); paramName = ClassUtils.correctMethodParameterName(paramName); JavaType paramJavaType = ConverterMgr.findJavaType(this, parameter); methodConfig.addParameter(paramName, paramJavaType); } classConfig.addMethod(methodConfig); } } } interfaceCls = JavassistUtils.createClass(classLoader, classConfig); }
protected void convertResponses() { if (swagger.getPaths() == null) { return; } for (Path path : swagger.getPaths().values()) { for (Operation operation : path.getOperations()) { for (Response response : operation.getResponses().values()) { convert(response.getSchema()); Map<String, Property> headers = response.getHeaders(); if (headers == null) { continue; } for (Property header : headers.values()) { convert(header); } } } } }
private ResponseWithStatusCode buildResponse(Function<Type, Model> modelFactory, Map<String, Object> attributes, Predicate<Integer> statusCode) { Response response = new Response(); String description = (String) attributes.get("apiResponse.message"); Class type = (Class) attributes.get("apiResponse.response"); if (!isVoid(type)) { response.setResponseSchema(modelFactory.apply(type)); } response.setDescription(description); buildResponseHeader(attributes, "apiResponse.responseHeaders", response::addHeader); Integer code = (Integer) attributes.get("apiResponse.code"); String key = code.toString(); if (statusCode.test(code)) { key += "(" + type.getSimpleName() + ")"; } return new ResponseWithStatusCode(key, response); }
.getOrDefault("apiOperation.code", returns.statusCode()); Response response = new Response(); String doc = returns.description() .orElseGet(() -> FriendlyTypeName.name(returns.type())); response.description(doc); response.responseSchema(modelFactory.apply(responseType)); .forEach(it -> consumer.accept( new ResponseWithStatusCode(it.getKey().toString(), new Response().description(it.getValue()))) );
Map<String, Response> responses = operation.getOperation().getResponses(); if (responses != null) for (Map.Entry<String, Response> responseEntry : responses.entrySet()) { Response response = responseEntry.getValue(); Object example = response.getExamples(); if (example == null) { Model model = response.getResponseSchema(); if (model != null) { Property schema = new PropertyModelConverter().modelToProperty(model); String simpleRef = ((RefProperty) schema).getSimpleRef(); example = generateExampleForRefModel(generateMissingExamples, simpleRef, definitions, definitionDocumentResolver, markupDocBuilder, new HashMap<>());
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; }
private Operation parseMethod(Class<?> cls, Method method, List<Parameter> globalParameters, List<ApiResponse> classApiResponses) { Operation operation = new Operation(); operation.summary(apiOperation.value()).description(apiOperation.notes()); Response response = new Response().description(SUCCESSFUL_OPERATION); response.schema(new RefProperty(apiOperation.responseReference())); operation.addResponse(String.valueOf(apiOperation.code()), response); } else if (responseType == null) { final int responseCode = apiOperation == null ? 200 : apiOperation.code(); operation.response(responseCode, new Response().description(SUCCESSFUL_OPERATION).schema(responseProperty) .headers(defaultResponseHeaders)); appendModels(responseType); if (operation.getResponses() == null) { Response response = new Response().description(SUCCESSFUL_OPERATION); operation.defaultResponse(response);
for (final Map.Entry<String, Path> pathEntry : notNull(swaggerModelInfo.getModel().getPaths()).entrySet()) { for (final Map.Entry<HttpMethod, Operation> operationEntry : notNull(pathEntry.getValue().getOperationMap()).entrySet()) { for (final Parameter parameter : notNull(operationEntry.getValue().getParameters())) { if (!(parameter instanceof BodyParameter)) { continue; for (final Map.Entry<String, Response> responseEntry : notNull(operationEntry.getValue().getResponses()).entrySet()) { if (!responseEntry.getKey().startsWith("2")) { continue; // check only correct responses if (responseEntry.getValue().getSchema() == null) { final String message = "Operation " + operationEntry.getKey() + " " + pathEntry.getKey() + " does not provide a response schema for code " + responseEntry.getKey();
/** * Processes the return value of a RequestMapping annotated method. * * @param returnType the return type. * @param operation the operation. * @param returnDescription the description of the return value. * * @throws MojoExecutionException if the return type isn't an XmlType. */ private void processRestMethodReturnValue(Class<?> returnType, Operation operation, String returnDescription) throws MojoExecutionException { log.debug("Processing REST method return value \"" + returnType.getName() + "\"."); // Add the class name to the list of classes which we will create an example for. exampleClassNames.add(returnType.getSimpleName()); // Add the success response operation.response(200, new Response().description(returnDescription == null ? "Success" : returnDescription) .schema(new RefProperty(getXmlType(returnType).name().trim()))); // If we have an error class, add that as the default response. if (modelErrorClass != null) { operation.defaultResponse(new Response().description("General Error").schema(new RefProperty(getXmlType(modelErrorClass).name().trim()))); } }
operation.response(200, new Response() .description("Successful request") .schema(responseProperty) .headers(defaultResponseHeaders)); if (model == null) { Property p = modelConverters.readAsProperty(responseClass); operation.response(200, new Response() .description("Successful request") .schema(p) .headers(defaultResponseHeaders)); operation.response(200, new Response() .description("Successful operation") .schema(responseProperty) .headers(defaultResponseHeaders)); swagger.model(name, model); Response response = new Response() .description(apiResponse.message()) .schema(errorProperty) .headers(responseHeaders); response.schema(modelConverters.readAsProperty(apiResponse.response())); Map<String, Model> models = modelConverters.read(responseClass); for (String key : models.keySet()) { response.schema(new RefProperty().asDefault(key));
fullPath += paths.get(0); Path path = swagger.getPath(fullPath); if (path == null) { path = new Path(); Operation op = new Operation(); op.addScheme(Scheme.HTTP); op.addScheme(Scheme.HTTPS); op.setDescription(fn.getDescription()); if (consumes != null) { op.defaultResponse(new Response()); path.set(method.toLowerCase(), op); logger.debug("afterScan; added op: {} for method {}", op, method); swagger.path(fullPath, path); logger.debug("afterScan; set path: {}", path.getOperations()); if (consumes != null) { for (String consume: consumes) { swagger.addConsumes(consume);
Map<String, Path> paths = swagger.getPaths(); if (paths == null) paths = Collections.emptyMap(); for (String path : paths.keySet()) { Map<HttpMethod, Operation> operations = paths.get(path).getOperationMap(); for (HttpMethod method : operations.keySet()) { Operation operation = operations.get(method); if (isEmpty(operation.getConsumes())) operation.setConsumes(swagger.getConsumes()); if (isEmpty(operation.getProduces())) operation.setProduces(swagger.getProduces()); Map<String, Response> responses = operation.getResponses(); Response response = responses != null ? responses.get("200") : null; DataProvider dataProvider = response != null && response.getSchema() != null ? DataProviders.getInstance().collect(swagger, response.getSchema(), true) : new ConstDataProvider(null); dataProvider.setRequired(true);
public void resolvePath(Path path) { for (Operation op : path.getOperations()) { // inputs for (Parameter parameter : op.getParameters()) { if (parameter instanceof BodyParameter) { BodyParameter body = (BodyParameter) parameter; Model schema = body.getSchema(); Model resolved = resolveModel(schema); body.setSchema(resolved); } } // responses if (op.getResponses() != null) { for (String code : op.getResponses().keySet()) { Response response = op.getResponses().get(code); if (response.getResponseSchema() != null) { Model resolved = resolveModel(response.getResponseSchema()); response.setResponseSchema(resolved); } } } } }
swagger.getPaths().forEach((pathName, path) -> path.getOperations().forEach(operation -> { operation.getParameters().forEach(parameter -> { if (parameter instanceof BodyParameter) { resources.add(((RefModel) ((BodyParameter)parameter).getSchema()).getSimpleRef()); operation.getResponses().entrySet().stream() .filter(entry -> "200".equals(entry.getKey())) .forEach(entry -> { Property rawSchema = entry.getValue().getSchema(); resources.add(refProperty.getSimpleRef()); swagger.getDefinitions().forEach((name, model) -> { String parent = (String) model.getVendorExtensions().get("x-okta-parent"); if (parent != null) { .map(resourceName -> swagger.getDefinitions().get(resourceName)) .forEach(model -> { model.getVendorExtensions().put("top-level", true);
tag.name(tagname); tags.put(tagname, tag); swagger.addTag(tag); path = new Path(); paths.put(pattern, path); Operation op = new Operation(); op.addTag(tag.getName()); route.name().ifPresent(op::operationId); route.name().ifPresent(n -> op.summary(Route.normalize(n).substring(1))); Response rsp = new Response(); RouteResponse routersp = route.response(); Map<Integer, String> statusCodes = Maps.newHashMap(routersp.statusCodes()); int statusCode = routersp.statusCode(); String doc = routersp.doc().orElse(statusCodes.get(statusCode)); rsp.description(doc); Type returnType = routersp.type(); definitions(returnType, swagger::addDefinition); rsp.schema(ModelConverters.getInstance().readAsProperty(returnType)); op.addResponse(String.valueOf(statusCode), rsp); op.addResponse(sc.toString(), new Response().description(label)); swagger.paths(paths);
Method interfaceMethod = entry.getKey(); final Operation operation = new Operation(); String operationPath = null; String httpMethod = null; if (operation.getResponses() == null) { operation.defaultResponse(new Response().description("successful operation")); final String parsedPath = PathUtils.parsePath(operationPath, regexMap); Path path = swagger.getPath(parsedPath); if (path == null) { path = new Path(); swagger.path(parsedPath, path); path.set(httpMethod.toLowerCase(), operation);
continue; final Operation operation = new Operation(); if ("post".equalsIgnoreCase(httpMethod) && operation.getConsumes() == null) { operation.addConsumes("application/x-www-form-urlencoded"); if (operation.getResponses() == null) { operation.defaultResponse(new Response().description("successful operation")); final String parsedPath = PathUtils.parsePath(operationPath, regexMap); Path path = swagger.getPath(parsedPath); if (path == null) { path = new SwaggerPath(); swagger.path(parsedPath, path); path.set(httpMethod.toLowerCase(), operation);
Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders()); Class<?> responseClass = apiResponse.response(); Response response = new Response() .description(apiResponse.message()) .headers(responseHeaders); if (operation.getResponses() != null) { Response apiOperationResponse = operation.getResponses().get(String.valueOf(apiResponse.code())); if (apiOperationResponse != null) { response.setSchema(apiOperationResponse.getSchema()); Map<String, Model> models = ModelConverters.getInstance().read(responseClass); for (String key : models.keySet()) { final Property schema = new RefProperty().asDefault(key); if (apiResponse.responseContainer().equals("List")) { response.schema(new ArrayProperty(schema)); } else { response.schema(schema); swagger.model(key, models.get(key)); if (response.getSchema() == null) { Map<String, Response> responses = operation.getResponses(); if (responses != null) { Response apiOperationResponse = responses.get(String.valueOf(apiResponse.code())); if (apiOperationResponse != null) { response.setSchema(apiOperationResponse.getSchema());
@Override public Response apply(ContainerRequestContext ctx) { List<Parameter> parameters = operation.getParameters(); final RequestContext requestContext = createContext(ctx); responseSchema = operation.getResponses().get("default"); if (responseSchema != null && responseSchema.getResponseSchema() != null) { validate(wrapper.getEntity(), responseSchema.getResponseSchema(), SchemaValidator.Direction.OUTPUT); } else { LOGGER.debug("no response schema for code " + responseCode + " to validate against"); io.swagger.models.Response response = responses.get(defaultKey); if(response.getHeaders() != null && response.getHeaders().size() > 0) { for(String key: response.getHeaders().keySet()) { Property headerProperty = response.getHeaders().get(key); Object output = ExampleBuilder.fromProperty(headerProperty, definitions); if(output instanceof ArrayExample) { Map<String, Object> examples = response.getExamples(); if (examples != null) { for (MediaType mediaType : requestContext.getAcceptableMediaTypes()) { Object output = ExampleBuilder.fromProperty(response.getSchema(), definitions);