Search in sources :

Example 96 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method resolveComposedSchema.

@Test
public void resolveComposedSchema(@Injectable final List<AuthorizationValue> auths) {
    ParseOptions options = new ParseOptions();
    options.setResolveCombinators(false);
    options.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/oneof-anyof.yaml", auths, options).getOpenAPI();
    assertTrue(openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ArraySchema);
    ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/mixed-array").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
    assertTrue(arraySchema.getItems() instanceof ComposedSchema);
    ComposedSchema oneOf = (ComposedSchema) arraySchema.getItems();
    assertEquals(oneOf.getOneOf().get(0).getType(), "string");
    // System.out.println(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() );
    assertTrue(openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ComposedSchema);
    ComposedSchema oneOfSchema = (ComposedSchema) openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
    assertEquals(oneOfSchema.getOneOf().get(0).getType(), "object");
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) 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 97 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testIssue1157.

@Test
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    OpenAPI openAPIAnyOf = new OpenAPIV3Parser().readLocation("/issue-1157/anyOf-example.yaml", auths, options).getOpenAPI();
    Schema petSchemaAnyOf = openAPIAnyOf.getComponents().getSchemas().get("Pet");
    assertTrue(petSchemaAnyOf instanceof ComposedSchema);
    assertTrue(((ComposedSchema) petSchemaAnyOf).getAnyOf() != null);
    OpenAPI openAPIOneOf = new OpenAPIV3Parser().readLocation("/issue-1157/oneOf-example.yaml", auths, options).getOpenAPI();
    Schema petSchemaOneOf = openAPIOneOf.getComponents().getSchemas().get("Pet");
    assertTrue(petSchemaOneOf instanceof ComposedSchema);
    assertTrue(((ComposedSchema) petSchemaOneOf).getOneOf() != null);
    OpenAPI openAPIAllOf = new OpenAPIV3Parser().readLocation("/issue-1157/allOf-example.yaml", auths, options).getOpenAPI();
    Schema petSchemaAllOf = openAPIAllOf.getComponents().getSchemas().get("Pet");
    assertFalse(petSchemaAllOf instanceof ComposedSchema);
    assertTrue(petSchemaAllOf.getProperties() != null);
}
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) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 98 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testSettingsAddParametersToEachOperationDisabled.

@Test
public void testSettingsAddParametersToEachOperationDisabled() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  title: test spec\n" + "  version: '1.0'\n" + "paths:\n" + "  '/test/{id}':\n" + "    parameters:\n" + "      - name: id\n" + "        in: path\n" + "        required: true\n" + "        schema:\n" + "          type: string\n" + "    get:\n" + "      description: test get\n" + "      parameters:\n" + "        - name: page\n" + "          in: query\n" + "          schema:\n" + "            type: string\n" + "      responses:\n" + "        default:\n" + "          description: test response";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI swagger = result.getOpenAPI();
    final OpenAPI resolved = new OpenAPIResolver(swagger, null, null, new OpenAPIResolver.Settings().addParametersToEachOperation(false)).resolve();
    assertEquals(resolved.getPaths().get("/test/{id}").getParameters().size(), 1);
    PathParameter pp = (PathParameter) resolved.getPaths().get("/test/{id}").getParameters().get(0);
    assertEquals(pp.getName(), "id");
    assertEquals(resolved.getPaths().get("/test/{id}").getGet().getParameters().size(), 1);
    QueryParameter qp = (QueryParameter) resolved.getPaths().get("/test/{id}").getGet().getParameters().get(0);
    assertEquals(qp.getName(), "page");
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) 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 99 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class FileReferenceTest method testIssue340.

@Test
public void testIssue340() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-340.json", null, options);
    assertNotNull(result.getOpenAPI());
    OpenAPI swagger = result.getOpenAPI();
    assertFalse(swagger.getComponents().getSchemas().get("BarData").get$ref() != null);
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 100 with OpenAPIV3Parser

use of io.swagger.v3.parser.OpenAPIV3Parser in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testTroublesomeFile.

@Test
public void testTroublesomeFile() throws Exception {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    final OpenAPI openAPI = parser.read("src/test/resources/troublesome.yaml");
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)295 Test (org.testng.annotations.Test)279 OpenAPI (io.swagger.v3.oas.models.OpenAPI)219 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)184 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)169 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)83 Schema (io.swagger.v3.oas.models.media.Schema)83 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)80 StringSchema (io.swagger.v3.oas.models.media.StringSchema)77 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)76 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)75 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)66 MapSchema (io.swagger.v3.oas.models.media.MapSchema)63 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)25 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)25 DateSchema (io.swagger.v3.oas.models.media.DateSchema)24 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)24 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 HashSet (java.util.HashSet)22 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)17