use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getTags.
public static Optional<Set<Tag>> getTags(io.swagger.v3.oas.annotations.tags.Tag[] tags, boolean skipOnlyName) {
if (tags == null) {
return Optional.empty();
}
Set<Tag> tagsList = new LinkedHashSet<>();
for (io.swagger.v3.oas.annotations.tags.Tag tag : tags) {
if (StringUtils.isBlank(tag.name())) {
continue;
}
if (skipOnlyName && StringUtils.isBlank(tag.description()) && StringUtils.isBlank(tag.externalDocs().description()) && StringUtils.isBlank(tag.externalDocs().url())) {
continue;
}
Tag tagObject = new Tag();
if (StringUtils.isNotBlank(tag.description())) {
tagObject.setDescription(tag.description());
}
tagObject.setName(tag.name());
getExternalDocumentation(tag.externalDocs()).ifPresent(tagObject::setExternalDocs);
if (tag.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(tag.extensions());
if (extensions != null) {
extensions.forEach(tagObject::addExtension);
}
}
tagsList.add(tagObject);
}
if (tagsList.isEmpty()) {
return Optional.empty();
}
return Optional.of(tagsList);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getLicense.
public static Optional<License> getLicense(io.swagger.v3.oas.annotations.info.License license) {
if (license == null) {
return Optional.empty();
}
License licenseObject = new License();
boolean isEmpty = true;
if (StringUtils.isNotBlank(license.name())) {
licenseObject.setName(license.name());
isEmpty = false;
}
if (StringUtils.isNotBlank(license.url())) {
licenseObject.setUrl(license.url());
isEmpty = false;
}
if (license.extensions() != null && license.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(license.extensions());
if (extensions != null) {
extensions.forEach(licenseObject::addExtension);
isEmpty = false;
}
}
if (isEmpty) {
return Optional.empty();
}
return Optional.of(licenseObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getHeader.
public static Optional<Header> getHeader(io.swagger.v3.oas.annotations.headers.Header header, JsonView jsonViewAnnotation) {
if (header == null) {
return Optional.empty();
}
Header headerObject = new Header();
boolean isEmpty = !StringUtils.isNotBlank(header.name());
if (StringUtils.isNotBlank(header.description())) {
headerObject.setDescription(header.description());
isEmpty = false;
}
if (StringUtils.isNotBlank(header.ref())) {
headerObject.set$ref(header.ref());
isEmpty = false;
}
if (header.deprecated()) {
headerObject.setDeprecated(header.deprecated());
}
if (header.required()) {
headerObject.setRequired(header.required());
isEmpty = false;
}
headerObject.setStyle(Header.StyleEnum.SIMPLE);
if (header.schema() != null) {
if (header.schema().implementation().equals(Void.class)) {
AnnotationsUtils.getSchemaFromAnnotation(header.schema(), jsonViewAnnotation).ifPresent(headerObject::setSchema);
}
}
if (isEmpty) {
return Optional.empty();
}
return Optional.of(headerObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getContent.
public static Optional<Content> getContent(io.swagger.v3.oas.annotations.media.Content[] annotationContents, String[] classTypes, String[] methodTypes, Schema schema, Components components, JsonView jsonViewAnnotation) {
if (annotationContents == null || annotationContents.length == 0) {
return Optional.empty();
}
// Encapsulating Content model
Content content = new Content();
for (io.swagger.v3.oas.annotations.media.Content annotationContent : annotationContents) {
MediaType mediaType = new MediaType();
if (components != null) {
getSchema(annotationContent, components, jsonViewAnnotation).ifPresent(mediaType::setSchema);
if (annotationContent.schemaProperties().length > 0) {
if (mediaType.getSchema() == null) {
mediaType.schema(new Schema<Object>().type("object"));
}
Schema oSchema = mediaType.getSchema();
for (SchemaProperty sp : annotationContent.schemaProperties()) {
Class<?> schemaImplementation = sp.schema().implementation();
boolean isArray = false;
if (schemaImplementation == Void.class) {
schemaImplementation = sp.array().schema().implementation();
if (schemaImplementation != Void.class) {
isArray = true;
}
}
getSchema(sp.schema(), sp.array(), isArray, schemaImplementation, components, jsonViewAnnotation).ifPresent(s -> {
if ("array".equals(oSchema.getType())) {
oSchema.getItems().addProperty(sp.name(), s);
} else {
oSchema.addProperty(sp.name(), s);
}
});
}
}
if (hasSchemaAnnotation(annotationContent.additionalPropertiesSchema()) && mediaType.getSchema() != null && !Boolean.TRUE.equals(mediaType.getSchema().getAdditionalProperties()) && !Boolean.FALSE.equals(mediaType.getSchema().getAdditionalProperties())) {
getSchemaFromAnnotation(annotationContent.additionalPropertiesSchema(), components, jsonViewAnnotation).ifPresent(s -> {
if ("array".equals(mediaType.getSchema().getType())) {
mediaType.getSchema().getItems().additionalProperties(s);
} else {
mediaType.getSchema().additionalProperties(s);
}
});
}
} else {
mediaType.setSchema(schema);
}
ExampleObject[] examples = annotationContent.examples();
if (examples.length == 1 && StringUtils.isBlank(examples[0].name())) {
getExample(examples[0], true).ifPresent(exampleObject -> mediaType.example(exampleObject.getValue()));
} else {
for (ExampleObject example : examples) {
getExample(example).ifPresent(exampleObject -> mediaType.addExamples(example.name(), exampleObject));
}
}
if (annotationContent.extensions() != null && annotationContent.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(annotationContent.extensions());
if (extensions != null) {
extensions.forEach(mediaType::addExtension);
}
}
io.swagger.v3.oas.annotations.media.Encoding[] encodings = annotationContent.encoding();
for (io.swagger.v3.oas.annotations.media.Encoding encoding : encodings) {
addEncodingToMediaType(mediaType, encoding, jsonViewAnnotation);
}
if (StringUtils.isNotBlank(annotationContent.mediaType())) {
content.addMediaType(annotationContent.mediaType(), mediaType);
} else {
applyTypes(classTypes, methodTypes, content, mediaType);
}
}
if (content.size() == 0) {
return Optional.empty();
}
return Optional.of(content);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class ParameterProcessor method getParamSchemaAnnotation.
public static Annotation getParamSchemaAnnotation(List<Annotation> annotations) {
if (annotations == null) {
return null;
}
io.swagger.v3.oas.annotations.media.Schema rootSchema = null;
io.swagger.v3.oas.annotations.media.ArraySchema rootArraySchema = null;
io.swagger.v3.oas.annotations.media.Schema contentSchema = null;
io.swagger.v3.oas.annotations.media.Schema paramSchema = null;
io.swagger.v3.oas.annotations.media.ArraySchema paramArraySchema = null;
for (Annotation annotation : annotations) {
if (annotation instanceof io.swagger.v3.oas.annotations.media.Schema) {
rootSchema = (io.swagger.v3.oas.annotations.media.Schema) annotation;
} else if (annotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema) {
rootArraySchema = (io.swagger.v3.oas.annotations.media.ArraySchema) annotation;
} else if (annotation instanceof io.swagger.v3.oas.annotations.Parameter) {
io.swagger.v3.oas.annotations.Parameter paramAnnotation = (io.swagger.v3.oas.annotations.Parameter) annotation;
if (paramAnnotation.content().length > 0) {
if (AnnotationsUtils.hasSchemaAnnotation(paramAnnotation.content()[0].schema())) {
contentSchema = paramAnnotation.content()[0].schema();
}
}
if (AnnotationsUtils.hasSchemaAnnotation(paramAnnotation.schema())) {
paramSchema = paramAnnotation.schema();
}
if (AnnotationsUtils.hasArrayAnnotation(paramAnnotation.array())) {
paramArraySchema = paramAnnotation.array();
}
}
}
if (rootSchema != null || rootArraySchema != null) {
return null;
}
if (contentSchema != null) {
return contentSchema;
}
if (paramSchema != null) {
return paramSchema;
}
if (paramArraySchema != null) {
return paramArraySchema;
}
return null;
}
Aggregations