Search in sources :

Example 1 with SecurityRequirementImpl

use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.

the class OpenAPIImpl method createInstance.

public static OpenAPI createInstance(AnnotationModel annotation, ApiContext context) {
    OpenAPIImpl from = new OpenAPIImpl();
    from.context = context;
    AnnotationModel info = annotation.getValue("info", AnnotationModel.class);
    if (info != null) {
        from.setInfo(InfoImpl.createInstance(info));
    }
    AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
    if (externalDocs != null) {
        from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
    }
    extractAnnotations(annotation, context, "security", SecurityRequirementImpl::createInstance, from::addSecurityRequirement);
    extractAnnotations(annotation, context, "servers", ServerImpl::createInstance, from::addServer);
    extractAnnotations(annotation, context, "tags", TagImpl::createInstance, from::addTag);
    AnnotationModel components = annotation.getValue("components", AnnotationModel.class);
    if (components != null) {
        from.setComponents(ComponentsImpl.createInstance(components, context));
    }
    return from;
}
Also used : ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel)

Example 2 with SecurityRequirementImpl

use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.

the class OperationImpl method createInstance.

public static Operation createInstance(AnnotationModel annotation, ApiContext context) {
    OperationImpl from = new OperationImpl();
    from.setSummary(annotation.getValue("summary", String.class));
    from.setDescription(annotation.getValue("description", String.class));
    AnnotationModel externalDocs = annotation.getValue("externalDocs", AnnotationModel.class);
    if (externalDocs != null) {
        from.setExternalDocs(ExternalDocumentationImpl.createInstance(externalDocs));
    }
    from.setOperationId(annotation.getValue("operationId", String.class));
    extractAnnotations(annotation, context, "parameters", ParameterImpl::createInstance, from::addParameter);
    AnnotationModel requestBody = annotation.getValue("requestBody", AnnotationModel.class);
    if (requestBody != null) {
        from.setRequestBody(RequestBodyImpl.createInstance(requestBody, context));
    }
    extractAnnotations(annotation, context, "responses", "responseCode", APIResponseImpl::createInstance, from.responses::addAPIResponse);
    extractAnnotations(annotation, context, "callbacks", "name", CallbackImpl::createInstance, from::addCallback);
    from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
    extractAnnotations(annotation, context, "security", SecurityRequirementImpl::createInstance, from::addSecurityRequirement);
    extractAnnotations(annotation, context, "servers", ServerImpl::createInstance, from::addServer);
    from.setMethod(annotation.getValue("method", String.class));
    return from;
}
Also used : CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)

Example 3 with SecurityRequirementImpl

use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.

the class ApplicationProcessor method visitSecurityRequirement.

@Override
public void visitSecurityRequirement(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        String securityRequirementName = annotation.getValue("name", String.class);
        SecurityRequirement securityRequirement = SecurityRequirementImpl.createInstance(annotation, context);
        if (securityRequirementName != null && !securityRequirementName.isEmpty()) {
            SecurityRequirement model = new SecurityRequirementImpl();
            SecurityRequirementImpl.merge(securityRequirement, model);
            context.getWorkingOperation().addSecurityRequirement(model);
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)

Example 4 with SecurityRequirementImpl

use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.

the class OpenAPIImpl method merge.

public static void merge(OpenAPI from, OpenAPI to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    to.setOpenapi(mergeProperty(to.getOpenapi(), from.getOpenapi(), override));
    // Handle @Info
    if (from.getInfo() != null) {
        if (to.getInfo() == null) {
            to.setInfo(new InfoImpl());
        }
        InfoImpl.merge(from.getInfo(), to.getInfo(), override);
    }
    // Handle @Servers
    if (from.getServers() != null) {
        for (Server server : from.getServers()) {
            if (server != null) {
                Server newServer = new ServerImpl();
                ServerImpl.merge(server, newServer, true);
                if (!to.getServers().contains(newServer)) {
                    to.addServer(newServer);
                }
            }
        }
    }
    // Handle @ExternalDocumentation
    if (from.getExternalDocs() != null) {
        if (to.getExternalDocs() == null) {
            to.setExternalDocs(new ExternalDocumentationImpl());
        }
        ExternalDocumentationImpl.merge(from.getExternalDocs(), to.getExternalDocs(), override);
    }
    // Handle @SecurityRequirement
    if (from.getSecurity() != null) {
        for (SecurityRequirement requirement : from.getSecurity()) {
            if (requirement != null) {
                SecurityRequirement newRequirement = new SecurityRequirementImpl();
                SecurityRequirementImpl.merge(requirement, newRequirement);
                if (!to.getSecurity().contains(newRequirement)) {
                    to.addSecurityRequirement(newRequirement);
                }
            }
        }
    }
    // Handle @Tags
    if (from.getTags() != null) {
        for (Tag tag : from.getTags()) {
            if (tag != null) {
                if (to.getTags() == null) {
                    to.setTags(createList());
                }
                Tag newTag = new TagImpl();
                TagImpl.merge(tag, newTag, override);
                to.addTag(newTag);
            }
        }
    }
    // Handle @Components
    ComponentsImpl.merge(from.getComponents(), to.getComponents(), override, context);
    PathsImpl.merge(from.getPaths(), to.getPaths(), override);
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) InfoImpl(fish.payara.microprofile.openapi.impl.model.info.InfoImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)

Example 5 with SecurityRequirementImpl

use of fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl in project Payara by payara.

the class ModelInvariantsTest method SecurityRequirementAddSchemePutsEmptyListForNullItem.

@Test
public void SecurityRequirementAddSchemePutsEmptyListForNullItem() {
    SecurityRequirement requirement = new SecurityRequirementImpl();
    requirement.addScheme("keyOnly");
    requirement.addScheme("nullItem", (String) null);
    requirement.addScheme("nullList", (List<String>) null);
    List<String> keyOnly = requirement.getScheme("keyOnly");
    assertNotNull(keyOnly);
    assertEquals(0, keyOnly.size());
    List<String> nullItem = requirement.getScheme("nullItem");
    assertNotNull(nullItem);
    assertEquals(0, nullItem.size());
    List<String> nullList = requirement.getScheme("nullList");
    assertNotNull(nullList);
    assertEquals(0, nullList.size());
}
Also used : SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) Test(org.junit.Test)

Aggregations

SecurityRequirementImpl (fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl)5 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)3 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)3 TagImpl (fish.payara.microprofile.openapi.impl.model.tags.TagImpl)2 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)2 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)1 InfoImpl (fish.payara.microprofile.openapi.impl.model.info.InfoImpl)1 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)1 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)1 Server (org.eclipse.microprofile.openapi.models.servers.Server)1 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)1 MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)1 Test (org.junit.Test)1