Search in sources :

Example 1 with Header

use of org.eclipse.microprofile.openapi.models.headers.Header in project wildfly-swarm by wildfly-swarm.

the class OpenApiParser method readHeaders.

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

Example 2 with Header

use of org.eclipse.microprofile.openapi.models.headers.Header in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readHeader.

/**
 * Reads a Header annotation into a model.
 * @param annotation
 */
private Header readHeader(AnnotationInstance annotation) {
    if (annotation == null) {
        return null;
    }
    LOG.debug("Processing a single @Header annotation.");
    Header header = new HeaderImpl();
    header.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
    header.setSchema(readSchema(annotation.value(OpenApiConstants.PROP_SCHEMA)));
    header.setRequired(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_REQUIRED));
    header.setDeprecated(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_DEPRECATED));
    header.setAllowEmptyValue(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_ALLOW_EMPTY_VALUE));
    header.setRef(JandexUtil.refValue(annotation, RefType.Header));
    return header;
}
Also used : Header(org.eclipse.microprofile.openapi.models.headers.Header) HeaderImpl(org.wildfly.swarm.microprofile.openapi.api.models.headers.HeaderImpl)

Example 3 with Header

use of org.eclipse.microprofile.openapi.models.headers.Header in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterHeaders.

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

Example 4 with Header

use of org.eclipse.microprofile.openapi.models.headers.Header in project Payara by payara.

the class HeaderImpl method merge.

public static void merge(String headerName, Header header, Map<String, Header> headers, boolean override, ApiContext context) {
    if (header == null) {
        return;
    }
    // Get the header name
    if (headerName == null || headerName.isEmpty()) {
        headerName = UNKNOWN_ELEMENT_NAME;
    }
    // Get or create the header
    Header model = headers.getOrDefault(headerName, new HeaderImpl());
    headers.put(headerName, model);
    // Merge the annotation
    merge(header, model, override, context);
    // If the merged annotation has a reference, set the name to the reference
    if (model.getRef() != null) {
        headers.remove(headerName);
        headers.put(model.getRef().split("/")[3], model);
    }
}
Also used : Header(org.eclipse.microprofile.openapi.models.headers.Header)

Example 5 with Header

use of org.eclipse.microprofile.openapi.models.headers.Header in project Payara by payara.

the class HeaderImpl method createInstances.

public static Map<String, Header> createInstances(AnnotationModel annotation, ApiContext context) {
    Map<String, Header> map = createMap();
    List<AnnotationModel> headers = annotation.getValue("headers", List.class);
    if (headers != null) {
        for (AnnotationModel header : headers) {
            String headerName = header.getValue("name", String.class);
            if (headerName == null) {
                headerName = header.getValue("ref", String.class);
            }
            map.put(headerName, createInstance(header, context));
        }
    }
    return map;
}
Also used : Header(org.eclipse.microprofile.openapi.models.headers.Header) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel)

Aggregations

Header (org.eclipse.microprofile.openapi.models.headers.Header)8 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)2 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)2 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)2 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)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 LinkedHashMap (java.util.LinkedHashMap)2 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)2 Example (org.eclipse.microprofile.openapi.models.examples.Example)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 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