Search in sources :

Example 11 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.

the class OASMerge method merge.

public static void merge(Header from, Header into) {
    if (into == null) {
        throw new IllegalArgumentException("Header 'into' parameter can not be null");
    }
    if (from != null) {
        String fromRef = from.getRef();
        if (fromRef != null) {
            into.setRef(fromRef);
        }
        String fromDescription = from.getDescription();
        if (fromDescription != null) {
            into.setDescription(fromDescription);
        }
        Boolean fromRequired = from.getRequired();
        if (fromRequired != null) {
            into.setRequired(fromRequired);
        }
        Boolean fromDeprecated = from.getDeprecated();
        if (fromDeprecated != null) {
            into.setDeprecated(fromDeprecated);
        }
        Boolean fromAllowEmptyValue = from.getAllowEmptyValue();
        if (fromAllowEmptyValue != null) {
            into.setAllowEmptyValue(fromAllowEmptyValue);
        }
        Header.Style fromStyle = from.getStyle();
        if (fromStyle != null) {
            into.setStyle(fromStyle);
        }
        Boolean fromExplode = from.getExplode();
        if (fromExplode != null) {
            into.setExplode(fromExplode);
        }
        Schema fromSchema = from.getSchema();
        if (fromSchema != null) {
            Schema intoSchema = into.getSchema();
            if (intoSchema != null) {
                merge(fromSchema, intoSchema);
            } else {
                into.setSchema(OASCopy.copy(fromSchema));
            }
        }
        Map<String, Example> fromExamples = from.getExamples();
        if (fromExamples != null) {
            Map<String, Example> intoExamples = into.getExamples();
            if (intoExamples != null) {
                for (Entry<String, Example> entry : fromExamples.entrySet()) {
                    if (intoExamples.containsKey(entry.getKey())) {
                        merge(entry.getValue(), intoExamples.get(entry.getKey()));
                    } else {
                        into.addExample(entry.getKey(), OASCopy.copy(entry.getValue()));
                    }
                }
            } else {
                for (Entry<String, Example> entry : fromExamples.entrySet()) {
                    into.addExample(entry.getKey(), OASCopy.copy(entry.getValue()));
                }
            }
        }
        Object fromExample = from.getExample();
        if (fromExample != null) {
            into.setExample(fromExample);
        }
        Content fromContent = from.getContent();
        if (fromContent != null) {
            Content intoContent = into.getContent();
            if (intoContent != null) {
                merge(fromContent, intoContent);
            } else {
                into.setContent(OASCopy.copy(fromContent));
            }
        }
        Map<String, Object> extensions = from.getExtensions();
        if (extensions != null) {
            for (Entry<String, Object> entry : extensions.entrySet()) {
                into.addExtension(entry.getKey(), entry.getValue());
            }
        }
    }
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) Header(org.eclipse.microprofile.openapi.models.headers.Header) Content(org.eclipse.microprofile.openapi.models.media.Content) Example(org.eclipse.microprofile.openapi.models.examples.Example)

Example 12 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.

the class OASMerge method merge.

