use of io.swagger.models.ModelImpl in project java-chassis by ServiceComb.
the class PendingBodyParameter method toRefModel.
// swagger中的body只能是ref,不能是简单类型
private RefModel toRefModel(String modelType) {
if (RefProperty.class.isInstance(property)) {
return (RefModel) PropertyBuilder.toModel(property);
}
ModelImpl modelImpl = new ModelImpl();
modelImpl.setType("object");
modelImpl.setName(name);
modelImpl.addProperty(name, property);
operationGenerator.getSwagger().addDefinition(modelType, modelImpl);
RefModel refModel = new RefModel();
refModel.setReference("#/definitions/" + modelType);
return refModel;
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ScannerTest method scanBeanParamResource.
@Test(description = "scan a bean param resource")
public void scanBeanParamResource() {
final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
final List<Parameter> params = getParameters(swagger, "/bean/{id}");
final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
assertEquals(headerParam1.getDefaultValue(), 1);
assertEquals(headerParam1.getName(), "test order annotation 1");
final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
assertEquals(headerParam2.getDefaultValue(), 2);
assertEquals(headerParam2.getName(), "test order annotation 2");
final QueryParameter priority1 = (QueryParameter) params.get(2);
assertNull(priority1.getDefaultValue());
assertEquals(priority1.getName(), "test priority 1");
final QueryParameter priority2 = (QueryParameter) params.get(3);
assertEquals(priority2.getDefaultValue(), 4);
assertEquals(priority2.getName(), "test priority 2");
final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
assertEquals(bodyParam1.getDefaultValue(), "bodyParam");
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method processModelWithJAXBAnnotations.
@Test(description = "it should process a model with JAXB annotations")
public void processModelWithJAXBAnnotations() {
final Map<String, Model> schemas = ModelConverters.getInstance().readAll(ModelWithJAXBAnnotations.class);
assertEquals(schemas.size(), 1);
final Model model = schemas.get("ModelWithJAXBAnnotations");
assertNotNull(model);
assertTrue(model instanceof ModelImpl);
final Xml rootXml = ((ModelImpl) model).getXml();
assertNotNull(rootXml);
assertEquals(rootXml.getName(), "rootName");
for (Map.Entry<String, Property> entry : model.getProperties().entrySet()) {
final String name = entry.getKey();
final Property property = entry.getValue();
if ("id".equals(name)) {
final Xml xml = property.getXml();
assertNotNull(xml);
assertNull(xml.getName());
assertTrue(xml.getAttribute());
assertNull(xml.getWrapped());
} else if ("name".equals(name)) {
final Xml xml = property.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "renamed");
assertNull(xml.getAttribute());
assertNull(xml.getWrapped());
} else if (Arrays.asList("list", "forcedElement").contains(name)) {
assertNull(property.getXml());
} else if ("wrappedList".equals(name)) {
final Xml xml = property.getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "wrappedListItems");
assertNull(xml.getAttribute());
assertTrue(xml.getWrapped());
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method deserializeModel.
@Test(description = "it should deserialize a model")
public void deserializeModel() throws IOException {
final String yaml = "---\n" + "type: \"object\"\n" + "properties:\n" + " id:\n" + " type: \"string\"\n" + " xml:\n" + " attribute: true\n" + " name:\n" + " type: \"string\"\n" + " xml:\n" + " name: \"renamed\"\n" + " list:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + " wrappedList:\n" + " type: \"array\"\n" + " xml:\n" + " name: \"wrappedListItems\"\n" + " wrapped: true\n" + " items:\n" + " type: \"string\"\n" + " forcedElement:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + "xml:\n" + " name: \"rootName\"";
final ModelImpl model = io.swagger.util.Yaml.mapper().readValue(yaml, ModelImpl.class);
final Property wrappedList = model.getProperties().get("wrappedList");
assertNotNull(wrappedList);
assertNotNull(wrappedList.getXml());
assertEquals(wrappedList.getXml().getName(), "wrappedListItems");
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class XmlModelTest method processXMLModelAttribute.
@Test(description = "it should process an XML model attribute")
public void processXMLModelAttribute() {
final Map<String, Model> schemas = ModelConverters.getInstance().readAll(Monster.class);
final Model model = schemas.get("Monster");
assertNotNull(model);
assertTrue(model instanceof ModelImpl);
Xml xml = ((ModelImpl) model).getXml();
assertNotNull(xml);
assertEquals(xml.getName(), "monster");
final Property property = model.getProperties().get("children");
assertNotNull(property);
xml = property.getXml();
assertTrue(xml.getWrapped());
assertNull(xml.getName());
}
Aggregations