Search in sources :

Example 1 with Components

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

the class OpenApiAnnotationScanner method jaxRsApplicationToOpenApi.

/**
 * Processes a JAX-RS {@link Application} and creates an {@link OpenAPI} model.  Performs
 * annotation scanning and other processing.  Returns a model unique to that single JAX-RS
 * app.
 * @param applicationClass
 */
private OpenAPIImpl jaxRsApplicationToOpenApi(ClassInfo applicationClass) {
    OpenAPIImpl oai = new OpenAPIImpl();
    oai.setOpenapi(OpenApiConstants.OPEN_API_VERSION);
    // Get the @ApplicationPath info and save it for later (also support @Path which seems nonstandard but common).
    // //////////////////////////////////////
    AnnotationInstance appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_APPLICATION_PATH);
    if (appPathAnno == null) {
        appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_PATH);
    }
    if (appPathAnno != null) {
        this.currentAppPath = appPathAnno.value().asString();
    } else {
        this.currentAppPath = "/";
    }
    // Get the @OpenAPIDefinition annotation and process it.
    // //////////////////////////////////////
    AnnotationInstance openApiDefAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_OPEN_API_DEFINITION);
    if (openApiDefAnno != null) {
        processDefinition(oai, openApiDefAnno);
    }
    // Process @SecurityScheme annotations
    // //////////////////////////////////////
    List<AnnotationInstance> securitySchemeAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SECURITY_SCHEME, OpenApiConstants.DOTNAME_SECURITY_SCHEMES);
    for (AnnotationInstance annotation : securitySchemeAnnotations) {
        String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
        if (name == null && JandexUtil.isRef(annotation)) {
            name = JandexUtil.nameFromRef(annotation);
        }
        if (name != null) {
            SecurityScheme securityScheme = readSecurityScheme(annotation);
            Components components = ModelUtil.components(oai);
            components.addSecurityScheme(name, securityScheme);
        }
    }
    // Process @Server annotations
    // /////////////////////////////////
    List<AnnotationInstance> serverAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SERVER, OpenApiConstants.DOTNAME_SERVERS);
    for (AnnotationInstance annotation : serverAnnotations) {
        Server server = readServer(annotation);
        oai.addServer(server);
    }
    return oai;
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) Server(org.eclipse.microprofile.openapi.models.servers.Server) OpenAPIImpl(org.wildfly.swarm.microprofile.openapi.api.models.OpenAPIImpl) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 2 with Components

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

the class ReferencesBuilderTest method setupBaseDocument.

@Override
protected void setupBaseDocument(OpenAPI document) {
    String name = "NameRef";
    Components components = document.getComponents();
    components.addCallback("callbackRef", createCallback().ref(name));
    components.addCallback("callbackUrlRef", createCallback().ref(url));
    components.addExample("exampleRef", createExample().ref(name));
    components.addExample("exampleUrlRef", createExample().ref(url));
    components.addHeader("headerRef", createHeader().ref(name));
    components.addHeader("headerUrlRef", createHeader().ref(url));
    components.addResponse("responseRef", createAPIResponse().ref(name));
    components.addResponse("responseUrlRef", createAPIResponse().ref(url));
    components.addLink("linkRef", createLink().ref(name));
    components.addLink("linkUrlRef", createLink().ref(url));
    components.addParameter("parameterRef", createParameter().ref(name));
    components.addParameter("parameterUrlRef", createParameter().ref(url));
    components.addRequestBody("requestBodyRef", createRequestBody().ref(name));
    components.addRequestBody("requestBodyUrlRef", createRequestBody().ref(url));
    components.addSchema("schemaRef", createSchema().ref(name));
    components.addSchema("schemaUrlRef", createSchema().ref(url));
    components.addSecurityScheme("securitySchemeRef", createSecurityScheme().ref(name));
    components.addSecurityScheme("securitySchemeUrlRef", createSecurityScheme().ref(url));
    document.getPaths().addPathItem("pathItemRef", createPathItem().ref(name));
    document.getPaths().addPathItem("pathItemUrlRef", createPathItem().ref(url));
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components)

Example 3 with Components

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

the class ModelInvariantsTest method addKeyValueIgnoresNull.

