Search in sources :

Example 11 with ModelImpl

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

the class ParameterSerializationTest method serializeBodyParameterToYaml.

@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
    final ModelImpl model = new ModelImpl().name("Cat").property("name", new StringProperty());
    final BodyParameter p = new BodyParameter().schema(model);
    final String yaml = "---\n" + "in: \"body\"\n" + "required: false\n" + "schema:\n" + "  properties:\n" + "    name:\n" + "      type: \"string\"";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 12 with ModelImpl

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

the class ObjectPropertyTest method readModelWithObjectProperty.

@Test(description = "convert a model with object properties")
public void readModelWithObjectProperty() throws IOException {
    String json = "{" + "   \"properties\":{" + "      \"id\":{" + "         \"type\":\"string\"" + "      }," + "      \"someObject\":{" + "         \"type\":\"object\"," + "        \"x-foo\": \"vendor x\"," + "         \"properties\":{" + "            \"innerId\":{" + "               \"type\":\"string\"" + "            }" + "         }" + "      }" + "   }" + "}";
    ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    Property p = model.getProperties().get("someObject");
    assertTrue(p instanceof ObjectProperty);
    ObjectProperty op = (ObjectProperty) p;
    Property sp = op.getProperties().get("innerId");
    assertTrue(sp instanceof StringProperty);
    assertTrue(op.getVendorExtensions() != null);
    assertNotNull(op.getVendorExtensions().get("x-foo"));
    assertEquals(op.getVendorExtensions().get("x-foo"), "vendor x");
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) StringProperty(io.swagger.models.properties.StringProperty) ModelImpl(io.swagger.models.ModelImpl) ObjectProperty(io.swagger.models.properties.ObjectProperty) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 13 with ModelImpl

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

the class ModelSerializerTest method testPrimitiveModel.

@Test
public void testPrimitiveModel() throws Exception {
    String json = "{\n" + "  \"type\": \"string\",\n" + "  \"enum\": [\n" + "    \"a\",\n" + "    \"b\",\n" + "    \"c\"\n" + "  ]\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    assertNotNull(model.getEnum());
    assertTrue(model.getEnum().size() == 3);
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 14 with ModelImpl

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

the class ModelSerializerTest method convertModel.

@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
    final ModelImpl pet = new ModelImpl();
    final HashMap<String, Property> props = new HashMap<String, Property>();
    props.put("intValue", new IntegerProperty());
    props.put("longValue", new LongProperty());
    props.put("dateValue", new DateProperty());
    props.put("dateTimeValue", new DateTimeProperty());
    pet.setProperties(props);
    pet.setRequired(Arrays.asList("intValue", "name"));
    final String json = "{\n" + "   \"required\":[\n" + "      \"intValue\"\n" + "   ],\n" + "   \"properties\":{\n" + "      \"dateValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date\"\n" + "      },\n" + "      \"longValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int64\"\n" + "      },\n" + "      \"dateTimeValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date-time\"\n" + "      },\n" + "      \"intValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      }\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(pet, json);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) HashMap(java.util.HashMap) DateProperty(io.swagger.models.properties.DateProperty) LongProperty(io.swagger.models.properties.LongProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 15 with ModelImpl

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

the class ModelSerializerTest method testIssue2064Neg.

@Test
public void testIssue2064Neg() throws Exception {
    String json = "{\n" + "  \"type\": \"string\",\n" + "  \"uniqueItems\": false\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    assertFalse(model.getUniqueItems());
}
Also used : 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