Search in sources :

Example 46 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeEnumStringProperty.

@Test(description = "it should deserialize a StringProperty with enums")
public void deserializeEnumStringProperty() throws IOException {
    final String json = "{\"type\":\"string\",\"enum\":[\"a\",\"b\"]}";
    final Schema p = m.readValue(json, Schema.class);
    assertEquals(p.getType(), "string");
    List<String> _enum = ((StringSchema) p).getEnum();
    assertNotNull(_enum);
    assertEquals(_enum, Arrays.asList("a", "b"));
    assertEquals(p.getClass(), StringSchema.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 47 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeObjectPropertyWithRequiredProperties.

@Test(description = "it should deserialize an object property with required set")
public void deserializeObjectPropertyWithRequiredProperties() throws IOException {
    final Schema p = new ObjectSchema().addProperties("stringProperty", new StringSchema());
    p.required(Arrays.asList("stringProperty"));
    final String json = "{\"type\":\"object\",\"properties\":{\"stringProperty\":{\"type\":\"string\"}},\"required\":[\"stringProperty\"]}";
    assertEquals(p, m.readValue(json, Schema.class));
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 48 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeNotReadOnlyStringProperty.

@Test(description = "it should serialize a string property with readOnly unset")
public void deserializeNotReadOnlyStringProperty() throws IOException {
    final StringSchema p = new StringSchema();
    p.setReadOnly(false);
    final String json = "{\"type\":\"string\",\"readOnly\":false}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Aggregations

StringSchema (io.swagger.v3.oas.models.media.StringSchema)47 Test (org.testng.annotations.Test)44 Schema (io.swagger.v3.oas.models.media.Schema)32 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)23 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)20 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)15 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)14 Parameter (io.swagger.v3.oas.models.parameters.Parameter)11 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)10 MapSchema (io.swagger.v3.oas.models.media.MapSchema)10 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)10 DateSchema (io.swagger.v3.oas.models.media.DateSchema)8 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)7 MediaType (io.swagger.v3.oas.models.media.MediaType)7 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)7 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)7 BigDecimal (java.math.BigDecimal)7 OpenAPI (io.swagger.v3.oas.models.OpenAPI)6 Content (io.swagger.v3.oas.models.media.Content)6 HashMap (java.util.HashMap)6