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

The following examples show how to use io.swagger.models.Operation#response() . 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: Reader.java    From dorado with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void addResponse(Operation operation, ApiResponse apiResponse, JsonView jsonView) {
	Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders(), jsonView);
	Map<String, Object> examples = parseExamples(apiResponse.examples());

	Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
	response.setExamples(examples);

	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, jsonView);
		if (property != null) {
			response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
			appendModels(responseType);
		}
	}
}
 
Example 2
Source File: PostOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation post = dropLastSegmentParameters ? listOperation() : defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    post.summary("creates " + getName(node));
    String description = node.getDescription() == null ? "creates " + getName(node) :
            node.getDescription();
    post.description(description);
    post.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added to list"));

    post.response(201, new Response().description("Object created"));
    post.response(409, new Response().description("Object already exists"));
    return post;
}
 
Example 3
Source File: PutOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation put = defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    put.summary("creates or updates " + getName(node));
    String description = node.getDescription() == null ? "creates or updates " + getName(node) :
            node.getDescription();
    put.description(description);
    put.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added or updated"));

    put.response(201, new Response().description("Object created"));
    put.response(204, new Response().description("Object modified"));
    return put;
}
 
Example 4
Source File: PatchOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation patch = defaultOperation();
    final RefModel definition = new RefModel(getDefinitionId(node));
    patch.summary("patches " + getName(node));
    String description = node.getDescription() == null ? "patches " + getName(node) :
            node.getDescription();
    patch.description(description);
    patch.parameter(new BodyParameter()
            .name(getName(node) + ".body-param")
            .schema(definition)
            .description(getName(node) + " to be added or updated"));

    patch.response(200, new Response()
            .schema(new RefProperty(getDefinitionId(node)))
            .description(getName(node)));
    patch.response(204, new Response().description("Operation successful"));
    return patch;
}
 
Example 5
Source File: RestControllerProcessor.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * 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())));
    }
}
 
Example 6
Source File: ExtendedSwaggerReader.java    From msf4j with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 7
Source File: DeleteOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation delete = defaultOperation();
    delete.summary("removes " + getName(node));
    String description = node.getDescription() == null ? "removes " + getName(node) :
            node.getDescription();
    delete.description(description);
    delete.response(204, new Response().description("Object deleted"));
    return delete;
}
 
Example 8
Source File: OperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default empty operation that defines error response only
 * @return basic operation with 400 response pre-defined
 */
protected Operation defaultOperation() {
    final Operation operation = new io.swagger.models.Operation();
    operation.response(400, new Response().description("Internal error"));
    operation.setParameters(path.params());
    return operation;
}
 
Example 9
Source File: GetOperationGenerator.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Operation execute(DataSchemaNode node) {
    final Operation get = defaultOperation();
    get.summary("returns " + getName(node));
    String description = node.getDescription() == null ? "returns " + getName(node) :
            node.getDescription();
    get.description(description);
    get.response(200, new Response()
            .schema(new RefProperty(getDefinitionId(node)))
            .description(getName(node)));
    return get;
}