Search in sources :

Example 1 with ModelImpl

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;
}
Also used : RefModel(io.swagger.models.RefModel) ModelImpl(io.swagger.models.ModelImpl)

Example 2 with ModelImpl

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");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 3 with ModelImpl

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));
        }
    }
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 4 with ModelImpl

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");
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 5 with ModelImpl

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());
}
Also used : Xml(io.swagger.models.Xml) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)102 Test (org.testng.annotations.Test)46 Model (io.swagger.models.Model)40 Property (io.swagger.models.properties.Property)37 StringProperty (io.swagger.models.properties.StringProperty)30 RefProperty (io.swagger.models.properties.RefProperty)29 ArrayProperty (io.swagger.models.properties.ArrayProperty)27 BodyParameter (io.swagger.models.parameters.BodyParameter)23 RefModel (io.swagger.models.RefModel)22 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Swagger (io.swagger.models.Swagger)15 MapProperty (io.swagger.models.properties.MapProperty)14 Map (java.util.Map)13 HashMap (java.util.HashMap)12 Test (org.junit.Test)12 JavaType (com.fasterxml.jackson.databind.JavaType)11 ComposedModel (io.swagger.models.ComposedModel)11 Parameter (io.swagger.models.parameters.Parameter)11 ArrayModel (io.swagger.models.ArrayModel)10 ArrayList (java.util.ArrayList)10