Search in sources :

Example 1 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.

the class OpenApiParser method readExamples.

/**
 * Reads the {@link Example} OpenAPI nodes.
 * @param node
 */
private Map<String, Example> readExamples(JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    Map<String, Example> models = new LinkedHashMap<>();
    for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
        String fieldName = fieldNames.next();
        JsonNode childNode = node.get(fieldName);
        models.put(fieldName, readExample(childNode));
    }
    return models;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readExample.

/**
 * Reads a Example annotation into a model.
 * @param annotation
 */
private Example readExample(AnnotationInstance annotation) {
    if (annotation == null) {
        return null;
    }
    LOG.debug("Processing a single @ExampleObject annotation.");
    Example example = new ExampleImpl();
    example.setSummary(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SUMMARY));
    example.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
    example.setValue(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_VALUE));
    example.setExternalValue(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_EXTERNAL_VALUE));
    example.setRef(JandexUtil.refValue(annotation, RefType.Example));
    return example;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) ExampleImpl(org.wildfly.swarm.microprofile.openapi.api.models.examples.ExampleImpl)

Example 3 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterExamples.

/**
 * Filters the given models.
 * @param filter
 * @param models
 */
private static void filterExamples(OASFilter filter, Map<String, Example> models) {
    if (models == null) {
        return;
    }
    Collection<String> keys = new ArrayList<>(models.keySet());
    for (String key : keys) {
        Example model = models.get(key);
        filterExample(filter, model);
    }
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) ArrayList(java.util.ArrayList)

Example 4 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project Payara by payara.

the class ParameterImpl method merge.

public static void merge(Parameter from, Parameter to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    if (from.getRef() != null && !from.getRef().isEmpty()) {
        applyReference(to, from.getRef());
        return;
    }
    to.setName(mergeProperty(to.getName(), from.getName(), override));
    to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
    if (from.getIn() != null) {
        to.setIn(mergeProperty(to.getIn(), from.getIn(), override));
    }
    to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
    to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
    to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
    if (from.getStyle() != null) {
        to.setStyle(mergeProperty(to.getStyle(), from.getStyle(), override));
    }
    if (from.getExplode() != null) {
        to.setExplode(mergeProperty(to.getExplode(), false, override));
    }
    to.setAllowReserved(mergeProperty(to.getAllowReserved(), from.getAllowReserved(), override));
    if (from.getSchema() != null) {
        if (to.getSchema() == null) {
            to.setSchema(new SchemaImpl());
        }
        SchemaImpl.merge(from.getSchema(), to.getSchema(), override, context);
    }
    to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
    if (from.getExamples() != null) {
        for (String exampleName : from.getExamples().keySet()) {
            if (exampleName != null) {
                Example example = new ExampleImpl();
                ExampleImpl.merge(from.getExamples().get(exampleName), example, override);
                to.addExample(exampleName, example);
            }
        }
    }
    if (from instanceof ParameterImpl) {
        ParameterImpl fromImpl = (ParameterImpl) from;
        if (fromImpl.getContents() != null) {
            if (to.getContent() == null) {
                to.setContent(new ContentImpl());
            }
            for (ContentImpl content : fromImpl.getContents()) {
                ContentImpl.merge(content, to.getContent(), override, context);
            }
        }
    }
    if (from.getContent() != null) {
        if (to.getContent() == null) {
            to.setContent(new ContentImpl());
        }
        ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
    }
}
Also used : SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 5 with Example

use of org.eclipse.microprofile.openapi.models.examples.Example in project Payara by payara.

the class ExampleImpl method createInstance.

public static Example createInstance(AnnotationModel annotation, ApiContext context) {
    Example from = new ExampleImpl();
    from.setSummary(annotation.getValue("summary", String.class));
    from.setDescription(annotation.getValue("description", String.class));
    from.setValue(annotation.getValue("value", Object.class));
    from.setExternalValue(annotation.getValue("externalValue", String.class));
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    return from;
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example)

Aggregations

Example (org.eclipse.microprofile.openapi.models.examples.Example)11 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)4 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)4 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)3 LinkedHashMap (java.util.LinkedHashMap)3 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)2 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)2 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)2 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)2 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)2 SecuritySchemeImpl (fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl)2 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)2 Header (org.eclipse.microprofile.openapi.models.headers.Header)2 Schema (org.eclipse.microprofile.openapi.models.media.Schema)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)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 DiscriminatorImpl (fish.payara.microprofile.openapi.impl.model.media.DiscriminatorImpl)1