Search in sources :

Example 16 with SchemaImpl

use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.

the class HeaderImpl method merge.

public static void merge(Header from, Header to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    if (from.getRef() != null && !from.getRef().isEmpty()) {
        applyReference(to, from.getRef());
        return;
    }
    to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
    to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
    to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
    to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
    to.setStyle(Style.SIMPLE);
    to.setExplode(mergeProperty(to.getExplode(), from.getExplode(), override));
    if (from.getSchema() != null) {
        if (to.getSchema() == null) {
            to.setSchema(new SchemaImpl());
        }
        SchemaImpl.merge(from.getSchema(), to.getSchema(), override, context);
    }
    to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
    if (from.getExamples() != null) {
        for (String exampleName : from.getExamples().keySet()) {
            if (exampleName != null) {
                Example example = new ExampleImpl();
                ExampleImpl.merge(from.getExamples().get(exampleName), example, override);
                to.addExample(exampleName, example);
            }
        }
    }
    if (from.getContent() != null) {
        if (to.getContent() == null) {
            to.setContent(new ContentImpl());
        }
        ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
    }
}
Also used : SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 17 with SchemaImpl

use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.

the class ApplicationProcessor method visitRequestBodySchema.

@Override
public void visitRequestBodySchema(AnnotationModel requestBodySchema, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel || element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        final RequestBody currentRequestBody = context.getWorkingOperation().getRequestBody();
        if (currentRequestBody != null) {
            final String implementationClass = requestBodySchema.getValue("value", String.class);
            final SchemaImpl schema = SchemaImpl.fromImplementation(implementationClass, context);
            for (MediaType mediaType : currentRequestBody.getContent().getMediaTypes().values()) {
                mediaType.setSchema(schema);
            }
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Example 18 with SchemaImpl

use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.

the class ApplicationProcessor method visitSchemaParameter.

private static void visitSchemaParameter(AnnotationModel schemaAnnotation, org.glassfish.hk2.classmodel.reflect.Parameter parameter, ApiContext context) {
    // If this is being parsed at the start, ignore it as the path doesn't exist
    if (context.getWorkingOperation() == null) {
        return;
    }
    // Check if it's a request body
    if (ModelUtils.isRequestBody(context, parameter)) {
        if (context.getWorkingOperation().getRequestBody() == null) {
            context.getWorkingOperation().setRequestBody(new RequestBodyImpl());
        }
        // Insert the schema to the request body media type
        MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
        Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
        SchemaImpl.merge(schema, mediaType.getSchema(), true, context);
        if (schema.getRef() != null && !schema.getRef().isEmpty()) {
            mediaType.setSchema(new SchemaImpl().ref(schema.getRef()));
        }
    } else if (ModelUtils.getParameterType(context, parameter) != null) {
        for (Parameter param : context.getWorkingOperation().getParameters()) {
            if (param.getName().equals(ModelUtils.getParameterName(context, parameter))) {
                Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
                SchemaImpl.merge(schema, param.getSchema(), true, context);
                if (schema.getRef() != null && !schema.getRef().isEmpty()) {
                    param.setSchema(new SchemaImpl().ref(schema.getRef()));
                }
            }
        }
    }
}
Also used : SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)

Example 19 with SchemaImpl

use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.

the class ConfigPropertyProcessor method process.

@Override
public OpenAPI process(OpenAPI api, OpenApiConfiguration config) {
    // Add the schemas
    for (Entry<String, SchemaImpl> schemaEntry : config.getSchemaMap().entrySet()) {
        final SchemaImpl schema = schemaEntry.getValue();
        // The Java class name represented by the schema
        final String schemaClassName = schemaEntry.getKey();
        schema.setImplementation(schemaClassName);
        // Get the name to use as the key for the Schema
        String schemaName = schema.getName();
        if (schemaName == null || schemaName.isEmpty()) {
            schemaName = ModelUtils.getSimpleName(schemaClassName);
        }
        api.getComponents().addSchema(schemaName, schema);
    }
    return api;
}
Also used : SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)

Aggregations

SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)19 Schema (org.eclipse.microprofile.openapi.models.media.Schema)10 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)7 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)5 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)5 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)5 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)5 FieldModel (org.glassfish.hk2.classmodel.reflect.FieldModel)5 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)4 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)4 Components (org.eclipse.microprofile.openapi.models.Components)4 Example (org.eclipse.microprofile.openapi.models.examples.Example)4 SchemaType (org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)4 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)3 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)3 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)3 SecuritySchemeImpl (fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl)3 Operation (org.eclipse.microprofile.openapi.models.Operation)3 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)3 MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)3