Search in sources :

Example 6 with ExampleImpl

use of fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl in project Payara by payara.

the class ContentImpl method createInstance.

public static ContentImpl createInstance(AnnotationModel annotation, ApiContext context) {
    ContentImpl from = new ContentImpl();
    String typeName = annotation.getValue("mediaType", String.class);
    if (typeName == null || typeName.isEmpty()) {
        typeName = javax.ws.rs.core.MediaType.WILDCARD;
    }
    MediaType mediaType = new MediaTypeImpl();
    from.addMediaType(typeName, mediaType);
    extractAnnotations(annotation, context, "examples", "name", ExampleImpl::createInstance, mediaType::addExample);
    mediaType.setExample(annotation.getValue("example", String.class));
    AnnotationModel schemaAnnotation = annotation.getValue("schema", AnnotationModel.class);
    if (schemaAnnotation != null) {
        Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
        if (hidden == null || !hidden) {
            mediaType.setSchema(SchemaImpl.createInstance(schemaAnnotation, context));
        }
    }
    extractAnnotations(annotation, context, "encoding", "name", EncodingImpl::createInstance, mediaType::addEncoding);
    return from;
}
Also used : AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)

Example 7 with ExampleImpl

use of fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl 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 8 with ExampleImpl

use of fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl in project Payara by payara.

the class HeaderImpl method createInstance.

public static Header createInstance(AnnotationModel annotation, ApiContext context) {
    HeaderImpl from = new HeaderImpl();
    String ref = annotation.getValue("ref", String.class);
    if (ref != null && !ref.isEmpty()) {
        from.setRef(ref);
    }
    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));
    EnumModel styleEnum = annotation.getValue("style", EnumModel.class);
    if (styleEnum != null) {
        from.setStyle(Header.Style.valueOf(styleEnum.getValue()));
    }
    from.setExplode(annotation.getValue("explode", 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)

Aggregations

ExampleImpl (fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl)8 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)5 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)5 Example (org.eclipse.microprofile.openapi.models.examples.Example)4 CallbackImpl (fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl)3 LinkImpl (fish.payara.microprofile.openapi.impl.model.links.LinkImpl)3 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)3 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)3 APIResponseImpl (fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl)3 SecuritySchemeImpl (fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl)3 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)3 HeaderImpl (fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl)2 Components (org.eclipse.microprofile.openapi.models.Components)2 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)2 Header (org.eclipse.microprofile.openapi.models.headers.Header)2 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)2 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