@Test
public void addKeyValueIgnoresNull() {
    BiPredicate<Extensible<?>, String> hasExtension = (obj, key) -> obj.getExtensions().containsKey(key);
    assertAddIgnoresNull(new CallbackImpl(), Callback::addPathItem, Callback::hasPathItem);
    assertAddIgnoresNull(new CallbackImpl(), Callback::addExtension, hasExtension);
    assertAddIgnoresNull(new ExampleImpl(), Example::addExtension, hasExtension);
    assertAddIgnoresNull(new HeaderImpl(), Header::addExample, (obj, key) -> obj.getExamples().containsKey(key));
    assertAddIgnoresNull(new HeaderImpl(), Header::addExtension, hasExtension);
    assertAddIgnoresNull(new ContactImpl(), Contact::addExtension, hasExtension);
    assertAddIgnoresNull(new InfoImpl(), Info::addExtension, hasExtension);
    assertAddIgnoresNull(new LicenseImpl(), License::addExtension, hasExtension);
    assertAddIgnoresNull(new LinkImpl(), Link::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
    assertAddIgnoresNull(new LinkImpl(), Link::addExtension, hasExtension);
    assertAddIgnoresNull(new ContentImpl(), Content::addMediaType, Content::hasMediaType);
    assertAddIgnoresNull(new DiscriminatorImpl(), Discriminator::addMapping, (obj, key) -> obj.getMapping().containsKey(key));
    assertAddIgnoresNull(new EncodingImpl(), Encoding::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
    assertAddIgnoresNull(new EncodingImpl(), Encoding::addExtension, hasExtension);
    assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addEncoding, (obj, key) -> obj.getEncoding().containsKey(key));
    assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExample, (obj, key) -> obj.getExamples().containsKey(key));
    assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExtension, hasExtension);
    assertAddIgnoresNull(new SchemaImpl(), Schema::addProperty, (obj, key) -> obj.getProperties().containsKey(key));
    assertAddIgnoresNull(new SchemaImpl(), Schema::addExtension, hasExtension);
    assertAddIgnoresNull(new XMLImpl(), XML::addExtension, hasExtension);
    assertAddIgnoresNull(new ParameterImpl(), Parameter::addExample, (obj, key) -> obj.getExamples().containsKey(key));
    assertAddIgnoresNull(new ParameterImpl(), Parameter::addExtension, hasExtension);
    assertAddIgnoresNull(new RequestBodyImpl(), RequestBody::addExtension, hasExtension);
    assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
    assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addLink, (obj, key) -> obj.getLinks().containsKey(key));
    assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addExtension, hasExtension);
    assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addAPIResponse, APIResponses::hasAPIResponse);
    assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addExtension, hasExtension);
    assertAddIgnoresNull(new OAuthFlowImpl(), OAuthFlow::addExtension, hasExtension);
    assertAddIgnoresNull(new OAuthFlowsImpl(), OAuthFlows::addExtension, hasExtension);
    assertAddIgnoresNull(new SecuritySchemeImpl(), SecurityScheme::addExtension, hasExtension);
    assertAddIgnoresNull(new ServerImpl(), Server::addExtension, hasExtension);
    assertAddIgnoresNull(new ServerVariableImpl(), ServerVariable::addExtension, hasExtension);
    assertAddIgnoresNull(new TagImpl(), Tag::addExtension, hasExtension);
    assertAddIgnoresNull(new ComponentsImpl(), Components::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addExample, (obj, key) -> obj.getExamples().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addLink, (obj, key) -> obj.getLinks().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addRequestBody, (obj, key) -> obj.getRequestBodies().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addResponse, (obj, key) -> obj.getResponses().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addSchema, (obj, key) -> obj.getSchemas().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addSecurityScheme, (obj, key) -> obj.getSecuritySchemes().containsKey(key));
    assertAddIgnoresNull(new ComponentsImpl(), Components::addExtension, hasExtension);
    assertAddIgnoresNull(new ExternalDocumentationImpl(), ExternalDocumentation::addExtension, hasExtension);
    assertAddIgnoresNull(new OpenAPIImpl(), OpenAPI::addExtension, hasExtension);
    assertAddIgnoresNull(new OperationImpl(), Operation::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
    assertAddIgnoresNull(new OperationImpl(), Operation::addExtension, hasExtension);
    assertAddIgnoresNull(new PathItemImpl(), PathItem::addExtension, hasExtension);
    assertAddIgnoresNull(new PathsImpl(), Paths::addPathItem, Paths::hasPathItem);
    assertAddIgnoresNull(new PathsImpl(), Paths::addExtension, hasExtension);
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Discriminator(org.eclipse.microprofile.openapi.models.media.Discriminator) Info(org.eclipse.microprofile.openapi.models.info.Info) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl) EncodingImpl(fish.payara.microprofile.openapi.impl.model.media.EncodingImpl) HeaderImpl(fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl) License(org.eclipse.microprofile.openapi.models.info.License) PathItem(org.eclipse.microprofile.openapi.models.PathItem) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) OAuthFlowsImpl(fish.payara.microprofile.openapi.impl.model.security.OAuthFlowsImpl) Header(org.eclipse.microprofile.openapi.models.headers.Header) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Contact(org.eclipse.microprofile.openapi.models.info.Contact) OAuthFlows(org.eclipse.microprofile.openapi.models.security.OAuthFlows) 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) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Assert.assertFalse(org.junit.Assert.assertFalse) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) LicenseImpl(fish.payara.microprofile.openapi.impl.model.info.LicenseImpl) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ServerVariableImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerVariableImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) Paths(org.eclipse.microprofile.openapi.models.Paths) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) OAuthFlow(org.eclipse.microprofile.openapi.models.security.OAuthFlow) DiscriminatorImpl(fish.payara.microprofile.openapi.impl.model.media.DiscriminatorImpl) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) ServerVariable(org.eclipse.microprofile.openapi.models.servers.ServerVariable) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Assert.assertSame(org.junit.Assert.assertSame) BiPredicate(java.util.function.BiPredicate) InfoImpl(fish.payara.microprofile.openapi.impl.model.info.InfoImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Assert.assertNotNull(org.junit.Assert.assertNotNull) Content(org.eclipse.microprofile.openapi.models.media.Content) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Link(org.eclipse.microprofile.openapi.models.links.Link) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) OAuthFlowImpl(fish.payara.microprofile.openapi.impl.model.security.OAuthFlowImpl) ContactImpl(fish.payara.microprofile.openapi.impl.model.info.ContactImpl) XMLImpl(fish.payara.microprofile.openapi.impl.model.media.XMLImpl) Assert.assertEquals(org.junit.Assert.assertEquals) Extensible(org.eclipse.microprofile.openapi.models.Extensible) XML(org.eclipse.microprofile.openapi.models.media.XML) OAuthFlowsImpl(fish.payara.microprofile.openapi.impl.model.security.OAuthFlowsImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) Schema(org.eclipse.microprofile.openapi.models.media.Schema) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) License(org.eclipse.microprofile.openapi.models.info.License) ServerVariable(org.eclipse.microprofile.openapi.models.servers.ServerVariable) Components(org.eclipse.microprofile.openapi.models.Components) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) PathItem(org.eclipse.microprofile.openapi.models.PathItem) EncodingImpl(fish.payara.microprofile.openapi.impl.model.media.EncodingImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) ContactImpl(fish.payara.microprofile.openapi.impl.model.info.ContactImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) Header(org.eclipse.microprofile.openapi.models.headers.Header) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) OAuthFlow(org.eclipse.microprofile.openapi.models.security.OAuthFlow) Content(org.eclipse.microprofile.openapi.models.media.Content) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) Link(org.eclipse.microprofile.openapi.models.links.Link) 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) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) LicenseImpl(fish.payara.microprofile.openapi.impl.model.info.LicenseImpl) OAuthFlowImpl(fish.payara.microprofile.openapi.impl.model.security.OAuthFlowImpl) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) Paths(org.eclipse.microprofile.openapi.models.Paths) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) DiscriminatorImpl(fish.payara.microprofile.openapi.impl.model.media.DiscriminatorImpl) Extensible(org.eclipse.microprofile.openapi.models.Extensible) OAuthFlows(org.eclipse.microprofile.openapi.models.security.OAuthFlows) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) Info(org.eclipse.microprofile.openapi.models.info.Info) XMLImpl(fish.payara.microprofile.openapi.impl.model.media.XMLImpl) Discriminator(org.eclipse.microprofile.openapi.models.media.Discriminator) Contact(org.eclipse.microprofile.openapi.models.info.Contact) ServerVariableImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerVariableImpl) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) XML(org.eclipse.microprofile.openapi.models.media.XML) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) InfoImpl(fish.payara.microprofile.openapi.impl.model.info.InfoImpl) Test(org.junit.Test)

