Search in sources :

Example 1 with PatternProperty

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;
}
Also used : PatternProperty(io.swagger.v3.oas.annotations.media.PatternProperty) AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) PatternProperties(io.swagger.v3.oas.annotations.media.PatternProperties) UUIDSchema(io.swagger.v3.oas.models.media.UUIDSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)1 PatternProperties (io.swagger.v3.oas.annotations.media.PatternProperties)1 PatternProperty (io.swagger.v3.oas.annotations.media.PatternProperty)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)1 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)1 MapSchema (io.swagger.v3.oas.models.media.MapSchema)1 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)1 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 StringSchema (io.swagger.v3.oas.models.media.StringSchema)1 UUIDSchema (io.swagger.v3.oas.models.media.UUIDSchema)1 Annotation (java.lang.annotation.Annotation)1 LinkedHashMap (java.util.LinkedHashMap)1