Search in sources :

Example 36 with io.swagger.v3.oas.models.media

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

the class ModelResolver method resolveExternalDocumentation.

protected ExternalDocumentation resolveExternalDocumentation(io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation) {
    if (externalDocumentation == null) {
        return null;
    }
    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 (isEmpty) {
        return null;
    }
    return external;
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation)

Example 37 with io.swagger.v3.oas.models.media

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

the class ModelResolver method resolveSchemaMembers.

protected void resolveSchemaMembers(Schema schema, Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schemaAnnotation) {
    String description = resolveDescription(a, annotations, schemaAnnotation);
    if (StringUtils.isNotBlank(description)) {
        schema.description(description);
    }
    String title = resolveTitle(a, annotations, schemaAnnotation);
    if (StringUtils.isNotBlank(title)) {
        schema.title(title);
    }
    String format = resolveFormat(a, annotations, schemaAnnotation);
    if (StringUtils.isNotBlank(format) && StringUtils.isBlank(schema.getFormat())) {
        schema.format(format);
    }
    Object defaultValue = resolveDefaultValue(a, annotations, schemaAnnotation);
    if (defaultValue != null) {
        schema.setDefault(defaultValue);
    }
    Object example = resolveExample(a, annotations, schemaAnnotation);
    if (example != null) {
        schema.example(example);
    }
    Boolean readOnly = resolveReadOnly(a, annotations, schemaAnnotation);
    if (readOnly != null) {
        schema.readOnly(readOnly);
    }
    Boolean nullable = resolveNullable(a, annotations, schemaAnnotation);
    if (nullable != null) {
        schema.nullable(nullable);
    }
    BigDecimal multipleOf = resolveMultipleOf(a, annotations, schemaAnnotation);
    if (multipleOf != null) {
        schema.multipleOf(multipleOf);
    }
    Integer maxLength = resolveMaxLength(a, annotations, schemaAnnotation);
    if (maxLength != null) {
        schema.maxLength(maxLength);
    }
    Integer minLength = resolveMinLength(a, annotations, schemaAnnotation);
    if (minLength != null) {
        schema.minLength(minLength);
    }
    BigDecimal minimum = resolveMinimum(a, annotations, schemaAnnotation);
    if (minimum != null) {
        schema.minimum(minimum);
    }
    BigDecimal maximum = resolveMaximum(a, annotations, schemaAnnotation);
    if (maximum != null) {
        schema.maximum(maximum);
    }
    Boolean exclusiveMinimum = resolveExclusiveMinimum(a, annotations, schemaAnnotation);
    if (exclusiveMinimum != null) {
        schema.exclusiveMinimum(exclusiveMinimum);
    }
    Boolean exclusiveMaximum = resolveExclusiveMaximum(a, annotations, schemaAnnotation);
    if (exclusiveMaximum != null) {
        schema.exclusiveMaximum(exclusiveMaximum);
    }
    String pattern = resolvePattern(a, annotations, schemaAnnotation);
    if (StringUtils.isNotBlank(pattern)) {
        schema.pattern(pattern);
    }
    Integer minProperties = resolveMinProperties(a, annotations, schemaAnnotation);
    if (minProperties != null) {
        schema.minProperties(minProperties);
    }
    Integer maxProperties = resolveMaxProperties(a, annotations, schemaAnnotation);
    if (maxProperties != null) {
        schema.maxProperties(maxProperties);
    }
    List<String> requiredProperties = resolveRequiredProperties(a, annotations, schemaAnnotation);
    if (requiredProperties != null) {
        for (String prop : requiredProperties) {
            addRequiredItem(schema, prop);
        }
    }
    Boolean writeOnly = resolveWriteOnly(a, annotations, schemaAnnotation);
    if (writeOnly != null) {
        schema.writeOnly(writeOnly);
    }
    ExternalDocumentation externalDocs = resolveExternalDocumentation(a, annotations, schemaAnnotation);
    if (externalDocs != null) {
        schema.externalDocs(externalDocs);
    }
    Boolean deprecated = resolveDeprecated(a, annotations, schemaAnnotation);
    if (deprecated != null) {
        schema.deprecated(deprecated);
    }
    List<String> allowableValues = resolveAllowableValues(a, annotations, schemaAnnotation);
    if (allowableValues != null) {
        for (String prop : allowableValues) {
            schema.addEnumItemObject(prop);
        }
    }
    Map<String, Object> extensions = resolveExtensions(a, annotations, schemaAnnotation);
    if (extensions != null) {
        extensions.forEach(schema::addExtension);
    }
}
Also used : ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) BigDecimal(java.math.BigDecimal)

