Search in sources :

Example 41 with Yaml

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");
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 42 with Yaml

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"));
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 43 with Yaml

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");
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 44 with Yaml

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));
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) MediaType(io.swagger.v3.oas.models.media.MediaType) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 45 with Yaml

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);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)63 OpenAPI (io.swagger.v3.oas.models.OpenAPI)55 Schema (io.swagger.v3.oas.models.media.Schema)15 Components (io.swagger.v3.oas.models.Components)13 Info (io.swagger.v3.oas.models.info.Info)13 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)9 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)8 SpecFilter (io.swagger.v3.core.filter.SpecFilter)8 StringSchema (io.swagger.v3.oas.models.media.StringSchema)8 AfterTest (org.testng.annotations.AfterTest)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)5 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)4 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 IOException (java.io.IOException)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3