Search in sources :

Example 16 with ModelConverterContextImpl

use of io.swagger.v3.core.converter.ModelConverterContextImpl 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"));
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) XML(io.swagger.v3.oas.models.media.XML) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverter(io.swagger.v3.core.converter.ModelConverter) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 17 with ModelConverterContextImpl

use of io.swagger.v3.core.converter.ModelConverterContextImpl in project swagger-core by swagger-api.

the class ComplexPropertyTest method testOuterBean.

@Test
public void testOuterBean() throws Exception {
    final ModelResolver modelResolver = modelResolver();
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(OuterBean.class));
    assertNotNull(model);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Example 18 with ModelConverterContextImpl

use of io.swagger.v3.core.converter.ModelConverterContextImpl 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 19 with ModelConverterContextImpl

use of io.swagger.v3.core.converter.ModelConverterContextImpl 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;
}
Also used : HashMap(java.util.HashMap) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverter(io.swagger.v3.core.converter.ModelConverter) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 20 with ModelConverterContextImpl

use of io.swagger.v3.core.converter.ModelConverterContextImpl 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");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) OpenAPISchema2JsonSchema(io.swagger.v3.core.util.OpenAPISchema2JsonSchema) Schema(io.swagger.v3.oas.models.media.Schema) AnnotatedPetSinglePatternProperty(io.swagger.v3.core.resolving.v31.model.AnnotatedPetSinglePatternProperty) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Aggregations

ModelConverterContextImpl (io.swagger.v3.core.converter.ModelConverterContextImpl)33 ModelResolver (io.swagger.v3.core.jackson.ModelResolver)29 Schema (io.swagger.v3.oas.models.media.Schema)27 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)26 Test (org.testng.annotations.Test)24 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 ModelConverter (io.swagger.v3.core.converter.ModelConverter)6 XML (io.swagger.v3.oas.models.media.XML)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 StringSchema (io.swagger.v3.oas.models.media.StringSchema)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)1 JsonIdentityReference (com.fasterxml.jackson.annotation.JsonIdentityReference)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1