public static void merge(MediaType from, MediaType into) {
    if (into == null) {
        throw new IllegalArgumentException("MediaType 'into' parameter can not be null");
    }
    if (from != null) {
        Schema fromSchema = from.getSchema();
        if (fromSchema != null) {
            Schema intoSchema = into.getSchema();
            if (intoSchema != null) {
                merge(fromSchema, intoSchema);
            } else {
                into.setSchema(OASCopy.copy(fromSchema));
            }
        }
        Map<String, Example> fromExamples = from.getExamples();
        if (fromExamples != null) {
            Map<String, Example> intoExamples = into.getExamples();
            if (intoExamples != null) {
                for (Entry<String, Example> entry : fromExamples.entrySet()) {
                    if (intoExamples.containsKey(entry.getKey())) {
                        merge(entry.getValue(), intoExamples.get(entry.getKey()));
                    } else {
                        into.addExample(entry.getKey(), OASCopy.copy(entry.getValue()));
                    }
                }
            } else {
                for (Entry<String, Example> entry : fromExamples.entrySet()) {
                    into.addExample(entry.getKey(), OASCopy.copy(entry.getValue()));
                }
            }
        }
        Object fromExample = from.getExample();
        if (fromExample != null) {
            into.setExample(fromExample);
        }
        Map<String, Encoding> fromEncoding = from.getEncoding();
        if (fromEncoding != null) {
            Map<String, Encoding> intoEncoding = into.getEncoding();
            if (intoEncoding != null) {
                for (Entry<String, Encoding> entry : fromEncoding.entrySet()) {
                    if (intoEncoding.containsKey(entry.getKey())) {
                        merge(entry.getValue(), intoEncoding.get(entry.getKey()));
                    } else {
                        into.addEncoding(entry.getKey(), OASCopy.copy(entry.getValue()));
                    }
                }
            } else {
                for (Entry<String, Encoding> entry : fromEncoding.entrySet()) {
                    into.addEncoding(entry.getKey(), OASCopy.copy(entry.getValue()));
                }
            }
        }
        Map<String, Object> extensions = from.getExtensions();
        if (extensions != null) {
            for (Entry<String, Object> entry : extensions.entrySet()) {
                into.addExtension(entry.getKey(), entry.getValue());
            }
        }
    }
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) Example(org.eclipse.microprofile.openapi.models.examples.Example) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding)

Example 13 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.

the class OASCopy method copy.

public static Header copy(Header from) {
    if (from == null) {
        return null;
    }
    Header to = OASFactory.createHeader();
    to.setRef(from.getRef());
    to.setDescription(from.getDescription());
    to.setRequired(from.getRequired());
    to.setDeprecated(from.getDeprecated());
    to.setAllowEmptyValue(from.getAllowEmptyValue());
    to.setStyle(from.getStyle());
    to.setExplode(from.getExplode());
    to.setSchema(copy(from.getSchema()));
    Map<String, Example> examples = from.getExamples();
    if (examples != null) {
        for (Entry<String, Example> entry : examples.entrySet()) {
            to.addExample(entry.getKey(), copy(entry.getValue()));
        }
    }
    to.setExample(from.getExample());
    to.setContent(copy(from.getContent()));
    Map<String, Object> extensions = from.getExtensions();
    if (extensions != null) {
        for (Entry<String, Object> entry : extensions.entrySet()) {
            to.addExtension(entry.getKey(), entry.getValue());
        }
    }
    return to;
}
Also used : Header(org.eclipse.microprofile.openapi.models.headers.Header) Example(org.eclipse.microprofile.openapi.models.examples.Example)

Example 14 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.

the class AbstractElementSerializerTest method testExampleWithReferenceToJson.

@Test
public void testExampleWithReferenceToJson() throws Exception {
    Example example = OASElement.createExample().ref("#/components/examples/SomeExample").description("Some description");
    String json = convertToJson(example);
    assertThatJson(json).isEqualTo("" + "{" + "    \"$ref\": \"#/components/examples/SomeExample\"" + "}");
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) Test(org.junit.jupiter.api.Test)

Example 15 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project empoa by OpenAPITools.

the class AbstractElementSerializerTest method testEmptyExampleToJson.

@Test
public void testEmptyExampleToJson() throws Exception {
    Example example = OASFactory.createExample();
    String json = convertToJson(example);
    assertThatJson(json).isEqualTo("{}");
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) Test(org.junit.jupiter.api.Test)

Aggregations

Example (org.eclipse.microprofile.openapi.models.examples.Example)36 Schema (org.eclipse.microprofile.openapi.models.media.Schema)8 Test (org.junit.jupiter.api.Test)8 Header (org.eclipse.microprofile.openapi.models.headers.Header)7 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)7 LinkedHashMap (java.util.LinkedHashMap)6 Encoding (org.eclipse.microprofile.openapi.models.media.Encoding)5 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)4 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)4 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)4 Link (org.eclipse.microprofile.openapi.models.links.Link)4 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)4 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)4 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)4 Test (org.testng.annotations.Test)4 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)3 Components (org.eclipse.microprofile.openapi.models.Components)3 Content (org.eclipse.microprofile.openapi.models.media.Content)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2