Search in sources :

Example 1 with Encoding

use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.

the class OpenApiSerializer method writeEncodings.

/**
 * Writes a map of {@link Encoding} objects to the JSON tree.
 * @param parent
 * @param models
 */
private void writeEncodings(ObjectNode parent, Map<String, Encoding> models) {
    if (models == null) {
        return;
    }
    ObjectNode node = parent.putObject(OpenApiConstants.PROP_ENCODING);
    for (String name : models.keySet()) {
        Encoding encoding = models.get(name);
        writeEncoding(node, encoding, name);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding)

Example 2 with Encoding

use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readEncoding.

/**
 * Reads a single Encoding annotation into a model.
 * @param annotation
 */
private Encoding readEncoding(AnnotationInstance annotation) {
    if (annotation == null) {
        return null;
    }
    LOG.debug("Processing a single @Encoding annotation.");
    Encoding encoding = new EncodingImpl();
    encoding.setContentType(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_CONTENT_TYPE));
    encoding.setStyle(JandexUtil.enumValue(annotation, OpenApiConstants.PROP_STYLE, org.eclipse.microprofile.openapi.models.media.Encoding.Style.class));
    encoding.setExplode(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_EXPLODE));
    encoding.setAllowReserved(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_ALLOW_RESERVED));
    encoding.setHeaders(readHeaders(annotation.value(OpenApiConstants.PROP_HEADERS)));
    return encoding;
}
Also used : EncodingImpl(org.wildfly.swarm.microprofile.openapi.api.models.media.EncodingImpl) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding)

Example 3 with Encoding

use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readEncodings.

/**
 * Reads an array of Encoding annotations as a Map.
 * @param value
 */
private Map<String, Encoding> readEncodings(AnnotationValue value) {
    if (value == null) {
        return null;
    }
    LOG.debug("Processing a map of @Encoding annotations.");
    Map<String, Encoding> map = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = value.asNestedArray();
    for (AnnotationInstance annotation : nestedArray) {
        String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_NAME);
        if (name != null) {
            map.put(name, readEncoding(annotation));
        }
    }
    return map;
}
Also used : Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) AnnotationInstance(org.jboss.jandex.AnnotationInstance) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Encoding

use of org.eclipse.microprofile.openapi.models.media.Encoding in project Payara by payara.

the class ContentImpl method merge.

public static void merge(ContentImpl from, Content to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    for (Map.Entry<String, MediaType> fromEntry : from.getMediaTypes().entrySet()) {
        final String typeName = fromEntry.getKey();
        final MediaType fromMediaType = fromEntry.getValue();
        // Get or create the corresponding media type
        MediaTypeImpl toMediaType = (MediaTypeImpl) to.getMediaTypes().getOrDefault(typeName, new MediaTypeImpl());
        to.addMediaType(typeName, toMediaType);
        // Merge encoding
        for (Map.Entry<String, Encoding> encoding : fromMediaType.getEncoding().entrySet()) {
            EncodingImpl.merge(encoding.getKey(), encoding.getValue(), toMediaType.encoding, override, context);
        }
        // Merge examples
        for (Map.Entry<String, Example> example : fromMediaType.getExamples().entrySet()) {
            ExampleImpl.merge(example.getKey(), example.getValue(), toMediaType.examples, override);
        }
        toMediaType.setExample(mergeProperty(toMediaType.getExample(), fromMediaType.getExample(), override));
        // Merge schema
        if (fromMediaType.getSchema() != null) {
            if (toMediaType.getSchema() == null) {
                toMediaType.setSchema(new SchemaImpl());
            }
            Schema schema = toMediaType.getSchema();
            SchemaImpl.merge(fromMediaType.getSchema(), schema, true, context);
        }
    }
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) Schema(org.eclipse.microprofile.openapi.models.media.Schema) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with Encoding

use of org.eclipse.microprofile.openapi.models.media.Encoding 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)

Aggregations

Encoding (org.eclipse.microprofile.openapi.models.media.Encoding)9 LinkedHashMap (java.util.LinkedHashMap)2 Example (org.eclipse.microprofile.openapi.models.examples.Example)2 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)1 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)1 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)1 ContactImpl (fish.payara.microprofile.openapi.impl.model.info.ContactImpl)1 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)1 LicenseImpl (fish.payara.microprofile.openapi.impl.model.info.LicenseImpl)1 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)1 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)1 DiscriminatorImpl (fish.payara.microprofile.openapi.impl.model.media.DiscriminatorImpl)1 EncodingImpl (fish.payara.microprofile.openapi.impl.model.media.EncodingImpl)1 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)1 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)1 XMLImpl (fish.payara.microprofile.openapi.impl.model.media.XMLImpl)1 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)1 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)1