use of org.wildfly.swarm.microprofile.openapi.api.models.responses.APIResponseImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method createResponseFromJaxRsMethod.
/**
* Called when a jax-rs method's APIResponse annotations have all been processed but
* no response was actually created for the operation. This method will create a response
* from the method information and add it to the given operation. It will try to do this
* by examining the method's return value and the type of operation (GET, PUT, POST, DELETE).
*
* If there is a return value of some kind (a non-void return type) then the response code
* is assumed to be 200.
*
* If there not a return value (void return type) then either a 201 or 204 is returned,
* depending on the type of request.
*
* TODO generate responses for each checked exception?
* @param method
* @param operation
*/
private void createResponseFromJaxRsMethod(MethodInfo method, Operation operation) {
Type returnType = method.returnType();
Schema schema;
APIResponses responses;
APIResponse response;
ContentImpl content;
if (returnType.kind() == Type.Kind.VOID) {
String code = "204";
if (method.hasAnnotation(OpenApiConstants.DOTNAME_POST)) {
code = "201";
}
responses = ModelUtil.responses(operation);
response = new APIResponseImpl();
responses.addApiResponse(code, response);
} else {
schema = typeToSchema(returnType);
responses = ModelUtil.responses(operation);
response = new APIResponseImpl();
content = new ContentImpl();
String[] produces = this.currentProduces;
if (produces == null || produces.length == 0) {
produces = OpenApiConstants.DEFAULT_PRODUCES;
}
for (String producesType : produces) {
MediaType mt = new MediaTypeImpl();
mt.setSchema(schema);
content.addMediaType(producesType, mt);
}
response.setContent(content);
responses.addApiResponse("200", response);
}
}
use of org.wildfly.swarm.microprofile.openapi.api.models.responses.APIResponseImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readResponse.
/**
* Reads a APIResponse annotation into a model.
* @param annotation
*/
private APIResponse readResponse(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @Response annotation.");
APIResponse response = new APIResponseImpl();
response.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
response.setHeaders(readHeaders(annotation.value(OpenApiConstants.PROP_HEADERS)));
response.setLinks(readLinks(annotation.value(OpenApiConstants.PROP_LINKS)));
response.setContent(readContent(annotation.value(OpenApiConstants.PROP_CONTENT), ContentDirection.Output));
response.setRef(JandexUtil.refValue(annotation, RefType.Response));
return response;
}
use of org.wildfly.swarm.microprofile.openapi.api.models.responses.APIResponseImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readAPIResponse.
/**
* Reads a {@link APIResponse} OpenAPI node.
* @param node
*/
private APIResponse readAPIResponse(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
APIResponseImpl model = new APIResponseImpl();
model.setRef(JsonUtil.stringProperty(node, OpenApiConstants.PROP_$REF));
model.setDescription(JsonUtil.stringProperty(node, OpenApiConstants.PROP_DESCRIPTION));
model.setHeaders(readHeaders(node.get(OpenApiConstants.PROP_HEADERS)));
model.setContent(readContent(node.get(OpenApiConstants.PROP_CONTENT)));
model.setLinks(readLinks(node.get(OpenApiConstants.PROP_LINKS)));
readExtensions(node, model);
return model;
}
Aggregations