use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ModelResolver method resolveSchemaProperties.
protected Map<String, Schema> resolveSchemaProperties(JavaType a, Annotation[] annotations, ModelConverterContext context) {
final Map<String, SchemaProperty> propList = new LinkedHashMap<>();
SchemaProperties props = a.getRawClass().getAnnotation(SchemaProperties.class);
if (props != null && props.value().length > 0) {
for (SchemaProperty prop : props.value()) {
propList.put(prop.name(), prop);
}
}
SchemaProperty singleProp = a.getRawClass().getAnnotation(SchemaProperty.class);
if (singleProp != null) {
propList.put(singleProp.name(), singleProp);
}
props = AnnotationsUtils.getAnnotation(SchemaProperties.class, annotations);
if (props != null && props.value().length > 0) {
for (SchemaProperty prop : props.value()) {
propList.put(prop.name(), prop);
}
}
singleProp = AnnotationsUtils.getAnnotation(SchemaProperty.class, annotations);
if (singleProp != null) {
propList.put(singleProp.name(), singleProp);
}
if (propList.isEmpty()) {
return null;
}
Map<String, Schema> schemaProperties = new LinkedHashMap<>();
for (SchemaProperty prop : propList.values()) {
String key = prop.name();
if (StringUtils.isBlank(key)) {
continue;
}
Annotation[] propAnnotations = new Annotation[] { prop.schema(), prop.array() };
AnnotatedType propType = new AnnotatedType().type(String.class).ctxAnnotations(propAnnotations).resolveAsRef(true);
Schema resolvedPropSchema = context.resolve(propType);
if (resolvedPropSchema != null) {
schemaProperties.put(key, resolvedPropSchema);
}
}
return schemaProperties;
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ModelConverters method read.
public Map<String, Schema> read(AnnotatedType type) {
Map<String, Schema> modelMap = new HashMap<>();
if (shouldProcess(type.getType())) {
ModelConverterContextImpl context = new ModelConverterContextImpl(converters);
Schema resolve = context.resolve(type);
for (Entry<String, Schema> entry : context.getDefinedModels().entrySet()) {
if (entry.getValue().equals(resolve)) {
modelMap.put(entry.getKey(), entry.getValue());
}
}
}
return modelMap;
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class SpecFilter method locateReferencedDefinitions.
protected void locateReferencedDefinitions(String ref, Set<String> nestedReferencedDefinitions, OpenAPI openAPI) {
nestedReferencedDefinitions.add(ref);
String simpleName = (String) RefUtils.extractSimpleName(ref).getLeft();
Schema model = openAPI.getComponents().getSchemas().get(simpleName);
if (model != null) {
addSchemaRef(model, nestedReferencedDefinitions);
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class JAXBAnnotationsHelper method applyElement.
/**
* Puts definitions for XML wrapper.
*
* @param wrapper XmlElementWrapper
* @param property property instance to be updated
*/
private static void applyElement(XmlElementWrapper wrapper, Schema property) {
if (wrapper != null) {
final XML xml = getXml(property);
xml.setWrapped(true);
// No need to set the xml name if the name provided by xmlelementwrapper annotation is ##default or equal to the property name | https://github.com/swagger-api/swagger-core/pull/2050
if (!JAXB_DEFAULT.equals(wrapper.name()) && !wrapper.name().isEmpty() && !wrapper.name().equals(property.getName())) {
xml.setName(wrapper.name());
}
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class JAXBAnnotationsHelper method applyAttribute.
/**
* Puts definitions for XML attribute.
*
* @param attribute XmlAttribute
* @param property property instance to be updated
*/
private static void applyAttribute(XmlAttribute attribute, Schema property) {
if (attribute != null) {
final XML xml = getXml(property);
xml.setAttribute(true);
setName(attribute.namespace(), attribute.name(), property);
}
}
Aggregations