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