Search in sources :

Example 81 with ParseOptions

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

the class OpenAPIV3ParserTest method checkPathParameterRequiredValue.

@Test
public void checkPathParameterRequiredValue() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation("src/test/resources/issue-1319.yaml", null, options);
    assertEquals(2, swaggerParseResult.getMessages().size());
    assertEquals(2, swaggerParseResult.getOpenAPI().getComponents().getSchemas().size());
    assertEquals(2, swaggerParseResult.getOpenAPI().getPaths().size());
    assertEquals(1, swaggerParseResult.getOpenAPI().getComponents().getParameters().size());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) Test(org.testng.annotations.Test)

Example 82 with ParseOptions

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

the class OpenAPIV3ParserTest method testIssue719.

@Test
public void testIssue719() {
    final OpenAPI openAPI = new OpenAPIV3Parser().readLocation("extensions-responses.yaml", null, new ParseOptions()).getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertNotNull(openAPI.getPaths().getExtensions());
    Assert.assertNotNull(openAPI.getPaths().get("/something").getGet().getResponses().getExtensions());
}
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 83 with ParseOptions

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

the class OpenAPIV3ParserTest method testIssue1071True.

@Test
public void testIssue1071True() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1071-true.yaml", null, options);
    OpenAPI apispec = parseResult.getOpenAPI();
    assertNotNull(apispec);
    Schema test = apispec.getPaths().get("/mapschema").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
    assertTrue(test instanceof MapSchema);
    assertTrue(test.getAdditionalProperties() instanceof Boolean);
    assertTrue((Boolean) test.getAdditionalProperties());
}
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) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) MapSchema(io.swagger.v3.oas.models.media.MapSchema) 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 84 with ParseOptions

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

the class OpenAPIV3ParserTest method testLinkIssue.

@Test
public void testLinkIssue() {
    ParseOptions parseOptions = new ParseOptions();
    parseOptions.setResolveFully(true);
    OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/linkIssue.yaml", null, parseOptions);
    Map<String, Link> links = openAPI.getPaths().get("/2.0/repositories/{username}").getGet().getResponses().get("200").getLinks();
    Object requestBody = links.get("userRepository").getRequestBody();
    assertEquals(requestBody, "$response.body#/slug");
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 85 with ParseOptions

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

the class OpenAPIV3ParserTest method testComposedSchemaAdjacent.

@Test
public void testComposedSchemaAdjacent(@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);
    Schema schema = openAPI.getPaths().get("/path").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
    Assert.assertTrue(schema instanceof ComposedSchema);
    ComposedSchema composedSchema = (ComposedSchema) schema;
    Assert.assertTrue(composedSchema.getOneOf().size() == 2);
    Assert.assertTrue(composedSchema.getAllOf().size() == 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) 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)

Aggregations

ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)202 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)172 Test (org.testng.annotations.Test)166 OpenAPI (io.swagger.v3.oas.models.OpenAPI)144 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)140 Schema (io.swagger.v3.oas.models.media.Schema)52 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)46 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)44 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)40 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)36 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)25 MapSchema (io.swagger.v3.oas.models.media.MapSchema)23 Test (org.junit.Test)20 File (java.io.File)12 Parameter (io.swagger.v3.oas.models.parameters.Parameter)11 Expectations (mockit.Expectations)11 HashSet (java.util.HashSet)10 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)9 PathItem (io.swagger.v3.oas.models.PathItem)8