Example 38 with io.swagger.v3.oas.models.media

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

the class ModelResolver method resolveSchemaMembers.

protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType) {
    final JavaType type;
    if (annotatedType.getType() instanceof JavaType) {
        type = (JavaType) annotatedType.getType();
    } else {
        type = _mapper.constructType(annotatedType.getType());
    }
    final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
    final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation = resolvedSchemaOrArrayAnnotation == null ? null : resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ? ((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() : (io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation;
    final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
    Annotated a = beanDesc.getClassInfo();
    Annotation[] annotations = annotatedType.getCtxAnnotations();
    resolveSchemaMembers(schema, a, annotations, schemaAnnotation);
}
Also used : UUIDSchema(io.swagger.v3.oas.models.media.UUIDSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) Annotation(java.lang.annotation.Annotation) Annotated(com.fasterxml.jackson.databind.introspect.Annotated) JavaType(com.fasterxml.jackson.databind.JavaType) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema)

Example 39 with io.swagger.v3.oas.models.media

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

the class AnnotationsUtils method getLink.

public static Optional<Link> getLink(io.swagger.v3.oas.annotations.links.Link link) {
    if (link == null) {
        return Optional.empty();
    }
    boolean isEmpty = true;
    Link linkObject = new Link();
    if (StringUtils.isNotBlank(link.description())) {
        linkObject.setDescription(link.description());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(link.operationId())) {
        linkObject.setOperationId(link.operationId());
        isEmpty = false;
        if (StringUtils.isNotBlank(link.operationRef())) {
            LOGGER.debug("OperationId and OperatonRef are mutually exclusive, there must be only one setted");
        }
    } else {
        if (StringUtils.isNotBlank(link.operationRef())) {
            linkObject.setOperationRef(link.operationRef());
            isEmpty = false;
        }
    }
    if (StringUtils.isNotBlank(link.ref())) {
        linkObject.set$ref(link.ref());
        isEmpty = false;
    }
    if (link.extensions() != null && link.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(link.extensions());
        if (extensions != null) {
            extensions.forEach(linkObject::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    Map<String, String> linkParameters = getLinkParameters(link.parameters());
    if (linkParameters.size() > 0) {
        linkObject.setParameters(linkParameters);
    }
    if (StringUtils.isNotBlank(link.requestBody())) {
        JsonNode processedValue = null;
        try {
            processedValue = Json.mapper().readTree(link.requestBody());
        } catch (Exception e) {
        // not a json string
        }
        if (processedValue == null) {
            linkObject.requestBody(link.requestBody());
        } else {
            linkObject.requestBody(processedValue);
        }
    }
    return Optional.of(linkObject);
}
Also used : ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Link(io.swagger.v3.oas.models.links.Link) IOException(java.io.IOException)

Example 40 with io.swagger.v3.oas.models.media

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

the class AnnotationsUtils method getContact.

public static Optional<Contact> getContact(io.swagger.v3.oas.annotations.info.Contact contact) {
    if (contact == null) {
        return Optional.empty();
    }
    boolean isEmpty = true;
    Contact contactObject = new Contact();
    if (StringUtils.isNotBlank(contact.email())) {
        contactObject.setEmail(contact.email());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(contact.name())) {
        contactObject.setName(contact.name());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(contact.url())) {
        contactObject.setUrl(contact.url());
        isEmpty = false;
    }
    if (contact.extensions() != null && contact.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(contact.extensions());
        if (extensions != null) {
            extensions.forEach(contactObject::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    return Optional.of(contactObject);
}
Also used : ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) Contact(io.swagger.v3.oas.models.info.Contact)

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