Refine search
List<ObjectType> inlineDefinitions = params.inlineDefinitions; if (config.isFlatBodyEnabled()) { List<Parameter> parameters = operation.getOperation().getParameters(); if (CollectionUtils.isNotEmpty(parameters)) { for (Parameter parameter : parameters) { if (StringUtils.equals(parameter.getIn(), "body")) { ParameterAdapter parameterAdapter = new ParameterAdapter(context, operation, parameter, definitionDocumentResolver); String description = parameter.getDescription(); if (isNotBlank(description)) { markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description)); typeInfos.italicText(labels.getLabel(NAME_COLUMN)).textLine(COLON + parameter.getName()); typeInfos.italicText(labels.getLabel(FLAGS_COLUMN)).textLine(COLON + (BooleanUtils.isTrue(parameter.getRequired()) ? labels.getLabel(FLAGS_REQUIRED).toLowerCase() : labels.getLabel(FLAGS_OPTIONAL).toLowerCase()));
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { PathOperation operation = params.operation; Map<String, Response> responses = operation.getOperation().getResponses(); sortedResponses.forEach((String responseName, Response response) -> { String schemaContent = labels.getLabel(NO_CONTENT); if (response.getResponseSchema() != null) { Model model = response.getResponseSchema(); Type type = null; descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription())); Map<String, Property> headers = response.getHeaders(); .text(String.format(" (%s)", propertyType.displaySchema(markupDocBuilder))); if (isNotBlank(headerDescription) || optionalDefaultValue.isPresent()) { descriptionBuilder.text(COLON); if (isNotBlank(headerDescription) && !headerDescription.endsWith(".")) headerDescription += "."; if (isNotBlank(responsesContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(RESPONSES)); markupDocBuilder.text(responsesContent);
Optional.ofNullable(swagger.getPath(pattern)) .orElseGet(() -> { Path path = new Path(); swagger.path(pattern, path); return path; Operation op = new Operation(); tags.forEach(it -> op.addTag(it.getName())); op.operationId(operationId(route, tags.get(0), opIds)); op.summary(summary(route)); op.description(description(route, op.getSummary())); op.setConsumes(ImmutableList.of(MediaType.multipart.name())); } else if (it.kind() == RouteParameter.Kind.FORM) { op.setConsumes(ImmutableList.of(MediaType.form.name(), MediaType.multipart.name())); buildResponse(route, modelFactory, rsp -> op.addResponse(rsp.statusCode, rsp.response)); path.set(method(route), op);
String summary = Strings.emptyToNull((String) value); if (summary != null) { op.summary(summary); .filter(it -> it != null && it.trim().length() > 0) .map(tagFactory) .forEach(tag -> op.addTag(tag.getName())); break; case "response": Class responseType = (Class) value; if (responseType != Void.class) { response.responseSchema(modelFactory.apply(responseType)); String operationId = Strings.emptyToNull((String) value); if (operationId != null) { op.setOperationId(operationId); String produces = Strings.emptyToNull((String) value); if (produces != null) { op.produces(Splitter.on(",").trimResults().omitEmptyStrings().splitToList(produces)); String consumes = Strings.emptyToNull((String) value); if (consumes != null) { op.consumes(Splitter.on(",").trimResults().omitEmptyStrings().splitToList(consumes)); int code = (Integer) value; if (code != 200) { op.addResponse(value.toString(), response);
protected void updateOperation(String[] apiConsumes, String[] apiProduces, Map<String, Tag> tags, List<SecurityRequirement> securities, Operation operation) { if (operation == null) { return; } if (operation.getConsumes() == null) { for (String mediaType : apiConsumes) { operation.consumes(mediaType); } } if (operation.getProduces() == null) { for (String mediaType : apiProduces) { operation.produces(mediaType); } } if (operation.getTags() == null) { for (String tagString : tags.keySet()) { operation.tag(tagString); } } for (SecurityRequirement security : securities) { operation.security(security); } }
private static void mergeResponse(Operation operation, ResponseConfig responseConfig) { if (operation.getResponses() == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response response = operation.getResponses().get(String.valueOf(responseConfig.getCode())); if (response == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response sourceResp = responseConfig.getResponse(); if (StringUtils.isNotEmpty(sourceResp.getDescription()) && StringUtils.isEmpty(response.getDescription())) { response.setDescription(sourceResp.getDescription()); } if (sourceResp.getSchema() != null && response.getSchema() == null) { response.setSchema(sourceResp.getSchema()); } if (sourceResp.getExamples() != null && response.getExamples() == null) { response.setExamples(sourceResp.getExamples()); } if (sourceResp.getHeaders() != null && response.getHeaders() == null) { response.setHeaders(sourceResp.getHeaders()); } if (sourceResp.getVendorExtensions() != null && response.getVendorExtensions() == null) { response.setVendorExtensions(sourceResp.getVendorExtensions()); } }
public void applySummary(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.value())) { operation.summary(apiOperation.value()); } }
PathOperation operation = params.operation; List<ObjectType> inlineDefinitions = params.inlineDefinitions; List<Parameter> parameters = operation.getOperation().getParameters(); if (config.getParameterOrdering() != null) parameters.sort(config.getParameterOrdering()); if (isNotBlank(parametersContent)) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(PARAMETERS)); markupDocBuilder.text(parametersContent);
protected void correctPath(OperationGenerator operationGenerator) { String path = operationGenerator.getPath(); if (StringUtils.isEmpty(path)) { path = "/" + operationGenerator.getOperation().getOperationId(); } operationGenerator.setPath(path); }
@Override public void applyDescription(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.notes())) { operation.description(apiOperation.notes()); } operation.description(operation.getDescription() == null ? outputMethod(method) : (outputMethod(method) + operation.getDescription())); }
public void applyOperationId(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.nickname())) { operation.operationId(apiOperation.nickname()); } else { operation.operationId(method.getName()); } }
public void applyDescription(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.notes())) { operation.description(apiOperation.notes()); } }
private void addResponse(Operation operation, ApiResponse apiResponse) { Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders()); Response response = new Response().description(apiResponse.message()).headers(responseHeaders); if (apiResponse.code() == 0) { operation.defaultResponse(response); } else { operation.response(apiResponse.code(), response); } if (StringUtils.isNotEmpty(apiResponse.reference())) { response.schema(new RefProperty(apiResponse.reference())); } else if (!isVoid(apiResponse.response())) { Type responseType = apiResponse.response(); final Property property = ModelConverters.getInstance().readAsProperty(responseType); if (property != null) { response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property)); appendModels(responseType); } } }
public Operation parseMethod(String httpMethod, Method method) { int responseCode = 200; Operation operation = new Operation(); ApiOperation apiOperation = AnnotationUtils.findAnnotation(method, ApiOperation.class); operation.summary(apiOperation.value()).description(apiOperation.notes()); operation.setVendorExtensions(customExtensions); operation.security(sec); operation.operationId(operationId); operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) if (models.isEmpty()) { Property p = ModelConverters.getInstance().readAsProperty(responseClassType); operation.response(responseCode, new Response() operation.response(responseCode, new Response() if (consumes != null) { for (String mediaType : consumes.value()) { operation.consumes(mediaType); if (produces != null) { for (String mediaType : produces.value()) { operation.produces(mediaType);
private void fillResponseType(Operation operation, ProtoMethod protoMethod) { for (Entry<String, Response> entry : operation.getResponses().entrySet()) { String type = convertSwaggerType(entry.getValue().getSchema()); boolean wrapped = !messages.contains(type); ProtoResponse protoResponse = new ProtoResponse(); protoResponse.setTypeName(type); if (wrapped) { String wrapName = StringUtils.capitalize(operation.getOperationId()) + "ResponseWrap" + entry.getKey(); wrapPropertyToMessage(wrapName, entry.getValue().getSchema()); protoResponse.setTypeName(wrapName); } protoMethod.addResponse(entry.getKey(), protoResponse); } }
private void fillRequestType(Operation operation, ProtoMethod protoMethod) { List<Parameter> parameters = operation.getParameters(); if (parameters.isEmpty()) { addImports(ProtoConst.EMPTY_PROTO); protoMethod.setArgTypeName(ProtoConst.EMPTY.getCanonicalName()); return; } if (parameters.size() == 1) { String type = convertSwaggerType(parameters.get(0)); if (messages.contains(type)) { protoMethod.setArgTypeName(type); return; } } String wrapName = StringUtils.capitalize(operation.getOperationId()) + "RequestWrap"; createWrapArgs(wrapName, parameters); protoMethod.setArgTypeName(wrapName); }
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 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; }
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();
@Test public void shouldValidateOperationUniqueness() { final Swagger swagger = new Swagger() .path("/path", new Path().get(new Operation().operationId("o1")).post(new Operation().operationId("o2"))) .path("/other", new Path().patch(new Operation().operationId("o2")).put(new Operation().operationId("o3"))) .path("/more", new Path().options(new Operation().operationId("o4")).delete(new Operation().operationId("o3"))); final SwaggerModelInfo info = new SwaggerModelInfo.Builder().model(swagger).build(); final SwaggerModelInfo validated = SyndesisSwaggerValidationRules.validateUniqueOperationIds(info); final List<Violation> warnings = validated.getWarnings(); assertThat(warnings).hasSize(1); final Violation nonUniqueWarning = warnings.get(0); assertThat(nonUniqueWarning.error()).isEqualTo("non-unique-operation-ids"); assertThat(nonUniqueWarning.property()).isNull(); assertThat(nonUniqueWarning.message()).isEqualTo("Found operations with non unique operationIds: o2, o3"); } }