Search in sources :

Example 6 with MediaType

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"));
}
Also used : OASFactory.createXML(org.eclipse.microprofile.openapi.OASFactory.createXML) XML(org.eclipse.microprofile.openapi.models.media.XML) OASFactory.createMediaType(org.eclipse.microprofile.openapi.OASFactory.createMediaType) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) OASFactory.createEncoding(org.eclipse.microprofile.openapi.OASFactory.createEncoding) OASFactory.createDiscriminator(org.eclipse.microprofile.openapi.OASFactory.createDiscriminator) Discriminator(org.eclipse.microprofile.openapi.models.media.Discriminator)

Example 7 with MediaType

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;
}
Also used : MediaTypeImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 8 with 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);
    }
}
Also used : Content(org.eclipse.microprofile.openapi.models.media.Content) MediaTypeImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 9 with MediaType

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);
    }
}
Also used : ArrayList(java.util.ArrayList) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 10 with MediaType

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);
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Aggregations

MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)18 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)5 Schema (org.eclipse.microprofile.openapi.models.media.Schema)5 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)4 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)4 Content (org.eclipse.microprofile.openapi.models.media.Content)4 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)4 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)4 MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)4 MediaTypeImpl (org.wildfly.swarm.microprofile.openapi.api.models.media.MediaTypeImpl)4 ContentImpl (org.wildfly.swarm.microprofile.openapi.api.models.media.ContentImpl)3 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)2 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)2 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)2 APIResponsesImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl)2 Encoding (org.eclipse.microprofile.openapi.models.media.Encoding)2 SchemaType (org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)2 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)2 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)1