use of io.swagger.v3.oas.models.media.MapSchema in project swagger-core by swagger-api.
the class ModelConverterTest method processModelWithPairProperties.
@Test(description = "it should process a model with org.apache.commons.lang3.tuple.Pair properties")
public void processModelWithPairProperties() {
final ModelWithTuple2.TupleAsMapPropertyConverter asPropertyConverter = new ModelWithTuple2.TupleAsMapPropertyConverter(Json.mapper());
ModelConverters.getInstance().addConverter(asPropertyConverter);
final Map<String, Schema> asProperty = readAll(ModelWithTuple2.class);
ModelConverters.getInstance().removeConverter(asPropertyConverter);
// assertEquals(asProperty.size(), 2);
Map<String, Schema> values = asProperty.get("ModelWithTuple2").getProperties();
Yaml.prettyPrint(values);
for (Map.Entry<String, Schema> entry : values.entrySet()) {
String name = entry.getKey();
Schema property = entry.getValue();
if ("timesheetStates".equals(name)) {
assertEquals(property.getClass(), MapSchema.class);
} else if ("manyPairs".equals(name)) {
assertEquals(property.getClass(), ArraySchema.class);
Schema items = ((ArraySchema) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapSchema.class);
Schema stringProperty = (Schema) ((MapSchema) items).getAdditionalProperties();
assertNotNull(stringProperty);
assertEquals(stringProperty.getClass(), StringSchema.class);
} else if ("complexLeft".equals(name)) {
assertEquals(property.getClass(), ArraySchema.class);
Schema items = ((ArraySchema) property).getItems();
assertNotNull(items);
assertEquals(items.getClass(), MapSchema.class);
Schema additionalProperty = (Schema) ((MapSchema) items).getAdditionalProperties();
assertNotNull(additionalProperty);
assertNotNull(additionalProperty.get$ref());
assertEquals(additionalProperty.get$ref(), "#/components/schemas/ComplexLeft");
} else {
fail(String.format("Unexpected property: %s", name));
}
}
}
use of io.swagger.v3.oas.models.media.MapSchema in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesDeserialization.
@Test(description = "it should deserialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof ObjectSchema);
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
Assert.assertFalse((Boolean) responseSchema.getAdditionalProperties());
operation = Json.mapper().readValue(jsonAdditionalPropertiesBooleanTrue, Operation.class);
response = operation.getResponses().get("200");
assertNotNull(response);
responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapSchema);
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
Assert.assertTrue((Boolean) responseSchema.getAdditionalProperties());
}
use of io.swagger.v3.oas.models.media.MapSchema in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.
@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
MapSchema mp = (MapSchema) responseSchema;
assertTrue(mp.getExtensions().size() > 0);
assertNotNull(mp.getExtensions().get("x-foo"));
assertEquals(mp.getExtensions().get("x-foo"), "vendor x");
}
use of io.swagger.v3.oas.models.media.MapSchema in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testMapDeserialization.
@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
Schema responseSchema = response.getContent().get("*/*").getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapSchema);
MapSchema mp = (MapSchema) responseSchema;
assertTrue(mp.getAdditionalProperties() instanceof IntegerSchema);
}
use of io.swagger.v3.oas.models.media.MapSchema in project swagger-core by swagger-api.
the class JsonPropertiesDeserializationTest method givenMapProperty_shouldDeserializeMinProperties.
@Test
public void givenMapProperty_shouldDeserializeMinProperties() {
String path = "json-schema-validation/map.json";
MapSchema property = (MapSchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class);
assertNotNull(property.getMinProperties());
assertEquals(property.getMinProperties().intValue(), 1);
}
Aggregations