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;
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations