Search in sources :

Example 46 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testShellMethod.

@Test
public void testShellMethod(@Injectable final List<AuthorizationValue> auths) {
    String url = "http://localhost:${dynamicPort}/remote/spec";
    url = url.replace("${dynamicPort}", String.valueOf(this.serverPort));
    OpenAPI openAPI = new OpenAPIV3Parser().read(url);
    Assert.assertNotNull(openAPI);
    assertEquals(openAPI.getOpenapi(), "3.0.1");
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 47 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testSelfReferenceResolution.

@Test
public void testSelfReferenceResolution(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + "  \"/selfRefB\":\n" + "    get:\n" + "      requestBody:\n" + "        description: user to add to the system\\n\"+\n" + "        content:\n" + "         'application/json':\n" + "             schema:\n" + "                $ref: '#/components/schemas/SchemaB'\n" + "components:\n" + "  schemas:\n" + "    SchemaA:\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        modelB:\n" + "          $ref: '#/components/schemas/SchemaB'\n" + "    SchemaB:\n" + "      properties:\n" + "        modelB:\n" + "          $ref: '#/components/schemas/SchemaB'";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
    ResolverFully resolverUtil = new ResolverFully();
    resolverUtil.resolveFully(openAPI);
    RequestBody body = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody();
    Schema schema = body.getContent().get("application/json").getSchema();
    assertEquals(schema, openAPI.getComponents().getSchemas().get("SchemaB"));
}
Also used : ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) 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) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ResolverFully(io.swagger.v3.parser.util.ResolverFully) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 48 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method selfReferenceTest.

@Test
public void selfReferenceTest(@Injectable final List<AuthorizationValue> auths) {
    String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + "  /selfRefA:\n" + "    get:\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/ModelA'\n" + "      responses:\n" + "        default:\n" + "          description: Default response\n" + "  /selfRefB:\n" + "    get:\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/ModelB'\n" + "      responses:\n" + "        default:\n" + "          description: Default response\n" + "  /selfRefC:\n" + "    get:\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              $ref: '#/components/schemas/ModelC'\n" + "      responses:\n" + "        default:\n" + "          description: Default response\n" + "  /selfRefD:\n" + "    get:\n" + "      responses:\n" + "        default:\n" + "          description: Default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/ModelA'\n" + "  /selfRefE:\n" + "    get:\n" + "      responses:\n" + "        default:\n" + "          description: Default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: array\n" + "                items:\n" + "                  $ref: '#/components/schemas/ModelA'\n" + "info:\n" + "  version: ''\n" + "  title: ''\n" + "components:\n" + "  schemas:\n" + "    ModelA:\n" + "      properties:\n" + "        modelB:\n" + "          $ref: '#/components/schemas/ModelB'\n" + "    ModelB:\n" + "      properties:\n" + "        modelB:\n" + "          $ref: '#/components/schemas/ModelB'\n" + "    ModelC:\n" + "      properties:\n" + "        modelA:\n" + "          $ref: '#/components/schemas/ModelA'";
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
    Schema schemaB = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody().getContent().get("application/json").getSchema();
    assertTrue(schemaB instanceof Schema);
    assertEquals(openAPI.getComponents().getSchemas().get("ModelB"), schemaB);
    Schema schema = openAPI.getPaths().get("/selfRefE").getGet().getResponses().get("default").getContent().get("*/*").getSchema();
    assertTrue(schema instanceof ArraySchema);
    ArraySchema arraySchema = (ArraySchema) schema;
    assertEquals(openAPI.getComponents().getSchemas().get("ModelA"), arraySchema.getItems());
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) 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) 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 49 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method resolveAllOfWithoutAggregatingParameters.

@Test
public void resolveAllOfWithoutAggregatingParameters(@Injectable final List<AuthorizationValue> auths) {
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    options.setResolveCombinators(false);
    // Testing components/schemas
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/composed.yaml", auths, options).getOpenAPI();
    ComposedSchema allOf = (ComposedSchema) openAPI.getComponents().getSchemas().get("ExtendedAddress");
    assertEquals(allOf.getAllOf().size(), 2);
    assertTrue(allOf.getAllOf().get(0).getProperties().containsKey("street"));
    assertTrue(allOf.getAllOf().get(1).getProperties().containsKey("gps"));
    // Testing path item
    ComposedSchema schema = (ComposedSchema) openAPI.getPaths().get("/withInvalidComposedModel").getPost().getRequestBody().getContent().get("application/json").getSchema();
    // In fact the schema resolved previously is the same of /withInvalidComposedModel
    assertEquals(schema, allOf);
    assertEquals(schema.getAllOf().size(), 2);
    assertTrue(schema.getAllOf().get(0).getProperties().containsKey("street"));
    assertTrue(schema.getAllOf().get(1).getProperties().containsKey("gps"));
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 50 with AuthorizationValue

use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method resolveComposedReferenceAllOfSchema.

@Test
public void resolveComposedReferenceAllOfSchema(@Injectable final List<AuthorizationValue> auths) {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/composed.yaml", auths, options).getOpenAPI();
    assertTrue(openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof ArraySchema);
    ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("application/json").getSchema();
    assertTrue(arraySchema.getItems() instanceof ObjectSchema);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) 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)

Aggregations

Test (org.testng.annotations.Test)44 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)40 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)34 OpenAPI (io.swagger.v3.oas.models.OpenAPI)31 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)21 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)18 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)18 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)17 Schema (io.swagger.v3.oas.models.media.Schema)17 StringSchema (io.swagger.v3.oas.models.media.StringSchema)17 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)16 AuthorizationValue (io.swagger.v3.parser.core.models.AuthorizationValue)13 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)8 MapSchema (io.swagger.v3.oas.models.media.MapSchema)8 HashSet (java.util.HashSet)7 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)5 DateSchema (io.swagger.v3.oas.models.media.DateSchema)5 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)5 ArrayList (java.util.ArrayList)5 Expectations (mockit.Expectations)5