use of io.swagger.v3.core.converter.AnnotatedType 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.core.converter.AnnotatedType 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.core.converter.AnnotatedType in project swagger-core by swagger-api.
the class ModelConverterContextImpl method resolve.
@Override
public Schema resolve(AnnotatedType type) {
AnnotatedType aType = OptionalUtils.unwrapOptional(type);
if (aType != null) {
return resolve(aType);
}
if (processedTypes.contains(type)) {
return modelByType.get(type);
} else {
processedTypes.add(type);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("resolve %s", type.getType()));
}
Iterator<ModelConverter> converters = this.getConverters();
Schema resolved = null;
if (converters.hasNext()) {
ModelConverter converter = converters.next();
LOGGER.trace("trying extension {}", converter);
resolved = converter.resolve(type, this, converters);
}
if (resolved != null) {
modelByType.put(type, resolved);
Schema resolvedImpl = resolved;
if (resolvedImpl.getName() != null) {
modelByName.put(resolvedImpl.getName(), resolved);
}
} else {
processedTypes.remove(type);
}
return resolved;
}
use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.
the class ReaderTest method resolveJaxb.
private Map<String, Schema> resolveJaxb(Type type) {
List<ModelConverter> converters = new CopyOnWriteArrayList<ModelConverter>();
ObjectMapper mapper = JaxbObjectMapperFactory.getMapper();
converters.add(new ModelResolver(mapper));
ModelConverterContextImpl context = new ModelConverterContextImpl(converters);
Schema resolve = context.resolve(new AnnotatedType().type(type));
Map<String, Schema> schemas = new HashMap<String, Schema>();
for (Map.Entry<String, Schema> entry : context.getDefinedModels().entrySet()) {
if (entry.getValue().equals(resolve)) {
schemas.put(entry.getKey(), entry.getValue());
}
}
return schemas;
}
use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.
the class PatternAndSchemaPropertiesTest method testSinglePatternAndSchemaProperties.
@Test
public void testSinglePatternAndSchemaProperties() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
Schema model = context.resolve(new AnnotatedType(AnnotatedPetSinglePatternProperty.class));
assertEquals(((Schema) model.getPatternProperties().get("what.*ever")).getFormat(), "int32");
assertEquals(((Schema) model.getProperties().get("anotherCategory")).get$ref(), "#/components/schemas/Category");
}
Aggregations