Java Code Examples for io.swagger.v3.oas.models.Operation#setDeprecated()

The following examples show how to use io.swagger.v3.oas.models.Operation#setDeprecated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractOpenApiResource.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
/**
 * Calculate path.
 *
 * @param handlerMethod the handler method
 * @param routerOperation the router operation
 */
protected void calculatePath(HandlerMethod handlerMethod, RouterOperation routerOperation) {
	String operationPath = routerOperation.getPath();
	Set<RequestMethod> requestMethods = new HashSet<>(Arrays.asList(routerOperation.getMethods()));
	io.swagger.v3.oas.annotations.Operation apiOperation = routerOperation.getOperation();
	String[] methodConsumes = routerOperation.getConsumes();
	String[] methodProduces = routerOperation.getProduces();
	String[] headers = routerOperation.getHeaders();
	Map<String, String> queryParams = routerOperation.getQueryParams();

	OpenAPI openAPI = openAPIBuilder.getCalculatedOpenAPI();
	Components components = openAPI.getComponents();
	Paths paths = openAPI.getPaths();

	Map<HttpMethod, Operation> operationMap = null;
	if (paths.containsKey(operationPath)) {
		PathItem pathItem = paths.get(operationPath);
		operationMap = pathItem.readOperationsMap();
	}

	for (RequestMethod requestMethod : requestMethods) {
		Operation existingOperation = getExistingOperation(operationMap, requestMethod);
		Method method = handlerMethod.getMethod();
		// skip hidden operations
		if (operationParser.isHidden(method))
			continue;

		RequestMapping reqMappingClass = AnnotatedElementUtils.findMergedAnnotation(handlerMethod.getBeanType(),
				RequestMapping.class);

		MethodAttributes methodAttributes = new MethodAttributes(springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType(), methodConsumes, methodProduces, headers);
		methodAttributes.setMethodOverloaded(existingOperation != null);

		if (reqMappingClass != null) {
			methodAttributes.setClassConsumes(reqMappingClass.consumes());
			methodAttributes.setClassProduces(reqMappingClass.produces());
		}

		methodAttributes.calculateConsumesProduces(method);

		Operation operation = (existingOperation != null) ? existingOperation : new Operation();

		if (isDeprecated(method))
			operation.setDeprecated(true);

		// Add documentation from operation annotation
		if (apiOperation == null || StringUtils.isBlank(apiOperation.operationId()))
			apiOperation = AnnotatedElementUtils.findMergedAnnotation(method,
					io.swagger.v3.oas.annotations.Operation.class);

		calculateJsonView(apiOperation, methodAttributes, method);
		if (apiOperation != null)
			openAPI = operationParser.parse(apiOperation, operation, openAPI, methodAttributes);
		fillParametersList(operation, queryParams, methodAttributes);

		// compute tags
		operation = openAPIBuilder.buildTags(handlerMethod, operation, openAPI);

		io.swagger.v3.oas.annotations.parameters.RequestBody requestBodyDoc = AnnotatedElementUtils.findMergedAnnotation(method,
				io.swagger.v3.oas.annotations.parameters.RequestBody.class);

		// RequestBody in Operation
		requestBuilder.getRequestBodyBuilder()
				.buildRequestBodyFromDoc(requestBodyDoc, methodAttributes, components,
						methodAttributes.getJsonViewAnnotationForRequestBody())
				.ifPresent(operation::setRequestBody);
		// requests
		operation = requestBuilder.build(handlerMethod, requestMethod, operation, methodAttributes, openAPI);

		// responses
		ApiResponses apiResponses = responseBuilder.build(components, handlerMethod, operation, methodAttributes);
		operation.setResponses(apiResponses);

		Set<io.swagger.v3.oas.annotations.callbacks.Callback> apiCallbacks = AnnotatedElementUtils.findMergedRepeatableAnnotations(method, io.swagger.v3.oas.annotations.callbacks.Callback.class);

		// callbacks
		buildCallbacks(openAPI, methodAttributes, operation, apiCallbacks);

		// allow for customisation
		customiseOperation(operation, handlerMethod);

		PathItem pathItemObject = buildPathItem(requestMethod, operation, operationPath, paths);
		paths.addPathItem(operationPath, pathItemObject);
	}
}
 
Example 2
Source File: OperationBuilder.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
/**
 * Parse open api.
 *
 * @param apiOperation the api operation
 * @param operation the operation
 * @param openAPI the open api
 * @param methodAttributes the method attributes
 * @return the open api
 */
