Search in sources :

Example 16 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 17 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 18 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)

Example 19 with ModelImpl

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

the class ModelSerializerTest method testIssue2064.

@Test
public void testIssue2064() throws Exception {
    String json = "{\n" + "  \"type\": \"string\",\n" + "  \"uniqueItems\": true\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    assertTrue(model.getUniqueItems());
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 20 with ModelImpl

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

the class ModelSerializerTest method deserializeModelWithObjectExample.

@Test(description = "it should deserialize a model with object example")
public void deserializeModelWithObjectExample() throws IOException {
    final String json = "{\n" + "   \"title\":\"Error\",\n" + "   \"type\":\"object\",\n" + "   \"properties\":{\n" + "      \"code\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      },\n" + "      \"message\":{\n" + "         \"type\":\"string\"\n" + "      },\n" + "      \"fields\":{\n" + "         \"type\":\"string\"\n" + "      }\n" + "   },\n" + "   \"example\":{\n" + "      \"code\":1,\n" + "      \"message\":\"hello\",\n" + "      \"fields\":\"abc\"\n" + "   }\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    assertEquals(Json.mapper().writeValueAsString(model.getExample()), "{\"code\":1,\"message\":\"hello\",\"fields\":\"abc\"}");
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)45 Test (org.testng.annotations.Test)37 Model (io.swagger.models.Model)23 Property (io.swagger.models.properties.Property)16 StringProperty (io.swagger.models.properties.StringProperty)15 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 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 BodyParameter (io.swagger.models.parameters.BodyParameter)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