use of io.swagger.v3.oas.annotations.media.PatternProperty in project swagger-core by swagger-api.
the class ModelResolver method resolvePatternProperties.
protected Map<String, Schema> resolvePatternProperties(JavaType a, Annotation[] annotations, ModelConverterContext context) {
final Map<String, PatternProperty> propList = new LinkedHashMap<>();
PatternProperties props = a.getRawClass().getAnnotation(PatternProperties.class);
if (props != null && props.value().length > 0) {
for (PatternProperty prop : props.value()) {
propList.put(prop.regex(), prop);
}
}
PatternProperty singleProp = a.getRawClass().getAnnotation(PatternProperty.class);
if (singleProp != null) {
propList.put(singleProp.regex(), singleProp);
}
props = AnnotationsUtils.getAnnotation(PatternProperties.class, annotations);
if (props != null && props.value().length > 0) {
for (PatternProperty prop : props.value()) {
propList.put(prop.regex(), prop);
}
}
singleProp = AnnotationsUtils.getAnnotation(PatternProperty.class, annotations);
if (singleProp != null) {
propList.put(singleProp.regex(), singleProp);
}
if (propList.isEmpty()) {
return null;
}
Map<String, Schema> patternProperties = new LinkedHashMap<>();
for (PatternProperty prop : propList.values()) {
String key = prop.regex();
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) {
patternProperties.put(key, resolvedPropSchema);
}
}
return patternProperties;
}
Aggregations