Search in sources :

Example 6 with io.swagger.v3.oas.models.security

use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.

the class ModelResolver method resolveDiscriminator.

protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) {
    io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass());
    String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty();
    if (disc.isEmpty()) {
        // longer method would involve AnnotationIntrospector.findTypeResolver(...) but:
        JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class);
        if (typeInfo != null) {
            disc = typeInfo.property();
        }
    }
    if (!disc.isEmpty()) {
        Discriminator discriminator = new Discriminator().propertyName(disc);
        if (declaredSchemaAnnotation != null) {
            DiscriminatorMapping[] mappings = declaredSchemaAnnotation.discriminatorMapping();
            if (mappings != null && mappings.length > 0) {
                for (DiscriminatorMapping mapping : mappings) {
                    if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) {
                        discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName()));
                    }
                }
            }
        }
        return discriminator;
    }
    return null;
}
Also used : DiscriminatorMapping(io.swagger.v3.oas.annotations.media.DiscriminatorMapping) AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Discriminator(io.swagger.v3.oas.models.media.Discriminator)

Example 7 with io.swagger.v3.oas.models.security

use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.

the class ModelResolver method resolveExternalDocumentation.

protected ExternalDocumentation resolveExternalDocumentation(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) {
    ExternalDocumentation external = null;
    if (a != null) {
        io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation = a.getAnnotation(io.swagger.v3.oas.annotations.ExternalDocumentation.class);
        external = resolveExternalDocumentation(externalDocumentation);
    }
    if (external == null) {
        if (schema != null) {
            external = resolveExternalDocumentation(schema.externalDocs());
        }
    }
    return external;
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation)

Example 8 with io.swagger.v3.oas.models.security

use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.

the class AnnotationsUtils method addEncodingToMediaType.

public static void addEncodingToMediaType(MediaType mediaType, io.swagger.v3.oas.annotations.media.Encoding encoding, JsonView jsonViewAnnotation) {
    if (encoding == null) {
        return;
    }
    if (StringUtils.isNotBlank(encoding.name())) {
        Encoding encodingObject = new Encoding();
        if (StringUtils.isNotBlank(encoding.contentType())) {
            encodingObject.setContentType(encoding.contentType());
        }
        if (StringUtils.isNotBlank(encoding.style())) {
            encodingObject.setStyle(Encoding.StyleEnum.valueOf(encoding.style()));
        }
        if (encoding.explode()) {
            encodingObject.setExplode(encoding.explode());
        }
        if (encoding.allowReserved()) {
            encodingObject.setAllowReserved(encoding.allowReserved());
        }
        if (encoding.headers() != null) {
            getHeaders(encoding.headers(), jsonViewAnnotation).ifPresent(encodingObject::headers);
        }
        if (encoding.extensions() != null && encoding.extensions().length > 0) {
            Map<String, Object> extensions = AnnotationsUtils.getExtensions(encoding.extensions());
            if (extensions != null) {
                extensions.forEach(encodingObject::addExtension);
            }
        }
        mediaType.addEncoding(encoding.name(), encodingObject);
    }
}
Also used : Encoding(io.swagger.v3.oas.models.media.Encoding) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject)

Example 9 with io.swagger.v3.oas.models.security

use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.

the class AnnotationsUtils method getExternalDocumentation.

public static Optional<ExternalDocumentation> getExternalDocumentation(io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation) {
    if (externalDocumentation == null) {
        return Optional.empty();
    }
    boolean isEmpty = true;
    ExternalDocumentation external = new ExternalDocumentation();
    if (StringUtils.isNotBlank(externalDocumentation.description())) {
        isEmpty = false;
        external.setDescription(externalDocumentation.description());
    }
    if (StringUtils.isNotBlank(externalDocumentation.url())) {
        isEmpty = false;
        external.setUrl(externalDocumentation.url());
    }
    if (externalDocumentation.extensions() != null && externalDocumentation.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(externalDocumentation.extensions());
        if (extensions != null) {
            extensions.forEach(external::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    return Optional.of(external);
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject)

Example 10 with io.swagger.v3.oas.models.security

use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.

the class AnnotationsUtils method getInfo.

public static Optional<Info> getInfo(io.swagger.v3.oas.annotations.info.Info info) {
    if (info == null) {
        return Optional.empty();
    }
    boolean isEmpty = true;
    Info infoObject = new Info();
    if (StringUtils.isNotBlank(info.description())) {
        infoObject.setDescription(info.description());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(info.termsOfService())) {
        infoObject.setTermsOfService(info.termsOfService());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(info.title())) {
        infoObject.setTitle(info.title());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(info.version())) {
        infoObject.setVersion(info.version());
        isEmpty = false;
    }
    if (info.extensions() != null && info.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(info.extensions());
        if (extensions != null) {
            extensions.forEach(infoObject::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    getContact(info.contact()).ifPresent(infoObject::setContact);
    getLicense(info.license()).ifPresent(infoObject::setLicense);
    return Optional.of(infoObject);
}
Also used : ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) Info(io.swagger.v3.oas.models.info.Info)

Aggregations

Schema (io.swagger.v3.oas.models.media.Schema)13 ExampleObject (io.swagger.v3.oas.annotations.media.ExampleObject)11 OpenAPI (io.swagger.v3.oas.models.OpenAPI)10 Annotation (java.lang.annotation.Annotation)8 Test (org.testng.annotations.Test)8 ResolvedSchema (io.swagger.v3.core.converter.ResolvedSchema)7 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)7 Content (io.swagger.v3.oas.models.media.Content)7 ArrayList (java.util.ArrayList)7 PathItem (io.swagger.v3.oas.models.PathItem)6 Parameter (io.swagger.v3.oas.models.parameters.Parameter)6 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)5 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)5 Hidden (io.swagger.v3.oas.annotations.Hidden)5 MediaType (io.swagger.v3.oas.models.media.MediaType)5 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 Map (java.util.Map)5 JavaType (com.fasterxml.jackson.databind.JavaType)4 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)4