use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeRefCallback.
@Test(description = "Deserialize ref callback")
public void testDeserializeRefCallback() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /simplecallback:\n" + " get:\n" + " summary: Simple get operation\n" + " operationId: getWithNoParameters\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " callbacks:\n" + " testCallback1:\n" + " $ref: '#/components/callbacks/Callback'\n" + " callbacks:\n" + " testCallback1:\n" + " $ref: '#/components/callbacks/Callback'\n" + "components:\n" + " callbacks:\n" + " Callback:\n" + " /post:\n" + " description: Post Path Item\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getPaths().get("/simplecallback").getGet().getCallbacks().get("testCallback1").get$ref(), "#/components/callbacks/Callback");
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class JsonDeserializationTest method deserializeDateExample.
@Test
public void deserializeDateExample() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/swos-126.yaml");
final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
Map<String, Schema> props = swagger.getComponents().getSchemas().get("MyModel").getProperties();
assertTrue(Yaml.pretty().writeValueAsString(props.get("date")).contains("example: 2019-08-05"));
assertTrue(Yaml.pretty().writeValueAsString(props.get("dateTime")).contains("example: 2019-08-05T12:34:56Z"));
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class OpenAPI3_1DeserializationTest method deserializePetstore3_1.
@Test
public void deserializePetstore3_1() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1.yaml");
final OpenAPI swagger = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
assertEquals(swagger.getInfo().getLicense().getIdentifier(), "test");
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ArrayPropertyDeserializerTest method testArrayDeserialization.
@Test(description = "it should includes the example in the arrayproperty")
public void testArrayDeserialization() throws Exception {
Operation operation = Yaml.mapper().readValue(yaml, Operation.class);
ApiResponse response = operation.getResponses().get("200");
assertNotNull(response);
MediaType media = response.getContent().get("*/*");
Schema responseSchema = media.getSchema();
assertTrue(media.getExamples().size() == 2);
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof ArraySchema);
ArraySchema mp = (ArraySchema) responseSchema;
assertEquals(mp.getMinItems(), new Integer(3));
assertEquals(mp.getMaxItems(), new Integer(100));
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class JsonSerializationTest method testSerializeNullInSchemaExample.
@Test
public void testSerializeNullInSchemaExample() throws Exception {
final String yaml = ResourceUtils.loadClassResource(getClass(), "specFiles/null-in-schema-example.yaml");
OpenAPI deser = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(deser, yaml);
}
Aggregations