Search in sources :

Example 6 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 7 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)

Example 8 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.

the class ExampleReader method readExample.

/**
 * Reads a Example annotation into a model.
 *
 * @param context the scanning context
 * @param annotationInstance {@literal @}ExampleObject annotation
 * @return Example model
 */
private static Example readExample(final AnnotationScannerContext context, final AnnotationInstance annotationInstance) {
    if (annotationInstance == null) {
        return null;
    }
    IoLogging.logger.singleAnnotation("@ExampleObject");
    Example example = new ExampleImpl();
    example.setRef(JandexUtil.refValue(annotationInstance, JandexUtil.RefType.EXAMPLE));
    example.setSummary(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_SUMMARY));
    example.setDescription(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_DESCRIPTION));
    example.setValue(parseValue(context, JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_VALUE)));
    example.setExternalValue(JandexUtil.stringValue(annotationInstance, ExampleConstant.PROP_EXTERNAL_VALUE));
    return example;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) ExampleImpl(io.smallrye.openapi.api.models.examples.ExampleImpl)

Example 9 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.

the class ExampleReader method readExample.

/**
 * Reads a {@link Example} OpenAPI node.
 *
 * @param node the example json node
 * @return Example model
 */
private static Example readExample(final JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    IoLogging.logger.singleJsonNode("ExampleObject");
    Example example = new ExampleImpl();
    example.setRef(JsonUtil.stringProperty(node, Referenceable.PROP_$REF));
    example.setSummary(JsonUtil.stringProperty(node, ExampleConstant.PROP_SUMMARY));
    example.setDescription(JsonUtil.stringProperty(node, ExampleConstant.PROP_DESCRIPTION));
    example.setValue(readObject(node.get(ExampleConstant.PROP_VALUE)));
    example.setExternalValue(JsonUtil.stringProperty(node, ExampleConstant.PROP_EXTERNAL_VALUE));
    ExtensionReader.readExtensions(node, example);
    return example;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) ExampleImpl(io.smallrye.openapi.api.models.examples.ExampleImpl)

Example 10 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project smallrye-open-api by smallrye.

the class ExampleReader method readExamples.

/**
 * Reads a map of Example annotations.
 *
 * @param context the scanning context
 * @param annotationValue map of {@literal @}ExampleObject annotations
 * @return Map of Example model
 */
public static Map<String, Example> readExamples(final AnnotationScannerContext context, final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }
    IoLogging.logger.annotationsMap("@ExampleObject");
    Map<String, Example> examples = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, ExampleConstant.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            examples.put(name, readExample(context, nested));
        }
    }
    return examples;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) AnnotationInstance(org.jboss.jandex.AnnotationInstance) LinkedHashMap(java.util.LinkedHashMap)

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