Search in sources :

Example 1 with ExternalDocumentationImpl

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

the class TagImpl method merge.

public static void merge(Tag from, Tag to, boolean override) {
    if (from == null) {
        return;
    }
    to.setName(mergeProperty(to.getName(), from.getName(), override));
    to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
    if (from.getExternalDocs() != null) {
        if (to.getExternalDocs() == null) {
            to.setExternalDocs(new ExternalDocumentationImpl());
        }
        ExternalDocumentationImpl.merge(from.getExternalDocs(), to.getExternalDocs(), override);
    }
}
Also used : ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl)

Example 2 with ExternalDocumentationImpl

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

the class ApplicationProcessor method visitExternalDocumentation.

@Override
public void visitExternalDocumentation(AnnotationModel externalDocs, AnnotatedElement element, ApiContext context) {
    if (element instanceof MethodModel) {
        ExternalDocumentation newExternalDocs = new ExternalDocumentationImpl();
        ExternalDocumentationImpl.merge(ExternalDocumentationImpl.createInstance(externalDocs), newExternalDocs, true);
        if (newExternalDocs.getUrl() != null && !newExternalDocs.getUrl().isEmpty()) {
            context.getWorkingOperation().setExternalDocs(newExternalDocs);
        }
    }
}
Also used : MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation)

Example 3 with ExternalDocumentationImpl

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

the class SchemaImpl method merge.

public static void merge(Schema from, Schema to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    if (from.getRef() != null && !from.getRef().isEmpty()) {
        applyReference(to, from.getRef());
        return;
    }
    if (from.getType() != null) {
        to.setType(mergeProperty(to.getType(), from.getType(), override));
    }
    if (from instanceof SchemaImpl && to instanceof SchemaImpl) {
        final String fromImplementation = ((SchemaImpl) from).getImplementation();
        if (fromImplementation != null) {
            setImplementation((SchemaImpl) to, fromImplementation, override, context);
        }
    }
    to.setDefaultValue(mergeProperty(to.getDefaultValue(), from.getDefaultValue(), override));
    to.setTitle(mergeProperty(to.getTitle(), from.getTitle(), override));
    if (from.getMultipleOf() != null && from.getMultipleOf().compareTo(BigDecimal.ZERO) > 0) {
        to.setMultipleOf(mergeProperty(to.getMultipleOf(), from.getMultipleOf().stripTrailingZeros(), override));
    }
    if (from.getMaximum() != null) {
        to.setMaximum(mergeProperty(to.getMaximum(), from.getMaximum(), override));
    }
    to.setExclusiveMaximum(mergeProperty(to.getExclusiveMaximum(), from.getExclusiveMaximum(), override));
    if (from.getMinimum() != null) {
        to.setMinimum(mergeProperty(to.getMinimum(), from.getMinimum(), override));
    }
    to.setExclusiveMinimum(mergeProperty(to.getExclusiveMinimum(), from.getExclusiveMinimum(), override));
    to.setMaxLength(mergeProperty(to.getMaxLength(), from.getMaxLength(), override));
    to.setMinLength(mergeProperty(to.getMinLength(), from.getMinLength(), override));
    to.setPattern(mergeProperty(to.getPattern(), from.getPattern(), override));
    to.setMaxItems(mergeProperty(to.getMaxItems(), from.getMaxItems(), override));
    to.setMinItems(mergeProperty(to.getMinItems(), from.getMinItems(), override));
    to.setUniqueItems(mergeProperty(to.getUniqueItems(), from.getUniqueItems(), override));
    to.setMaxProperties(mergeProperty(to.getMaxProperties(), from.getMaxProperties(), override));
    to.setMinProperties(mergeProperty(to.getMinProperties(), from.getMinProperties(), override));
    if (from.getRequired() != null && !from.getRequired().isEmpty()) {
        if (to.getRequired() == null) {
            to.setRequired(createList());
        }
        for (String value : from.getRequired()) {
            if (!to.getRequired().contains(value)) {
                to.addRequired(value);
            }
        }
    }
    if (from.getProperties() != null && !from.getProperties().isEmpty()) {
        if (to.getProperties() == null) {
            to.setProperties(createMap());
        }
        final Map<String, Schema> toProperties = to.getProperties();
        for (Entry<String, Schema> fromEntry : from.getProperties().entrySet()) {
            final String name = fromEntry.getKey();
            final Schema fromSchema = fromEntry.getValue();
            if (!toProperties.containsKey(name)) {
                to.addProperty(name, fromSchema);
            } else {
                final Schema toSchema = toProperties.get(name);
                SchemaImpl.merge(fromSchema, toSchema, override, context);
            }
        }
    }
    to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
    to.setFormat(mergeProperty(to.getFormat(), from.getFormat(), override));
    to.setNullable(mergeProperty(to.getNullable(), from.getNullable(), override));
    to.setReadOnly(mergeProperty(to.getReadOnly(), from.getReadOnly(), override));
    to.setWriteOnly(mergeProperty(to.getWriteOnly(), from.getWriteOnly(), override));
    to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
    if (from.getExternalDocs() != null) {
        if (to.getExternalDocs() == null) {
            to.setExternalDocs(new ExternalDocumentationImpl());
        }
        ExternalDocumentationImpl.merge(from.getExternalDocs(), to.getExternalDocs(), override);
    }
    to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
    if (from.getEnumeration() != null && from.getEnumeration().size() > 0) {
        if (to.getEnumeration() == null) {
            to.setEnumeration(createList());
        }
        for (Object value : from.getEnumeration()) {
            if (!to.getEnumeration().contains(value)) {
                to.addEnumeration(value);
            }
        }
    }
    if (from.getDiscriminator() != null) {
        if (to.getDiscriminator() == null) {
            to.setDiscriminator(new DiscriminatorImpl());
        }
        Discriminator discriminator = to.getDiscriminator();
        discriminator.setPropertyName(mergeProperty(discriminator.getPropertyName(), from.getDiscriminator().getPropertyName(), override));
        for (Entry<String, String> mapping : from.getDiscriminator().getMapping().entrySet()) {
            discriminator.addMapping(mapping.getKey(), mapping.getValue());
        }
    }
    if (from.getNot() != null) {
        to.setNot(from.getNot());
    }
    mergeImmutableList(from.getAnyOf(), to.getAnyOf(), to::setAnyOf);
    mergeImmutableList(from.getAllOf(), to.getAllOf(), to::setAllOf);
    mergeImmutableList(from.getOneOf(), to.getOneOf(), to::setOneOf);
}
Also used : ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Discriminator(org.eclipse.microprofile.openapi.models.media.Discriminator)

Aggregations

ExternalDocumentationImpl (fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl)3 ExternalDocumentation (org.eclipse.microprofile.openapi.models.ExternalDocumentation)1 Discriminator (org.eclipse.microprofile.openapi.models.media.Discriminator)1 Schema (org.eclipse.microprofile.openapi.models.media.Schema)1 MethodModel (org.glassfish.hk2.classmodel.reflect.MethodModel)1