use of io.swagger.v3.core.converter.ModelConverter in project swagger-core by swagger-api.
the class GericModelConverter method resolve.
@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> next) {
if (type.getType() instanceof Class<?>) {
Class<?> cls = (Class<?>) type.getType();
if (GenericModel.class.isAssignableFrom(cls)) {
Schema impl = new Schema();
impl.title(cls.getSimpleName());
for (Entry<String, Class<?>> entry : GenericModel.getDeclaredProperties().entrySet()) {
impl.addProperties(entry.getKey(), context.resolve(new AnnotatedType(entry.getValue())));
}
context.defineModel(impl.getTitle(), impl);
return impl;
}
}
if (next.hasNext()) {
return next.next().resolve(type, context, next);
} else {
return null;
}
}
use of io.swagger.v3.core.converter.ModelConverter in project swagger-core by swagger-api.
the class XMLInfoTest method testReadingXmlAccessorTypeNone.
@Test
public void testReadingXmlAccessorTypeNone() throws Exception {
final ModelConverter mr = modelResolver();
final Schema model = mr.resolve(new AnnotatedType(XmlDecoratedBeanXmlAccessorNone.class), new ModelConverterContextImpl(mr), null);
final XML xml = model.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "xmlDecoratedBean");
final Schema property = (Schema) model.getProperties().get("a");
assertNotNull(property);
assertNull(model.getProperties().get("b"));
assertNotNull(model.getProperties().get("c"));
assertNotNull(model.getProperties().get("d"));
assertNotNull(model.getProperties().get("e"));
assertNotNull(model.getProperties().get("f"));
}
use of io.swagger.v3.core.converter.ModelConverter 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.ModelConverter 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.ModelConverter in project swagger-core by swagger-api.
the class GenericOpenApiContext method buildModelConverters.
protected Set<ModelConverter> buildModelConverters(final OpenAPIConfiguration openApiConfiguration) throws Exception {
if (openApiConfiguration.getModelConverterClasses() != null && !openApiConfiguration.getModelConverterClasses().isEmpty()) {
LinkedHashSet<ModelConverter> modelConverters = new LinkedHashSet<>();
for (String converterClass : openApiConfiguration.getModelConverterClasses()) {
Class cls = getClass().getClassLoader().loadClass(converterClass);
ModelConverter converter = (ModelConverter) cls.newInstance();
modelConverters.add(converter);
}
return modelConverters;
}
return null;
}
Aggregations