Search in sources :

Example 1 with Reference

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

the class ApplicationProcessor method findOperationParameterFor.

private static Parameter findOperationParameterFor(Parameter parameter, MethodModel annotated, ApiContext context) {
    String name = parameter.getName();
    // If the parameter reference is valid
    if (name != null && !name.isEmpty()) {
        // Get all parameters with the same name
        List<org.glassfish.hk2.classmodel.reflect.Parameter> matchingMethodParameters = annotated.getParameters().stream().filter(x -> name.equals(ModelUtils.getParameterName(context, x))).collect(Collectors.toList());
        // If there is more than one match, filter it further
        In in = parameter.getIn();
        if (matchingMethodParameters.size() > 1 && in != null) {
            // Remove all parameters of the wrong input type
            matchingMethodParameters.removeIf(x -> ModelUtils.getParameterType(context, x) != In.valueOf(in.name()));
        }
        if (matchingMethodParameters.isEmpty()) {
            return null;
        }
        // If there's only one matching parameter, handle it immediately
        String matchingMethodParamName = ModelUtils.getParameterName(context, matchingMethodParameters.get(0));
        // Find the matching operation parameter
        for (Parameter operationParam : context.getWorkingOperation().getParameters()) {
            if (operationParam.getName().equals(matchingMethodParamName)) {
                return operationParam;
            }
        }
    }
    return null;
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Arrays(java.util.Arrays) ExtensibleImpl(fish.payara.microprofile.openapi.impl.model.ExtensibleImpl) ModelUtils.isVoid(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid) PathItem(org.eclipse.microprofile.openapi.models.PathItem) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) DefaultValue(javax.ws.rs.DefaultValue) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Method(java.lang.reflect.Method) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Collection(java.util.Collection) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) Set(java.util.Set) WARNING(java.util.logging.Level.WARNING) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) ApiVisitor(fish.payara.microprofile.openapi.api.visitor.ApiVisitor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) List(java.util.List) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Entry(java.util.Map.Entry) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) OASProcessor(fish.payara.microprofile.openapi.api.processor.OASProcessor) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ModelUtils(fish.payara.microprofile.openapi.impl.model.util.ModelUtils) HttpMethod(javax.ws.rs.HttpMethod) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) Schema(org.eclipse.microprofile.openapi.models.media.Schema) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Status(javax.ws.rs.core.Response.Status) FINE(java.util.logging.Level.FINE) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Types(org.glassfish.hk2.classmodel.reflect.Types) FormParam(javax.ws.rs.FormParam) OpenApiWalker(fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) EnumType(org.glassfish.hk2.classmodel.reflect.EnumType) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Reference(org.eclipse.microprofile.openapi.models.Reference) ApiContext(fish.payara.microprofile.openapi.api.visitor.ApiContext) Collections(java.util.Collections) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Type(org.glassfish.hk2.classmodel.reflect.Type) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)

Example 2 with Reference

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

the class MergeUtil method mergeMaps.

/**
 * Merges two Maps.  Any values missing from Map1 but present in Map2 will be added.  If a value
 * is present in both maps, it will be overridden or merged.
 * @param values1
 * @param values2
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map mergeMaps(Map values1, Map values2) {
    if (values1 == null && values2 == null) {
        return null;
    }
    if (values1 != null && values2 == null) {
        return values1;
    }
    if (values1 == null && values2 != null) {
        return values2;
    }
    for (Object key : values2.keySet()) {
        if (values1.containsKey(key)) {
            Object pval1 = values1.get(key);
            Object pval2 = values2.get(key);
            if (pval1 instanceof Map) {
                values1.put(key, mergeMaps((Map) pval1, (Map) pval2));
            } else if (pval1 instanceof List) {
                values1.put(key, mergeLists((List) pval1, (List) pval2));
            } else if (pval1 instanceof Constructible) {
                values1.put(key, mergeObjects(pval1, pval2));
            } else {
                values1.put(key, pval2);
            }
        } else {
            Object pval2 = values2.get(key);
            values1.put(key, pval2);
        }
    }
    if (values1 instanceof Constructible) {
        if (values1 instanceof Reference) {
            Reference ref1 = (Reference) values1;
            Reference ref2 = (Reference) values2;
            if (ref2.getRef() != null) {
                ref1.setRef(ref2.getRef());
            }
        }
        if (values1 instanceof Extensible) {
            Extensible extensible1 = (Extensible) values1;
            Extensible extensible2 = (Extensible) values2;
            extensible1.setExtensions(mergeMaps(extensible1.getExtensions(), extensible2.getExtensions()));
        }
        if (values1 instanceof APIResponses) {
            APIResponses responses1 = (APIResponses) values1;
            APIResponses responses2 = (APIResponses) values2;
            responses1.defaultValue(mergeObjects(responses1.getDefault(), responses2.getDefault()));
        }
    }
    return values1;
}
Also used : Constructible(org.eclipse.microprofile.openapi.models.Constructible) Extensible(org.eclipse.microprofile.openapi.models.Extensible) Reference(org.eclipse.microprofile.openapi.models.Reference) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Reference (org.eclipse.microprofile.openapi.models.Reference)2 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)2 OASProcessor (fish.payara.microprofile.openapi.api.processor.OASProcessor)1 ApiContext (fish.payara.microprofile.openapi.api.visitor.ApiContext)1 ApiVisitor (fish.payara.microprofile.openapi.api.visitor.ApiVisitor)1 OpenApiConfiguration (fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration)1 ExtensibleImpl (fish.payara.microprofile.openapi.impl.model.ExtensibleImpl)1 ExternalDocumentationImpl (fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl)1 OpenAPIImpl (fish.payara.microprofile.openapi.impl.model.OpenAPIImpl)1 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)1 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)1 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)1 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)1 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)1 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)1 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)1 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)1 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)1