Search in sources :

Example 21 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class XMLInfoTest method testReadingXmlAccessorTypePublic.

@Test
public void testReadingXmlAccessorTypePublic() throws Exception {
    final ModelConverter mr = modelResolver();
    final Model model = mr.resolve(XmlDecoratedBeanXmlAccessorPublic.class, new ModelConverterContextImpl(mr), null);
    assertTrue(model instanceof ModelImpl);
    final ModelImpl impl = (ModelImpl) model;
    final Xml xml = impl.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    final Property propertyA = impl.getProperties().get("a");
    assertNotNull(propertyA);
    Property propertyB = impl.getProperties().get("b");
    assertNotNull(propertyB);
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ApiModel(io.swagger.annotations.ApiModel) ModelImpl(io.swagger.models.ModelImpl) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelConverter(io.swagger.converter.ModelConverter) ModelConverterContextImpl(io.swagger.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 22 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class SpecFilterTest method filterNoPropertiesModels.

@Test(description = "it should filter models where some fields have no properties")
public void filterNoPropertiesModels() throws IOException {
    final String modelName = "Array";
    final ModelImpl model = new ModelImpl().type(ModelImpl.OBJECT).name(modelName);
    final Swagger swagger = new Swagger();
    swagger.addDefinition(modelName, model);
    final Map<String, Model> filtered = new SpecFilter().filterDefinitions(new NoOpOperationsFilter(), swagger.getDefinitions(), null, null, null);
    if (filtered.size() != 1) {
        fail("ModelImpl with no properties failed to filter");
    }
}
Also used : Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 23 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ModelDeserializer method deserialize.

@Override
public Model deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    JsonNode sub = node.get("$ref");
    JsonNode allOf = node.get("allOf");
    if (sub != null) {
        return Json.mapper().convertValue(sub, RefModel.class);
    } else if (allOf != null) {
        ComposedModel model = null;
        // we only support one parent, no multiple inheritance or composition
        model = Json.mapper().convertValue(node, ComposedModel.class);
        List<Model> allComponents = model.getAllOf();
        if (allComponents.size() >= 1) {
            model.setParent(allComponents.get(0));
            if (allComponents.size() >= 2) {
                model.setChild(allComponents.get(allComponents.size() - 1));
                List<RefModel> interfaces = new ArrayList<RefModel>();
                int size = allComponents.size();
                for (Model m : allComponents.subList(1, size - 1)) {
                    if (m instanceof RefModel) {
                        RefModel ref = (RefModel) m;
                        interfaces.add(ref);
                    }
                }
                model.setInterfaces(interfaces);
            } else {
                model.setChild(new ModelImpl());
            }
        }
        return model;
    } else {
        sub = node.get("type");
        Model model = null;
        if (sub != null && "array".equals(((TextNode) sub).textValue())) {
            model = Json.mapper().convertValue(node, ArrayModel.class);
        } else {
            model = Json.mapper().convertValue(node, ModelImpl.class);
        }
        return model;
    }
}
Also used : RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) ModelImpl(io.swagger.models.ModelImpl)

Example 24 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ByteConverterTest method testByteProperty.

@Test
public void testByteProperty() {
    Model model = new ModelImpl().property("byteProperty", new ByteArrayProperty());
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteProperty\" : {" + NEWLINE + "      \"type\" : \"string\"," + NEWLINE + "      \"format\" : \"byte\"" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 25 with ModelImpl

use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.

the class ByteConverterTest method testReadOnlyByteArray.

@Test
public void testReadOnlyByteArray() {
    Model model = new ModelImpl().property("byteArray", new ArrayProperty(new BinaryProperty()).readOnly());
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteArray\" : {" + NEWLINE + "      \"type\" : \"array\"," + NEWLINE + "      \"readOnly\" : true," + NEWLINE + "      \"items\" : {" + NEWLINE + "        \"type\" : \"string\"," + NEWLINE + "        \"format\" : \"binary\"" + NEWLINE + "      }" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) BinaryProperty(io.swagger.models.properties.BinaryProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)46 Test (org.testng.annotations.Test)37 Model (io.swagger.models.Model)24 Property (io.swagger.models.properties.Property)17 StringProperty (io.swagger.models.properties.StringProperty)16 ArrayProperty (io.swagger.models.properties.ArrayProperty)12 IntegerProperty (io.swagger.models.properties.IntegerProperty)11 RefProperty (io.swagger.models.properties.RefProperty)9 Xml (io.swagger.models.Xml)8 RefModel (io.swagger.models.RefModel)7 BodyParameter (io.swagger.models.parameters.BodyParameter)7 LongProperty (io.swagger.models.properties.LongProperty)7 MapProperty (io.swagger.models.properties.MapProperty)7 ApiModel (io.swagger.annotations.ApiModel)6 ApiModelProperty (io.swagger.annotations.ApiModelProperty)6 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)5 ComposedModel (io.swagger.models.ComposedModel)5 EmptyModel (io.swagger.models.EmptyModel)4 JacksonReadonlyModel (io.swagger.models.JacksonReadonlyModel)4 JodaDateTimeModel (io.swagger.models.JodaDateTimeModel)4