Example 4 with Components

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

the class ApplicationProcessor method visitSchemaFieldOrMethod.

private void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod, ExtensibleType<?> declaringType, String typeName, ApiContext context) {
    assert (fieldOrMethod instanceof FieldModel) || (fieldOrMethod instanceof MethodModel);
    Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
    if (hidden == null || !hidden) {
        // Get the schema object name
        String schemaName = ModelUtils.getSchemaName(context, fieldOrMethod);
        SchemaImpl schema = SchemaImpl.createInstance(schemaAnnotation, context);
        // Get the parent schema object name
        String parentName = null;
        AnnotationModel classSchemaAnnotation = context.getAnnotationInfo(declaringType).getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class);
        if (classSchemaAnnotation != null) {
            parentName = classSchemaAnnotation.getValue("name", String.class);
        }
        if (parentName == null || parentName.isEmpty()) {
            parentName = declaringType.getSimpleName();
        }
        // Get or create the parent schema object
        final Components components = context.getApi().getComponents();
        Schema parentSchema = components.getSchemas().getOrDefault(parentName, new SchemaImpl());
        components.addSchema(parentName, parentSchema);
        Schema property = parentSchema.getProperties().getOrDefault(schemaName, new SchemaImpl());
        parentSchema.addProperty(schemaName, property);
        if (schema.isRequired()) {
            parentSchema.addRequired(schemaName);
        }
        if (property.getRef() == null) {
            property.setType(ModelUtils.getSchemaType(typeName, context));
        }
        SchemaImpl.merge(schema, property, true, context);
    }
}
Also used : Components(org.eclipse.microprofile.openapi.models.Components) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Example 5 with Components

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

