Search in sources :

Example 96 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.

the class OpenAPIParserTest method testIssue813.

@Test
public void testIssue813() throws Exception {
    String inputSpec = "{\n" + "  \"swagger\": \"2.0\",\n" + "  \"info\": {\n" + "    \"description\": \"This is a sample server Petstore server.  You can find out more about Swagger at <a href=\\\"http://swagger.io\\\">http://swagger.io</a> or on irc.freenode.net, #swagger.  For this sample, you can use the api key \\\"special-key\\\" to test the authorization filters\",\n" + "    \"version\": \"1.0.0\",\n" + "    \"title\": \"Swagger Petstore\",\n" + "    \"termsOfService\": \"http://helloreverb.com/terms/\",\n" + "    \"contact\": {\n" + "      \"email\": \"apiteam@wordnik.com\"\n" + "    },\n" + "    \"license\": {\n" + "      \"name\": \"Apache-2.0\",\n" + "      \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + "    }\n" + "  },\n" + "  \"host\": \"petstore.swagger.io\",\n" + "  \"basePath\": \"/v2\",\n" + "  \"schemes\": [\n" + "    \"http\"\n" + "  ],\n" + "  \"paths\": {\n" + "    \"/pet\": {\n" + "      \"post\": {\n" + "        \"tags\": [\n" + "          \"pet\"\n" + "        ],\n" + "        \"summary\": \"Add a new pet to the store\",\n" + "        \"description\": \"\",\n" + "        \"operationId\": \"addPet\",\n" + "        \"consumes\": [\n" + "          \"application/json\",\n" + "          \"application/xml\"\n" + "        ],\n" + "        \"produces\": [\n" + "          \"application/json\",\n" + "          \"application/xml\"\n" + "        ],\n" + "        \"parameters\": [{\n" + "          \"in\": \"body\",\n" + "          \"name\": \"body\",\n" + "          \"description\": \"Pet object that needs to be added to the store\",\n" + "          \"required\": false,\n" + "          \"schema\": {\n" + "            \"$ref\": \"#/definitions/Pet\"\n" + "          }\n" + "        }],\n" + "        \"responses\": {\n" + "          \"405\": {\n" + "            \"description\": \"Invalid input\"\n" + "          }\n" + "        },\n" + "        \"security\": [{\n" + "          \"petstore_auth\": [\n" + "            \"write:pets\",\n" + "            \"read:pets\"\n" + "          ]\n" + "        }]\n" + "      },\n" + "      \"put\": {\n" + "        \"tags\": [\n" + "          \"pet\"\n" + "        ],\n" + "        \"summary\": \"Update an existing pet\",\n" + "        \"description\": \"\",\n" + "        \"operationId\": \"updatePet\",\n" + "        \"consumes\": [\n" + "          \"application/json\",\n" + "          \"application/xml\"\n" + "        ],\n" + "        \"produces\": [\n" + "          \"application/json\",\n" + "          \"application/xml\"\n" + "        ],\n" + "        \"parameters\": [{\n" + "          \"in\": \"body\",\n" + "          \"name\": \"body\",\n" + "          \"description\": \"Pet object that needs to be added to the store\",\n" + "          \"required\": false,\n" + "          \"schema\": {\n" + "            \"$ref\": \"#/definitions/Pet\"\n" + "          }\n" + "        }],\n" + "        \"responses\": {\n" + "          \"405\": {\n" + "            \"description\": \"Validation exception\"\n" + "          },\n" + "          \"404\": {\n" + "            \"description\": \"Pet not found\"\n" + "          },\n" + "          \"400\": {\n" + "            \"description\": \"Invalid ID supplied\"\n" + "          }\n" + "        },\n" + "        \"security\": [{\n" + "          \"petstore_auth\": [\n" + "            \"write:pets\",\n" + "            \"read:pets\"\n" + "          ]\n" + "        }]\n" + "      }\n" + "    },\n" + "    \"securityDefinitions\": {\n" + "      \"api_key\": {\n" + "        \"type\": \"apiKey\",\n" + "        \"name\": \"api_key\",\n" + "        \"in\": \"header\"\n" + "      },\n" + "      \"petstore_auth\": {\n" + "        \"type\": \"oauth2\",\n" + "        \"authorizationUrl\": \"http://petstore.swagger.io/api/oauth/dialog\",\n" + "        \"flow\": \"implicit\",\n" + "        \"scopes\": {\n" + "          \"write:pets\": \"modify pets in your account\",\n" + "          \"read:pets\": \"read your pets\"\n" + "        }\n" + "      }\n" + "    },\n" + "    \"definitions\": {\n" + "      \"Pet\": {\n" + "        \"required\": [\n" + "          \"name\",\n" + "          \"photoUrls\"\n" + "        ],\n" + "        \"properties\": {\n" + "          \"id\": {\n" + "            \"type\": \"integer\",\n" + "            \"format\": \"int64\"\n" + "          },\n" + "          \"category\": {\n" + "            \"$ref\": \"#/definitions/Category\"\n" + "          },\n" + "          \"name\": {\n" + "            \"type\": \"string\",\n" + "            \"example\": \"doggie\"\n" + "          },\n" + "          \"photoUrls\": {\n" + "            \"type\": \"array\",\n" + "            \"xml\": {\n" + "              \"name\": \"photoUrl\",\n" + "              \"wrapped\": true\n" + "            },\n" + "            \"items\": {\n" + "              \"type\": \"string\"\n" + "            }\n" + "          },\n" + "          \"tags\": {\n" + "            \"type\": \"array\",\n" + "            \"xml\": {\n" + "              \"name\": \"tag\",\n" + "              \"wrapped\": true\n" + "            },\n" + "            \"items\": {\n" + "              \"$ref\": \"#/definitions/Tag\"\n" + "            }\n" + "          },\n" + "          \"status\": {\n" + "            \"type\": \"string\",\n" + "            \"description\": \"pet status in the store\",\n" + "            \"enum\": [\n" + "              \"available\",\n" + "              \"pending\",\n" + "              \"sold\"\n" + "            ]\n" + "          }\n" + "        },\n" + "        \"xml\": {\n" + "          \"name\": \"Pet\"\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setFlatten(true);
    SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, null, options);
    assertTrue(result.getOpenAPI() != null);
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) Test(org.junit.Test)

