Search in sources :

Example 26 with Property

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

the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.

@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
    Operation operation = Yaml.mapper().readValue("      produces:\n" + "        - application/json\n" + "      responses:\n" + "        200:\n" + "          description: OK\n" + "          schema:\n" + "            type: object\n" + "            properties:\n" + "              id:\n" + "                type: integer\n" + "                format: int32\n" + "              name:\n" + "                type: string\n" + "            required: [id, name]\n" + "            example:\n" + "              id: 42\n" + "              name: Arthur Dent\n", Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property schema = response.getSchema();
    Object example = schema.getExample();
    assertNotNull(example);
    assertTrue(example instanceof ObjectNode);
    ObjectNode objectNode = (ObjectNode) example;
    assertEquals(objectNode.get("id").intValue(), 42);
    assertEquals(objectNode.get("name").textValue(), "Arthur Dent");
}
Also used : Response(io.swagger.models.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 27 with Property

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

the class PropertyDeserializerTest method deserializeParameterWithMinimumMaximumValues.

@Test
public void deserializeParameterWithMinimumMaximumValues() throws Exception {
    String json = "{\n" + "  \"in\": \"query\",\n" + "  \"type\": \"integer\",\n" + "  \"format\": \"int32\",\n" + "  \"minimum\": 32,\n" + "  \"maximum\": 100\n" + "}";
    Property property = Json.mapper().readValue(json, Property.class);
    assertTrue(property instanceof IntegerProperty);
    IntegerProperty ip = (IntegerProperty) property;
    assertEquals(ip.getMinimum(), new BigDecimal("32"));
    assertEquals(ip.getMaximum(), new BigDecimal("100"));
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 28 with Property

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

the class PropertySerializationTest method deserializeRefProperty.

@Test(description = "it should deserialize a RefProperty")
public void deserializeRefProperty() throws IOException {
    final String json = "{\"$ref\":\"#/definitions/Dog\"}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getClass(), RefProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 29 with Property

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

the class PropertySerializationTest method deserializeStringMapProperty.

@Test(description = "it should deserialize a string MapProperty")
public void deserializeStringMapProperty() throws IOException {
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "object");
    assertEquals(p.getClass(), MapProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 30 with Property

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

the class PropertySerializationTest method deserializeEnumIntegerProperty.

@Test(description = "it should deserialize an IntegerProperty with enums")
public void deserializeEnumIntegerProperty() throws IOException {
    final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "integer");
    List<Integer> _enum = ((IntegerProperty) p).getEnum();
    assertNotNull(_enum);
    assertEquals(_enum, Arrays.asList(1, 2));
    assertEquals(p.getClass(), IntegerProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

Property (io.swagger.models.properties.Property)143 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)85 StringProperty (io.swagger.models.properties.StringProperty)73 RefProperty (io.swagger.models.properties.RefProperty)64 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)51 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)16 Response (io.swagger.models.Response)16