use of org.eclipse.microprofile.openapi.models.media.MediaType in project Payara by payara.
the class MediaBuilderTest method setupBaseDocument.
@Override
protected void setupBaseDocument(OpenAPI document) {
document.getComponents().addSchema("SimpleMap", createSchema().type(SchemaType.OBJECT).additionalPropertiesSchema(createSchema().type(SchemaType.STRING)));
XML xml = createXML().name("name").namespace("namespace").prefix("prefix").attribute(true).wrapped(true).addExtension("x-ext", "ext-value");
document.getComponents().addSchema("XML", createSchema().xml(xml));
Encoding encoding = createEncoding().contentType("contentType").style(Style.FORM).explode(true).allowReserved(true).addExtension("x-ext", "ext-value").addHeader("header1", createHeader().ref("ref1")).addHeader("header2", createHeader().ref("ref2"));
MediaType mediaType = createMediaType().example("example").schema(createSchema().ref("ref")).addExtension("x-ext", "ext-value").addExample("example1", createExample().ref("ref1")).addExample("example2", createExample().ref("ref2")).addEncoding("encoding1", encoding);
document.getComponents().addResponse("MediaType", createAPIResponse().description("description").content(createContent().addMediaType("type1", mediaType)));
Discriminator discriminator = createDiscriminator().propertyName("propertyName").addMapping("key1", "value1").addMapping("key2", "value2");
document.getComponents().addSchema("Discriminator", createSchema().discriminator(discriminator));
document.getComponents().addSchema("Schema", createSchema().title("title").multipleOf(BigDecimal.ONE).maximum(BigDecimal.ONE).exclusiveMaximum(true).minimum(BigDecimal.ONE).exclusiveMinimum(true).maxLength(10).minLength(1).pattern("pattern").maxItems(11).minItems(2).uniqueItems(true).maxProperties(12).minProperties(3).addRequired("required1").addRequired("required2").type(SchemaType.NUMBER).not(createSchema().ref("not")).addProperty("property1", createSchema().ref("property1")).description("description").format("format").nullable(true).readOnly(true).writeOnly(true).example("example").externalDocs(createExternalDocumentation().url("url")).deprecated(true).xml(xml).addEnumeration("enumeration1").addEnumeration("enumeration2").discriminator(discriminator).addAnyOf(createSchema().ref("anyOf1")).addAnyOf(createSchema().ref("anyOf2")).addAllOf(createSchema().ref("allOf1")).addAllOf(createSchema().ref("allOf2")).addOneOf(createSchema().ref("oneOf1")).addOneOf(createSchema().ref("oneOf2")).additionalPropertiesBoolean(true).items(createSchema().ref("items")).addExtension("x-ext", "ext-value"));
}
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 visitConsumes.
@Override
public void visitConsumes(AnnotationModel consumes, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel && context.getWorkingOperation() != null) {
RequestBody requestBody = context.getWorkingOperation().getRequestBody();
if (requestBody != null) {
// Find the wildcard return type
if (requestBody.getContent() != null && requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
MediaType wildcardMedia = requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
// Copy the wildcard return type to the valid request body types
List<String> mediaTypes = consumes.getValue("value", List.class);
for (String mediaType : mediaTypes) {
requestBody.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
}
// If there is an @Consumes, remove the wildcard
requestBody.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
}
}
}
}
Aggregations