Search in sources :

Example 1 with ContentImpl

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

the class ParameterImpl method merge.

public static void merge(Parameter from, Parameter to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    if (from.getRef() != null && !from.getRef().isEmpty()) {
        applyReference(to, from.getRef());
        return;
    }
    to.setName(mergeProperty(to.getName(), from.getName(), override));
    to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
    if (from.getIn() != null) {
        to.setIn(mergeProperty(to.getIn(), from.getIn(), 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));
    if (from.getStyle() != null) {
        to.setStyle(mergeProperty(to.getStyle(), from.getStyle(), override));
    }
    if (from.getExplode() != null) {
        to.setExplode(mergeProperty(to.getExplode(), false, override));
    }
    to.setAllowReserved(mergeProperty(to.getAllowReserved(), from.getAllowReserved(), 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 instanceof ParameterImpl) {
        ParameterImpl fromImpl = (ParameterImpl) from;
        if (fromImpl.getContents() != null) {
            if (to.getContent() == null) {
                to.setContent(new ContentImpl());
            }
            for (ContentImpl content : fromImpl.getContents()) {
                ContentImpl.merge(content, to.getContent(), override, context);
            }
        }
    }
    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 2 with ContentImpl

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

the class ParameterImpl method createInstance.

public static Parameter createInstance(AnnotationModel annotation, ApiContext context) {
    ParameterImpl from = new ParameterImpl();
    from.setName(annotation.getValue("name", String.class));
    EnumModel inEnum = annotation.getValue("in", EnumModel.class);
    if (inEnum != null) {
        from.setIn(In.valueOf(inEnum.getValue()));
    }
    from.setDescription(annotation.getValue("description", String.class));
    from.setRequired(annotation.getValue("required", Boolean.class));
    from.setDeprecated(annotation.getValue("deprecated", Boolean.class));
    from.setAllowEmptyValue(annotation.getValue("allowEmptyValue", Boolean.class));
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
    if (styleEnum != null) {
        from.setStyle(Style.valueOf(styleEnum.getValue()));
    }
    from.setExplode(annotation.getValue("explode", Boolean.class));
    from.setAllowReserved(annotation.getValue("allowReserved", Boolean.class));
    AnnotationModel schemaAnnotation = annotation.getValue("schema", AnnotationModel.class);
    if (schemaAnnotation != null) {
        Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
        if (hidden == null || !hidden) {
            from.setSchema(SchemaImpl.createInstance(schemaAnnotation, context));
        }
    }
    extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, from::addExample);
    from.setExample(annotation.getValue("example", Object.class));
    final List<ContentImpl> contents = createList();
    extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
    for (ContentImpl content : contents) {
        content.getMediaTypes().forEach(from.content::addMediaType);
    }
    return from;
}
Also used : EnumModel(org.glassfish.hk2.classmodel.reflect.EnumModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 3 with ContentImpl

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

the class APIResponseImpl method createInstance.

public static APIResponseImpl createInstance(AnnotationModel annotation, ApiContext context) {
    APIResponseImpl from = new APIResponseImpl();
    from.setDescription(annotation.getValue("description", String.class));
    HeaderImpl.createInstances(annotation, context).forEach(from::addHeader);
    final List<ContentImpl> contents = createList();
    // If the annotation is @APIResponseSchema, parse the schema and description
    final String implementationClass = annotation.getValue("value", String.class);
    if (implementationClass != null) {
        ContentImpl content = new ContentImpl().addMediaType(MediaType.WILDCARD, new MediaTypeImpl().schema(SchemaImpl.fromImplementation(implementationClass, context)));
        contents.add(content);
        from.setDescription(annotation.getValue("responseDescription", String.class));
    }
    extractAnnotations(annotation, context, "content", ContentImpl::createInstance, contents::add);
    for (ContentImpl content : contents) {
        content.getMediaTypes().forEach(from.content::addMediaType);
    }
    extractAnnotations(annotation, context, "links", "name", LinkImpl::createInstance, from::addLink);
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    from.setResponseCode(annotation.getValue("responseCode", String.class));
    return from;
}
Also used : MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl)

Example 4 with ContentImpl

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

the class ApplicationProcessor method visitFormParam.

@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
    // Find the aggregate schema type of all the parameters
    SchemaType formSchemaType = null;
    if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
        List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
        for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
            if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
                formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
            }
        }
    }
    final Operation workingOperation = context.getWorkingOperation();
    if (workingOperation != null) {
        // If there's no request body, fill out a new one right down to the schema
        if (workingOperation.getRequestBody() == null) {
            workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
        }
        for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
            final Schema schema = mediaType.getSchema();
            if (schema != null) {
                schema.setType(formSchemaType);
            }
        }
    }
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType)

Example 5 with ContentImpl

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

the class RequestBodyImpl method merge.

public static void merge(RequestBody from, RequestBody 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));
    if (from.getContent() != null) {
        if (to.getContent() == null) {
            to.setContent(new ContentImpl());
        }
        ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
    }
}
Also used : ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl)

Aggregations

ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)9 ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)5 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)4 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)3 Example (org.eclipse.microprofile.openapi.models.examples.Example)3 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)2 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)2 Operation (org.eclipse.microprofile.openapi.models.Operation)2 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)1 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 DiscriminatorImpl (fish.payara.microprofile.openapi.impl.model.media.DiscriminatorImpl)1 EncodingImpl (fish.payara.microprofile.openapi.impl.model.media.EncodingImpl)1 XMLImpl (fish.payara.microprofile.openapi.impl.model.media.XMLImpl)1 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)1 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)1 APIResponsesImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl)1 OAuthFlowImpl (fish.payara.microprofile.openapi.impl.model.security.OAuthFlowImpl)1