Search in sources :

Example 16 with ExternalDocumentation

use of io.swagger.v3.oas.models.ExternalDocumentation 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 17 with ExternalDocumentation

use of io.swagger.v3.oas.models.ExternalDocumentation 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)

Aggregations

ExternalDocumentation (io.swagger.v3.oas.models.ExternalDocumentation)15 OpenAPI (io.swagger.v3.oas.models.OpenAPI)7 Operation (io.swagger.v3.oas.models.Operation)6 Paths (io.swagger.v3.oas.models.Paths)5 Schema (io.swagger.v3.oas.models.media.Schema)5 Test (org.testng.annotations.Test)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Components (io.swagger.v3.oas.models.Components)4 PathItem (io.swagger.v3.oas.models.PathItem)4 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)4 Tag (io.swagger.v3.oas.models.tags.Tag)4 Callback (io.swagger.v3.oas.models.callbacks.Callback)3 Content (io.swagger.v3.oas.models.media.Content)3 MediaType (io.swagger.v3.oas.models.media.MediaType)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JsonView (com.fasterxml.jackson.annotation.JsonView)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 JavaType (com.fasterxml.jackson.databind.JavaType)2