Search in sources :

Example 16 with Paths

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

the class ReaderTest method testSecuritySchemeWithRef.

@Test(description = "SecurityScheme with REf")
public void testSecuritySchemeWithRef() {
    Components components = new Components();
    components.addSecuritySchemes("Security", new SecurityScheme().description("Security Example").name("Security").type(SecurityScheme.Type.OAUTH2).$ref("myOauth2Security").in(SecurityScheme.In.HEADER));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefSecurityResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      description: description\n" + "      operationId: Operation Id\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      security:\n" + "      - security_key:\n" + "        - write:pets\n" + "        - read:pets\n" + "components:\n" + "  securitySchemes:\n" + "    Security:\n" + "      type: oauth2\n" + "      description: Security Example\n" + "    myOauth2Security:\n" + "      type: oauth2\n" + "      description: myOauthSecurity Description\n" + "      $ref: '#/components/securitySchemes/Security'\n" + "      in: header\n" + "      flows:\n" + "        implicit:\n" + "          authorizationUrl: http://x.com\n" + "          scopes:\n" + "            write:pets: modify pets in your account\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 17 with Paths

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

the class ReaderTest method test2644.

@Test(description = "test ticket #2644 annotated interface")
public void test2644() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2644ConcreteImplementation.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 1);
    PathItem pathItem = paths.get("/resources");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 18 with Paths

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

the class ReaderTest method testResponseWithFilter.

@Test(description = "Responses with filter")
public void testResponseWithFilter() {
    Components components = new Components();
    components.addResponses("invalidJWT", new ApiResponse().description("when JWT token invalid/expired"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(SimpleResponsesResource.class);
    OpenAPISpecFilter filterImpl = new RefResponseFilter();
    SpecFilter f = new SpecFilter();
    openAPI = f.filter(openAPI, filterImpl, null, null, null);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with no inputs and a complex output\n" + "        object\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/SampleResponseSchema'\n" + "        default:\n" + "          description: boo\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/GenericError'\n" + "        \"401\":\n" + "          $ref: '#/components/responses/invalidJWT'\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    GenericError:\n" + "      type: object\n" + "    SampleResponseSchema:\n" + "      type: object\n" + "  responses:\n" + "    invalidJWT:\n" + "      description: when JWT token invalid/expired";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) AbstractSpecFilter(io.swagger.v3.core.filter.AbstractSpecFilter) OpenAPISpecFilter(io.swagger.v3.core.filter.OpenAPISpecFilter) SpecFilter(io.swagger.v3.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 19 with Paths

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

the class ReaderTest method testTicket2340.

@Test(description = "Responses with array schema")
public void testTicket2340() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2340Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/test:\n" + "    post:\n" + "      operationId: getAnimal\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/Animal'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                type: string\n" + "components:\n" + "  schemas:\n" + "    Animal:\n" + "      required:\n" + "      - type\n" + "      type: object\n" + "      properties:\n" + "        type:\n" + "          type: string\n" + "      discriminator:\n" + "        propertyName: type\n" + "    Cat:\n" + "      type: object\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Animal'\n" + "      - type: object\n" + "        properties:\n" + "          lives:\n" + "            type: integer\n" + "            format: int32\n" + "    Dog:\n" + "      type: object\n" + "      allOf:\n" + "      - $ref: '#/components/schemas/Animal'\n" + "      - type: object\n" + "        properties:\n" + "          barkVolume:\n" + "            type: number\n" + "            format: double\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 20 with Paths

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

the class ReaderTest method testTicket3587.

@Test(description = "Parameter examples ordering")
public void testTicket3587() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3587Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /test/test:\n" + "    get:\n" + "      operationId: parameterExamplesOrderingTest\n" + "      parameters:\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example One:\n" + "            description: Example One\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example Three:\n" + "            description: Example Three\n" + "      - in: query\n" + "        schema:\n" + "          type: string\n" + "        examples:\n" + "          Example Three:\n" + "            description: Example Three\n" + "          Example Two:\n" + "            description: Example Two\n" + "          Example One:\n" + "            description: Example One\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYamlExact(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) 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