use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class EnumTest method testEnum.
@Test
public void testEnum() {
final ModelResolver modelResolver = new ModelResolver(mapper());
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
final Schema model = context.resolve((new AnnotatedType().type(Currency.class)));
assertNotNull(model);
assertTrue(model instanceof StringSchema);
final StringSchema strModel = (StringSchema) model;
assertNotNull(strModel.getEnum());
final Collection<String> modelValues = new ArrayList<String>(Collections2.transform(Arrays.asList(Currency.values()), Functions.toStringFunction()));
assertEquals(strModel.getEnum(), modelValues);
final Schema property = context.resolve(new AnnotatedType().type(Currency.class).schemaProperty(true));
assertNotNull(property);
assertTrue(property instanceof StringSchema);
final StringSchema strProperty = (StringSchema) property;
assertNotNull(strProperty.getEnum());
final Collection<String> values = new ArrayList<>(Collections2.transform(Arrays.asList(Currency.values()), Functions.toStringFunction()));
assertEquals(strProperty.getEnum(), values);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeStringMapProperty.
@Test(description = "it should serialize a string MapProperty")
public void serializeStringMapProperty() throws IOException {
final Schema p = new MapSchema().additionalProperties(new StringSchema());
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeStringProperty.
@Test(description = "it should serialize a StringProperty")
public void serializeStringProperty() throws IOException {
final StringSchema p = new StringSchema()._default("Bob");
final String json = "{\"type\":\"string\",\"default\":\"Bob\"}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeObjectPropertyWithRequiredProperties.
@Test(description = "it should serialize an object property with required set")
public void serializeObjectPropertyWithRequiredProperties() throws IOException {
final Schema p = new ObjectSchema().addProperties("stringProperty", new StringSchema());
p.required(Arrays.asList("stringProperty"));
final String json = "{\"required\":[\"stringProperty\"],\"type\":\"object\",\"properties\":{\"stringProperty\":{\"type\":\"string\"}}}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.StringSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeArrayStringProperty.
@Test(description = "it should serialize a string array property")
public void serializeArrayStringProperty() throws IOException {
final Schema p = new ArraySchema().items(new StringSchema());
final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}";
assertEquals(m.writeValueAsString(p), json);
}
Aggregations