Search in sources :

Example 1 with Link

use of org.eclipse.microprofile.openapi.models.links.Link in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readLinks.

/**
 * Reads a map of Link annotations.
 * @param value
 */
private Map<String, Link> readLinks(AnnotationValue value) {
    if (value == null) {
        return null;
    }
    LOG.debug("Processing a map of @Link annotations.");
    Map<String, Link> map = new LinkedHashMap<>();
    AnnotationInstance[] nestedArray = value.asNestedArray();
    for (AnnotationInstance nested : nestedArray) {
        String name = JandexUtil.stringValue(nested, OpenApiConstants.PROP_NAME);
        if (name == null && JandexUtil.isRef(nested)) {
            name = JandexUtil.nameFromRef(nested);
        }
        if (name != null) {
            map.put(name, readLink(nested));
        }
    }
    return map;
}
Also used : Link(org.eclipse.microprofile.openapi.models.links.Link) AnnotationInstance(org.jboss.jandex.AnnotationInstance) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Link

use of org.eclipse.microprofile.openapi.models.links.Link in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterLinks.

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

Example 3 with Link

use of org.eclipse.microprofile.openapi.models.links.Link in project Payara by payara.

the class LinkImpl method createInstance.

public static Link createInstance(AnnotationModel annotation, ApiContext context) {
    Link from = new LinkImpl();
    from.setOperationRef(annotation.getValue("operationRef", String.class));
    from.setOperationId(annotation.getValue("operationId", String.class));
    List<AnnotationModel> parametersAnnotation = annotation.getValue("parameters", List.class);
    if (parametersAnnotation != null) {
        for (AnnotationModel parameterAnnotation : parametersAnnotation) {
            from.addParameter(parameterAnnotation.getValue("name", String.class), parameterAnnotation.getValue("expression", String.class));
        }
    }
    from.setRequestBody(annotation.getValue("requestBody", String.class));
    from.setDescription(annotation.getValue("description", String.class));
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    AnnotationModel serverAnnotation = annotation.getValue("server", AnnotationModel.class);
    if (serverAnnotation != null) {
        from.setServer(ServerImpl.createInstance(serverAnnotation, context));
    }
    return from;
}
Also used : AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) Link(org.eclipse.microprofile.openapi.models.links.Link)

Example 4 with Link

use of org.eclipse.microprofile.openapi.models.links.Link in project Payara by payara.

the class LinkImpl method merge.

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

Example 5 with Link

use of org.eclipse.microprofile.openapi.models.links.Link in project Payara by payara.

the class ComponentsImpl method merge.

public static void merge(Components from, Components to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    // Handle @Schema
    if (from.getSchemas() != null) {
        for (Entry<String, Schema> fromEntry : from.getSchemas().entrySet()) {
            final String schemaName = fromEntry.getKey();
            if (schemaName != null) {
                final Schema fromSchema = fromEntry.getValue();
                final Schema toSchema = to.getSchemas().getOrDefault(schemaName, new SchemaImpl());
                SchemaImpl.merge(fromSchema, toSchema, override, context);
                to.addSchema(schemaName, toSchema);
            }
        }
    }
    // Handle @Callback
    if (from.getCallbacks() != null) {
        for (String callbackName : from.getCallbacks().keySet()) {
            if (callbackName != null) {
                Callback newCallback = new CallbackImpl();
                CallbackImpl.merge(from.getCallbacks().get(callbackName), newCallback, override, context);
                to.addCallback(callbackName, newCallback);
            }
        }
    }
    // Handle @ExampleObject
    if (from.getExamples() != null) {
        for (String exampleName : from.getExamples().keySet()) {
            if (exampleName != null) {
                Example newExample = new ExampleImpl();
                ExampleImpl.merge(from.getExamples().get(exampleName), newExample, override);
                to.addExample(exampleName, newExample);
            }
        }
    }
    // Handle @Header
    if (from.getHeaders() != null) {
        for (String headerName : from.getHeaders().keySet()) {
            if (headerName != null) {
                Header newHeader = new HeaderImpl();
                HeaderImpl.merge(from.getHeaders().get(headerName), newHeader, override, context);
                to.addHeader(headerName, newHeader);
            }
        }
    }
    // Handle @Link
    if (from.getLinks() != null) {
        for (String linkName : from.getLinks().keySet()) {
            if (linkName != null) {
                Link newLink = new LinkImpl();
                LinkImpl.merge(from.getLinks().get(linkName), newLink, override);
                to.addLink(linkName, newLink);
            }
        }
    }
    // Handle @Parameter
    if (from.getParameters() != null) {
        for (String parameterName : from.getParameters().keySet()) {
            if (parameterName != null) {
                Parameter newParameter = new ParameterImpl();
                ParameterImpl.merge(from.getParameters().get(parameterName), newParameter, override, context);
                to.addParameter(parameterName, newParameter);
            }
        }
    }
    // Handle @RequestBody
    if (from.getRequestBodies() != null) {
        for (String requestBodyName : from.getRequestBodies().keySet()) {
            if (requestBodyName != null) {
                RequestBody newRequestBody = new RequestBodyImpl();
                RequestBodyImpl.merge(from.getRequestBodies().get(requestBodyName), newRequestBody, override, context);
                to.addRequestBody(requestBodyName, newRequestBody);
            }
        }
    }
    // Handle @APIResponse
    if (from.getResponses() != null) {
        for (String responseName : from.getResponses().keySet()) {
            if (responseName != null) {
                APIResponse newResponse = new APIResponseImpl();
                APIResponseImpl.merge(from.getResponses().get(responseName), newResponse, override, context);
                to.addResponse(responseName, newResponse);
            }
        }
    }
    // Handle @SecurityScheme
    if (from.getSecuritySchemes() != null) {
        for (String securitySchemeName : from.getSecuritySchemes().keySet()) {
            if (securitySchemeName != null) {
                SecurityScheme newSecurity = new SecuritySchemeImpl();
                SecuritySchemeImpl.merge(from.getSecuritySchemes().get(securitySchemeName), newSecurity, override);
                to.addSecurityScheme(securitySchemeName, newSecurity);
            }
        }
    }
}
Also used : APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) HeaderImpl(fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Header(org.eclipse.microprofile.openapi.models.headers.Header) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Link(org.eclipse.microprofile.openapi.models.links.Link) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Aggregations

Link (org.eclipse.microprofile.openapi.models.links.Link)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 Header (org.eclipse.microprofile.openapi.models.headers.Header)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