Search in sources :

Example 71 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.

the class SpecFilterTest method shouldRemoveBrokenRefs.

@Test
public void shouldRemoveBrokenRefs() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
    assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
    assertNotNull(filtered.getComponents().getSchemas().get("Category"));
    assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 72 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.

the class SpecFilterTest method shouldRemoveBrokenNestedRefs.

@Test
public void shouldRemoveBrokenNestedRefs() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH_3303);
    openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
    assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
    assertNull(filtered.getComponents().getSchemas().get("Bar"));
    assertNotNull(filtered.getComponents().getSchemas().get("Category"));
    assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
    assertNotNull(filtered.getComponents().getSchemas().get("Foo"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfNestedParentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfNestedParentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorParent"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorMatchedChildA"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorRefProperty"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorParentRefProperty"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorMatchedChildB"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 73 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwayPetRefInSchemas.

@Test(description = "it should filter any Pet Ref in Schemas")
public void filterAwayPetRefInSchemas() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoPetRefSchemaFilter(), null, null, null);
    validateSchemasInComponents(filtered.getComponents(), PET_MODEL);
}
Also used : NoPetRefSchemaFilter(io.swagger.v3.core.filter.resources.NoPetRefSchemaFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 74 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.

the class JsonDeserializationTest method testDeserializeAResponseRef.

@Test
public void testDeserializeAResponseRef() throws Exception {
    final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/responseRef.json", OpenAPI.class);
    final ApiResponses responseMap = oas.getPaths().get("/pet").getPut().getResponses();
    // TODO: missing response ref
    assertIsRefResponse(responseMap.get("405"), "http://my.company.com/responses/errors.json#/method-not-allowed");
    assertIsRefResponse(responseMap.get("404"), "http://my.company.com/responses/errors.json#/not-found");
    assertTrue(responseMap.get("400") instanceof ApiResponse);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 75 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.

the class JsonDeserializationTest method testExampleDeserializationOnMediaType.

@Test
public void testExampleDeserializationOnMediaType() throws Exception {
    String content = FileUtils.readFileToString(new File("src/test/resources/specFiles/media-type-null-example.yaml"), "UTF-8");
    OpenAPI openAPI = Yaml.mapper().readValue(content, OpenAPI.class);
    assertNull(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExample());
    assertTrue(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
    assertNull(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExample());
    assertFalse(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
    assertNotNull(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExample());
    assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag());
}
Also used : File(java.io.File) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)69 OpenAPI (io.swagger.v3.oas.models.OpenAPI)60 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)37 Schema (io.swagger.v3.oas.models.media.Schema)32 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)28 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)28 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)24 StringSchema (io.swagger.v3.oas.models.media.StringSchema)24 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)20 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)17 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)17 PathItem (io.swagger.v3.oas.models.PathItem)16 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)15 MapSchema (io.swagger.v3.oas.models.media.MapSchema)12 DateSchema (io.swagger.v3.oas.models.media.DateSchema)10 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)10 ArrayList (java.util.ArrayList)10 Operation (io.swagger.v3.oas.models.Operation)9 Paths (io.swagger.v3.oas.models.Paths)9 Parameter (io.swagger.v3.oas.models.parameters.Parameter)8