use of org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readMediaType.
/**
* Reads a {@link MediaType} OpenAPI node.
* @param node
* @return
*/
private MediaType readMediaType(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
MediaTypeImpl model = new MediaTypeImpl();
model.setSchema(readSchema(node.get(OpenApiConstants.PROP_SCHEMA)));
model.setExample(readObject(node.get(OpenApiConstants.PROP_EXAMPLE)));
model.setExamples(readExamples(node.get(OpenApiConstants.PROP_EXAMPLES)));
model.setEncoding(readEncodings(node.get(OpenApiConstants.PROP_ENCODING)));
readExtensions(node, model);
return model;
}
use of org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readMediaType.
/**
* Reads a single Content annotation into a {@link MediaType} model.
* @param nested
*/
private MediaType readMediaType(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @Content annotation as a MediaType.");
MediaType mediaType = new MediaTypeImpl();
mediaType.setExamples(readExamples(annotation.value(OpenApiConstants.PROP_EXAMPLES)));
mediaType.setSchema(readSchema(annotation.value(OpenApiConstants.PROP_SCHEMA)));
mediaType.setEncoding(readEncodings(annotation.value(OpenApiConstants.PROP_ENCODING)));
return mediaType;
}
use of org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl in project wildfly-swarm by wildfly-swarm.
the class ModelUtil method setParameterSchema.
/**
* Sets the given {@link Schema} on the given {@link Parameter}. This is tricky
* because the paramater may EITHER have a schema property or it may have a
* {@link Content} child which itself has zero or more {@link MediaType} children
* which will contain the {@link Schema}.
*
* The OpenAPI specification requires that a parameter have *either* a schema
* or a content, but not both.
* @param parameter
* @param schema
*/
public static void setParameterSchema(Parameter parameter, Schema schema) {
if (schema == null) {
return;
}
if (parameter.getContent() == null) {
parameter.schema(schema);
return;
}
Content content = parameter.getContent();
if (content.isEmpty()) {
String[] defMediaTypes = OpenApiConstants.DEFAULT_PARAMETER_MEDIA_TYPES;
for (String mediaTypeName : defMediaTypes) {
MediaType mediaType = new MediaTypeImpl();
mediaType.setSchema(schema);
content.addMediaType(mediaTypeName, mediaType);
}
return;
}
for (String mediaTypeName : content.keySet()) {
MediaType mediaType = content.get(mediaTypeName);
mediaType.setSchema(schema);
}
}
use of org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl 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.media.MediaTypeImpl in project wildfly-swarm by wildfly-swarm.
the class ModelUtil method setRequestBodySchema.
/**
* Sets the given {@link Schema} on the given {@link RequestBody}.
* @param requestBody
* @param schema
* @param mediaTypes
*/
public static void setRequestBodySchema(RequestBody requestBody, Schema schema, String[] mediaTypes) {
Content content = requestBody.getContent();
if (content == null) {
content = new ContentImpl();
requestBody.setContent(content);
}
if (content.isEmpty()) {
String[] requestBodyTypes = OpenApiConstants.DEFAULT_REQUEST_BODY_TYPES;
if (mediaTypes != null && mediaTypes.length > 0) {
requestBodyTypes = mediaTypes;
}
for (String mediaTypeName : requestBodyTypes) {
MediaType mediaType = new MediaTypeImpl();
mediaType.setSchema(schema);
content.addMediaType(mediaTypeName, mediaType);
}
return;
}
for (String mediaTypeName : content.keySet()) {
MediaType mediaType = content.get(mediaTypeName);
mediaType.setSchema(schema);
}
}
Aggregations