Java Code Examples for io.swagger.models.Operation#setResponses()

The following examples show how to use io.swagger.models.Operation#setResponses() . 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 Operation mapOperation(String operationName, HttpMethod httpMethod, Method method, String[] produces, String[] consumes, String controllerClassName) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(operationName, method, httpMethod));
	operation.setSummary(StringUtils.isBlank(operationName) ? operationName : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setResponses(createApiResponses(method));
	operation.setParameters(transformParameters(method));
	if (isNotEmpty(consumes)) {
		operation.setConsumes(asList(consumes));
	}
	if (isNotEmpty(produces)) {
		operation.setProduces(asList(produces));
	}

	if (isHttpMethodWithRequestBody(httpMethod)) {
		io.swagger.models.parameters.Parameter requestBody = createRequestBody(method, getFirstFromArray(consumes));
		if (requestBody != null) {
			operation.getParameters().add(requestBody);
		}
	}

	applyAnnotationsForOperation(operation, method.getAnnotations());
	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	return operation;
}
 
Example 2
Source File: TestVendorExtension.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void decorateOperation(final Operation operation, final Method method, final Iterator<SwaggerExtension> chain) {

    final TestVendorAnnotation annotation = method.getAnnotation(TestVendorAnnotation.class);
    if (annotation != null) {

        Map<String, Response> map = new HashMap<String, Response>(operation.getResponses());
        final Response value = new Response();
        value.setDescription(RESPONSE_DESCRIPTION);
        map.put(RESPONSE_STATUS_401, value);
        operation.setResponses(map);
    }

    if (chain.hasNext()) {
        chain.next().decorateOperation(operation, method, chain);
    }
}
 
Example 3
Source File: VendorExtensionWithoutReader.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void decorateOperation(final Operation operation, final Method method, final Iterator<SwaggerExtension> chain) {

    final TestVendorAnnotation annotation = method.getAnnotation(TestVendorAnnotation.class);
    if (annotation != null) {

        Map<String, Response> map = new HashMap<String, Response>(operation.getResponses());
        final Response value = new Response();
        value.setDescription(RESPONSE_DESCRIPTION);
        map.put(RESPONSE_STATUS_501, value);
        operation.setResponses(map);
    }

    if (chain.hasNext()) {
        chain.next().decorateOperation(operation, method, chain);
    }
}
 
Example 4
Source File: UpdateManager.java    From cellery-distribution with Apache License 2.0 5 votes vote down vote up
/**
 * Creates API Resources inside a Component
 *
 * @param api API sent by controller
 * @return Swagger Path Map
 */
private static Map<String, Path> createAPIResources(API api) {
    Map<String, Path> pathMap = new HashMap<>();
    for (ApiDefinition definition : api.getDefinitions()) {
        Path path = pathMap.computeIfAbsent(definition.getPath(), (key) -> new Path());
        Operation op = new Operation();

        Map<String, Response> resMap = new HashMap<>();
        Response res = new Response();
        res.setDescription("Successful");

        resMap.put("200", res);
        op.setResponses(resMap);

        disableMicroGWAuth(op);
        switch (definition.getMethod().toLowerCase(Locale.ENGLISH)) {
            case Constants.JsonParamNames.GET:
                path.setGet(op);
                break;
            case Constants.JsonParamNames.POST:
                path.setPost(op);
                break;
            case Constants.JsonParamNames.PUT:
                path.setPut(op);
                break;
            case Constants.JsonParamNames.DELETE:
                path.setDelete(op);
                break;
            default:
                log.error("HTTP Method not implemented");
        }
    }
    return pathMap;
}