public OpenAPI parse(io.swagger.v3.oas.annotations.Operation apiOperation,
		Operation operation, OpenAPI openAPI, MethodAttributes methodAttributes) {
	Components components = openAPI.getComponents();
	if (StringUtils.isNotBlank(apiOperation.summary()))
		operation.setSummary(propertyResolverUtils.resolve(apiOperation.summary()));

	if (StringUtils.isNotBlank(apiOperation.description()))
		operation.setDescription(propertyResolverUtils.resolve(apiOperation.description()));

	if (StringUtils.isNotBlank(apiOperation.operationId()))
		operation.setOperationId(getOperationId(apiOperation.operationId(), openAPI));

	if (apiOperation.deprecated())
		operation.setDeprecated(apiOperation.deprecated());

	buildTags(apiOperation, operation);

	if (operation.getExternalDocs() == null)  // if not set in root annotation
		AnnotationsUtils.getExternalDocumentation(apiOperation.externalDocs())
				.ifPresent(operation::setExternalDocs);

	// servers
	AnnotationsUtils.getServers(apiOperation.servers())
			.ifPresent(servers -> servers.forEach(operation::addServersItem));

	// build parameters
	for (io.swagger.v3.oas.annotations.Parameter parameterDoc : apiOperation.parameters()) {
		Parameter parameter = parameterBuilder.buildParameterFromDoc(parameterDoc, components,
				methodAttributes.getJsonViewAnnotation());
		operation.addParametersItem(parameter);
	}

	// RequestBody in Operation
	requestBodyBuilder.buildRequestBodyFromDoc(apiOperation.requestBody(), operation.getRequestBody(), methodAttributes, components).ifPresent(operation::setRequestBody);

	// build response
	buildResponse(components, apiOperation, operation, methodAttributes);

	// security
	securityParser.buildSecurityRequirement(apiOperation.security(), operation);

	// Extensions in Operation
	buildExtensions(apiOperation, operation);
	return openAPI;
}
 
Example 3
Source File: OASMergeUtil.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
public static Operation mergeOperations(Operation thisOperation, Operation thatOperation) {
  if (thatOperation == null) {
    return thisOperation;
  }

  if (thatOperation.getTags() != null) {
    thisOperation.setTags(
        mergeTags(thisOperation.getTags(), thatOperation.getTags())
    );
  }
  if (thatOperation.getExternalDocs() != null) {
    thisOperation.setExternalDocs(
      mergeExternalDocumentation(thisOperation.getExternalDocs(), thatOperation.getExternalDocs())
    );
  }
  if (thatOperation.getParameters() != null) {
    thisOperation.setParameters(
        mergeParameters(thisOperation.getParameters(), thatOperation.getParameters())
    );
  }
  if (thatOperation.getRequestBody() != null) {
    thisOperation.setRequestBody(thatOperation.getRequestBody());
  }
  if (thatOperation.getResponses() != null) {
    thisOperation.setResponses(thatOperation.getResponses());
  }
  if (thatOperation.getCallbacks() != null) {
    thisOperation.setCallbacks(thatOperation.getCallbacks());
  }
  if (thatOperation.getDeprecated() != null) {
    thisOperation.setDeprecated(thatOperation.getDeprecated());
  }
  if (thatOperation.getSecurity() != null) {
    thisOperation.setSecurity(thatOperation.getSecurity());
  }
  if (thatOperation.getServers() != null) {
    thisOperation.setServers(thatOperation.getServers());
  }
  if (thatOperation.getExtensions() != null) {
    thisOperation.setExtensions(thatOperation.getExtensions());
  }
  if (thatOperation.getOperationId() != null) {
    thisOperation.setOperationId(thatOperation.getOperationId());
  }
  if (thatOperation.getSummary() != null) {
    thisOperation.setSummary(thatOperation.getSummary());
  }
  if (thatOperation.getDescription() != null) {
    thisOperation.setDescription(thatOperation.getDescription());
  }
  if (thatOperation.getExtensions() != null) {
    thisOperation.setExtensions(thatOperation.getExtensions());
  }
  return thisOperation;
}
 
Example 4
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public Operation getOperation(ObjectNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    Operation operation = new Operation();

    ArrayNode array = getArray("tags", obj, false, location, result);
    List<String> tags = getTagsStrings(array, String.format("%s.%s", location, "tags"), result);
    if (tags != null) {
        operation.setTags(tags);
    }
    String value = getString("summary", obj, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        operation.setSummary(value);
    }

    value = getString("description", obj, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        operation.setDescription(value);
    }

    ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result);
    ExternalDocumentation docs = getExternalDocs(externalDocs, String.format("%s.%s", location, "externalDocs"), result);
    if(docs != null) {
        operation.setExternalDocs(docs);
    }
    value = getString("operationId", obj, false, location, result, operationIDs);
    if (StringUtils.isNotBlank(value)) {
        operation.operationId(value);
    }

    ArrayNode parameters = getArray("parameters", obj, false, location, result);
    if (parameters != null){
        operation.setParameters(getParameterList(parameters, String.format("%s.%s", location, "parameters"), result));
    }

    final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result);
    if (requestObjectNode != null){
        operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location, "requestBody"), result));
    }

    ObjectNode responsesNode = getObject("responses", obj, true, location, result);
    ApiResponses responses = getResponses(responsesNode, String.format("%s.%s", location, "responses"), result, false);
    if(responses != null) {
        operation.setResponses(responses);
    }

    ObjectNode callbacksNode = getObject("callbacks", obj, false, location, result);
    Map<String,Callback> callbacks = getCallbacks(callbacksNode, String.format("%s.%s", location, "callbacks"), result, false);
    if(callbacks != null){
        operation.setCallbacks(callbacks);
    }

    Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
    if (deprecated != null) {
        operation.setDeprecated(deprecated);
    }

    array = getArray("servers", obj, false, location, result);
    if (array != null && array.size() > 0) {
        operation.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result));
    }


    array = getArray("security", obj, false, location, result);
    if (array != null) {
        operation.setSecurity(getSecurityRequirementsList(array, String.format("%s.%s", location, "security"), result));
    }


    Map <String,Object> extensions = getExtensions(obj);
    if(extensions != null && extensions.size() > 0) {
        operation.setExtensions(extensions);
    }

    Set<String> keys = getKeys(obj);
    for(String key : keys) {
        if(!OPERATION_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }


    return operation;
}