Search in sources :

Example 91 with Schema

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;
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) SchemaProperty(io.swagger.v3.oas.annotations.media.SchemaProperty) 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) SchemaProperties(io.swagger.v3.oas.annotations.media.SchemaProperties)

Example 92 with Schema

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;
}
Also used : HashMap(java.util.HashMap) Schema(io.swagger.v3.oas.models.media.Schema)

Example 93 with Schema

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);
    }
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema)

Example 94 with Schema

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());
        }
    }
}
Also used : XML(io.swagger.v3.oas.models.media.XML)

Example 95 with Schema

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);
    }
}
Also used : XML(io.swagger.v3.oas.models.media.XML)

Aggregations

Test (org.testng.annotations.Test)257 Schema (io.swagger.v3.oas.models.media.Schema)234 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)141 StringSchema (io.swagger.v3.oas.models.media.StringSchema)126 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)112 OpenAPI (io.swagger.v3.oas.models.OpenAPI)68 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)65 MapSchema (io.swagger.v3.oas.models.media.MapSchema)62 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)60 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)58 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)51 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)47 Operation (io.swagger.v3.oas.annotations.Operation)44 DateSchema (io.swagger.v3.oas.models.media.DateSchema)44 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)42 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)42 Parameter (io.swagger.v3.oas.models.parameters.Parameter)33 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)32 ModelConverterContextImpl (io.swagger.v3.core.converter.ModelConverterContextImpl)25 Components (io.swagger.v3.oas.models.Components)23