Example 97 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwayPetResource.

@Test(description = "it should filter away the pet resource")
public void filterAwayPetResource() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final NoPetOperationsFilter filter = new NoPetOperationsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            assertNull(entry.getValue().getDelete());
            assertNull(entry.getValue().getPost());
            assertNull(entry.getValue().getPut());
            assertNull(entry.getValue().getGet());
            assertNull(entry.getValue().getHead());
            assertNull(entry.getValue().getOptions());
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoPetOperationsFilter(io.swagger.v3.core.filter.resources.NoPetOperationsFilter) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 98 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            if (get != null) {
                for (Parameter param : get.getParameters()) {
                    final String description = param.getDescription();
                    if (StringUtils.isNotBlank(description)) {
                        assertFalse(description.startsWith("secret"));
                    }
                }
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) RemoveInternalParamsFilter(io.swagger.v3.core.filter.resources.RemoveInternalParamsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 99 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class SpecFilterTest method assertOperations.

private void assertOperations(OpenAPI filtered, String operationId, String description) {
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            Operation get = entry.getValue().getGet();
            if (get != null) {
                assertEquals(get.getOperationId(), operationId);
                assertEquals(get.getDescription(), description);
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Operation(io.swagger.v3.oas.models.Operation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 100 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwayGetOperations.

@Test(description = "it should filter away get operations in a resource")
public void filterAwayGetOperations() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final NoGetOperationsFilter filter = new NoGetOperationsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            assertNull(entry.getValue().getGet());
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) NoGetOperationsFilter(io.swagger.v3.core.filter.resources.NoGetOperationsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)154 OpenAPI (io.swagger.v3.oas.models.OpenAPI)145 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)75 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)70 PathItem (io.swagger.v3.oas.models.PathItem)61 Operation (io.swagger.v3.oas.models.Operation)46 Paths (io.swagger.v3.oas.models.Paths)45 Schema (io.swagger.v3.oas.models.media.Schema)40 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)36 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)33 Components (io.swagger.v3.oas.models.Components)32 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)27 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)25 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)23 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 Info (io.swagger.v3.oas.models.info.Info)21 MapSchema (io.swagger.v3.oas.models.media.MapSchema)21 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)21 DateSchema (io.swagger.v3.oas.models.media.DateSchema)19