Search in sources :

Example 66 with Pet

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

the class OpenAPIV3ParserTest method testOneOfExternalRefConflictName.

@Test
public void testOneOfExternalRefConflictName() throws Exception {
    OpenAPI openAPI = new OpenAPIV3Parser().read("./oneof_name_conflict/oneOf-external-ref-name-conflict.yaml");
    Assert.assertNotNull(openAPI);
    Schema pet = openAPI.getComponents().getSchemas().get("Pet");
    Assert.assertNotNull(pet);
    Assert.assertTrue(pet.getDiscriminator().getMapping().containsKey("Cat"));
    Assert.assertTrue(pet.getDiscriminator().getMapping().get("Cat").equals("#/components/schemas/Cat_1"));
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 67 with Pet

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

the class OpenAPIV3ParserTest method testComposedRefResolvingIssue628.

@Test
public void testComposedRefResolvingIssue628(@Injectable final List<AuthorizationValue> auths) throws Exception {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/composedSchemaRef.yaml", auths, options);
    Assert.assertNotNull(openAPI);
    Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 5);
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("Cat"));
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("Dog"));
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("Pet"));
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("Lion"));
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("Bear"));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 68 with Pet

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

the class OpenAPIV3ParserTest method testIssue594.

@Test
public void testIssue594() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + "  /test:\n" + "    post:\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              minItems: 1\n" + "              maxItems: 1\n" + "              items:\n" + "                $ref: \"#/components/schemas/Pet\"\n" + "        description: Hello world\n" + "info:\n" + "  version: ''\n" + "  title: ''";
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
    assertNotNull(result.getOpenAPI());
    ArraySchema schema = (ArraySchema) (result.getOpenAPI().getPaths().get("/test").getPost().getRequestBody().getContent().get("application/json").getSchema());
    assertEquals(schema.getItems().get$ref(), "#/components/schemas/Pet");
    assertNotNull(schema.getMaxItems());
    assertNotNull(schema.getMinItems());
}
Also used : ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 69 with Pet

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

the class OpenAPIV3ParserTest method testParameterRequired.

@Test(description = "Test (path & form) parameter's required attribute")
public void testParameterRequired() {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    final OpenAPI openAPI = parser.read("src/test/resources/petstore.yaml");
    final List<Parameter> operationParams = openAPI.getPaths().get("/pet/{petId}").getPost().getParameters();
    final PathParameter pathParameter = (PathParameter) operationParams.get(0);
    Assert.assertTrue(pathParameter.getRequired());
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 70 with Pet

use of io.swagger.v3.jaxrs2.resources.model.Pet 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)

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