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

The following examples show how to use io.swagger.v3.oas.models.Operation#setSummary() . 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: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private void mapRequestMapping(RequestMapping requestMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName,
							   String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(requestMapping.name(), method, getSpringMethod(requestMapping.method())));
	operation.setSummary(StringUtils.isBlank(requestMapping.name()) ? requestMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	if (isHttpMethodWithRequestBody(requestMapping.method())) {
		operation.setRequestBody(createRequestBody(method, getFirstFromArray(requestMapping.consumes())));
	}
	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(requestMapping.produces())));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(requestMapping.value()), getFirstFromArray(requestMapping.path()));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap,
			pathItem -> setContentBasedOnHttpMethod(pathItem, requestMapping.method(), operation)
	);
}
 
Example 2
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapDelete(DeleteMapping deleteMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName,
					   String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(deleteMapping.name(), method, HttpMethod.DELETE));
	operation.setSummary(StringUtils.isBlank(deleteMapping.name()) ? deleteMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(deleteMapping.produces())));
	String path = ObjectUtils.defaultIfNull(getFirstFromArray(deleteMapping.value()), getFirstFromArray(deleteMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setDelete(operation));
}
 
Example 3
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapGet(GetMapping getMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(getMapping.name(), method, HttpMethod.GET));
	operation.setSummary(StringUtils.isBlank(getMapping.name()) ? getMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(getMapping.produces())));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(getMapping.value()), getFirstFromArray(getMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setGet(operation));
}
 
Example 4
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPatch(PatchMapping patchMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(patchMapping.name(), method, HttpMethod.PATCH));
	operation.setSummary(StringUtils.isBlank(patchMapping.name()) ? patchMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(patchMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(patchMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(patchMapping.value()), getFirstFromArray(patchMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPatch(operation));
}
 
Example 5
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPut(PutMapping putMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(putMapping.name(), method, HttpMethod.PUT));
	operation.setSummary(StringUtils.isBlank(putMapping.name()) ? putMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(putMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(putMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(putMapping.value()), getFirstFromArray(putMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPut(operation));
}
 
Example 6
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPost(PostMapping postMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(postMapping.name(), method, HttpMethod.POST));
	operation.setSummary(StringUtils.isBlank(postMapping.name()) ? postMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(postMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(postMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(postMapping.value()), getFirstFromArray(postMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPost(operation));
}
 
Example 7
Source File: ActuatorOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
	if (operation.getTags() != null && operation.getTags().contains(actuatorProvider.getTag().getName())) {
		operation.setSummary(handlerMethod.toString());
		operation.setOperationId(operation.getOperationId() + "_" + methodCount++);
	}
	return operation;
}
 
Example 8
Source File: OASMergeUtilTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeOperations() {
  Operation thatOperation = new Operation();

  Operation thisOperation = new Operation();
  thisOperation.setOperationId("new id");
  thisOperation.setSummary("new summary");
  thisOperation.setDescription("new description");

  Map<String, Object> extensions = new HashMap<>();
  extensions.put("new schema", new Schema());
  thisOperation.setExtensions(extensions);

  Assert.assertSame(thisOperation, OASMergeUtil.mergeOperations(thisOperation, null));

  Operation afterMerge = OASMergeUtil.mergeOperations(thatOperation, thisOperation);
  Assert.assertEquals("new id", afterMerge.getOperationId());
  Assert.assertEquals("new summary", afterMerge.getSummary());
  Assert.assertEquals("new description", afterMerge.getDescription());
  Assert.assertSame(extensions, afterMerge.getExtensions());

  thatOperation.setOperationId("existing id");
  thatOperation.setSummary("existing summary");
  thatOperation.setDescription("existing description");

  Map<String, Object> existingExtensions = new HashMap<>();
  extensions.put("existing schema", new Schema());
  thisOperation.setExtensions(extensions);

  afterMerge = OASMergeUtil.mergeOperations(thisOperation, thatOperation);
  Assert.assertEquals("existing id", afterMerge.getOperationId());
  Assert.assertEquals("existing summary", afterMerge.getSummary());
  Assert.assertEquals("existing description", afterMerge.getDescription());
  Assert.assertSame(extensions, afterMerge.getExtensions());
}
 
Example 9
Source File: TestOperationInterceptor.java    From spring-openapi with MIT License 4 votes vote down vote up
@Override
public void intercept(Method method, Operation transformedOperation) {
	transformedOperation.setSummary("Interceptor summary");
}
 
Example 10
Source File: TestOperationInterceptor.java    From spring-openapi with MIT License 4 votes vote down vote up
@Override
public void intercept(Method method, Operation transformedOperation) {
	transformedOperation.setSummary("Interceptor summary");
}
 
Example 11
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 12
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 13
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;
}