the class ApplicationProcessor method visitSchemaClass.

private Schema visitSchemaClass(Schema schema, AnnotationModel schemaAnnotation, ClassModel clazz, Collection<ParameterizedInterfaceModel> parameterizedInterfaces, ApiContext context) {
    // Get the schema object name
    String schemaName = ModelUtils.getSchemaName(context, clazz);
    // Add a new schema
    if (schema == null) {
        final Components components = context.getApi().getComponents();
        schema = components.getSchemas().getOrDefault(schemaName, new SchemaImpl());
        components.addSchema(schemaName, schema);
    }
    // If there is an annotation, parse its configuration
    if (schemaAnnotation != null) {
        SchemaImpl.merge(SchemaImpl.createInstance(schemaAnnotation, context), schema, false, context);
    }
    for (FieldModel field : clazz.getFields()) {
        final String fieldName = field.getName();
        Boolean hidden = false;
        AnnotationModel fieldSchemaAnnotation = field.getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class.getName());
        if (fieldSchemaAnnotation != null) {
            hidden = fieldSchemaAnnotation.getValue("hidden", Boolean.class);
        }
        if (!Boolean.TRUE.equals(hidden) && !field.isTransient() && !fieldName.startsWith("this$")) {
            final Schema existingProperty = schema.getProperties().get(fieldName);
            final Schema newProperty = createSchema(null, context, field, clazz, parameterizedInterfaces);
            if (existingProperty != null) {
                SchemaImpl.merge(existingProperty, newProperty, true, context);
            }
            schema.addProperty(fieldName, newProperty);
        }
    }
    if (schema.getType() == null) {
        schema.setType(ModelUtils.getSchemaType(clazz.getName(), context));
    }
    // If there is an extending class, add the data
    final ClassModel superClass = clazz.getParent();
    if (superClass != null && !superClass.getName().startsWith("java.")) {
        // Get the parent annotation
        AnnotationModel parentSchemAnnotation = context.getAnnotationInfo(superClass).getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class);
        ParameterizedInterfaceModel parameterizedInterface = clazz.getParameterizedInterface(superClass);
        if (parameterizedInterface == null) {
            // Create a schema for the parent
            final Schema parentSchema = visitSchemaClass(null, parentSchemAnnotation, superClass, Collections.emptyList(), context);
            // Get the superclass schema name
            String parentSchemaName = ModelUtils.getSchemaName(context, superClass);
            // Link the schemas
            schema.addAllOf(new SchemaImpl().ref(parentSchemaName));
            // Add all the parent schema properties
            for (Entry<String, Schema> property : parentSchema.getProperties().entrySet()) {
                schema.addProperty(property.getKey(), property.getValue());
            }
        } else {
            visitSchemaClass(schema, parentSchemAnnotation, superClass, parameterizedInterface.getParametizedTypes(), context);
        }
    }
    return schema;
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) Components(org.eclipse.microprofile.openapi.models.Components) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel)

Aggregations

Components (org.eclipse.microprofile.openapi.models.Components)8 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)4 Schema (org.eclipse.microprofile.openapi.models.media.Schema)3 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)2 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)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 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)2 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)2 FieldModel (org.glassfish.hk2.classmodel.reflect.FieldModel)2 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)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