use of org.eclipse.microprofile.openapi.models.media.MediaType 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.eclipse.microprofile.openapi.models.media.MediaType 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.eclipse.microprofile.openapi.models.media.MediaType in project wildfly-swarm by wildfly-swarm.
the class FilterUtil method filterContent.
/**
* Filters the given model.
* @param filter
* @param model
*/
private static void filterContent(OASFilter filter, Content model) {
if (model == null) {
return;
}
Collection<String> keys = new ArrayList<>(model.keySet());
for (String key : keys) {
MediaType childModel = model.get(key);
filterMediaType(filter, childModel);
}
}
use of org.eclipse.microprofile.openapi.models.media.MediaType in project Payara by payara.
the class ApplicationProcessor method insertDefaultResponse.
/**
* Creates a new {@link APIResponse} to model the default response of a
* {@link Method}, and inserts it into the {@link Operation} responses.
*
* @param context the API context.
* @param operation the {@link Operation} to add the default response to.
* @param method the {@link Method} to model the default response on.
* @return the newly created {@link APIResponse}.
*/
private void insertDefaultResponse(ApiContext context, OperationImpl operation, MethodModel method) {
final APIResponsesImpl responses = new APIResponsesImpl();
operation.setResponses(responses);
// Add the default response
APIResponse defaultResponse = new APIResponseImpl();
responses.addAPIResponse(APIResponses.DEFAULT, defaultResponse);
defaultResponse.setDescription("Default Response.");
// Configure the default response with a wildcard mediatype
MediaType mediaType = new MediaTypeImpl().schema(createSchema(context, method.getReturnType()));
defaultResponse.getContent().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, mediaType);
// Add responses for the applicable declared exceptions
for (String exceptionType : method.getExceptionTypes()) {
final APIResponseImpl mappedResponse = (APIResponseImpl) context.getMappedExceptionResponses().get(exceptionType);
if (mappedResponse != null) {
final String responseCode = mappedResponse.getResponseCode();
if (responseCode != null) {
responses.addAPIResponse(responseCode, mappedResponse);
}
}
operation.addExceptionType(exceptionType);
}
}
use of org.eclipse.microprofile.openapi.models.media.MediaType in project Payara by payara.
the class ApplicationProcessor method visitFormParam.
@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
// Find the aggregate schema type of all the parameters
SchemaType formSchemaType = null;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
}
}
}
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
// If there's no request body, fill out a new one right down to the schema
if (workingOperation.getRequestBody() == null) {
workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
}
for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
final Schema schema = mediaType.getSchema();
if (schema != null) {
schema.setType(formSchemaType);
}
}
}
}
Aggregations