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);
}
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");
}
}
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;
}
}
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 + "}");
}
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 + "}");
}
Aggregations