Search in sources :

Example 86 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testIssueSameRefsDifferentModel.

@Test
public void testIssueSameRefsDifferentModel() throws IOException {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model-domain.yaml"), "UTF-8");
    WireMock.stubFor(get(urlPathMatching("/issue-domain")).willReturn(aResponse().withStatus(HttpURLConnection.HTTP_OK).withHeader("Content-type", "application/json").withBody(pathFile.getBytes(StandardCharsets.UTF_8))));
    pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model.yaml"), "UTF-8");
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    options.setResolveFully(true);
    final SwaggerParseResult openAPI = parser.readContents(pathFile, null, options);
    Yaml.prettyPrint(openAPI);
    assertEquals(openAPI.getMessages().size(), 0);
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) Test(org.testng.annotations.Test)

Example 87 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testResolveEmpty.

@Test
public void testResolveEmpty(@Injectable final List<AuthorizationValue> auths) throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/empty-oas.yaml"));
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
}
Also used : ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) Test(org.testng.annotations.Test)

Example 88 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testIssue357.

@Test
public void testIssue357() {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    final OpenAPI openAPI = parser.read("src/test/resources/issue_357.yaml");
    assertNotNull(openAPI);
    List<Parameter> getParams = openAPI.getPaths().get("/testApi").getGet().getParameters();
    assertEquals(2, getParams.size());
    for (Parameter param : getParams) {
        switch(param.getName()) {
            case "pathParam1":
                assertEquals(param.getSchema().getType(), "integer");
                break;
            case "pathParam2":
                assertEquals(param.getSchema().getType(), "string");
                break;
            default:
                fail("Unexpected parameter named " + param.getName());
                break;
        }
    }
}
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) Test(org.testng.annotations.Test)

Example 89 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testIssue913.

@Test
public void testIssue913() {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    final OpenAPI openAPI = parser.readLocation("issue-913/BS/ApiSpecification.yaml", null, options).getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertNotNull(openAPI.getComponents().getSchemas().get("indicatorType"));
    Assert.assertEquals(openAPI.getComponents().getSchemas().get("indicatorType").getProperties().size(), 1);
}
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 90 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testDiscriminatorSameFileExternalMapping.

@Test
public void testDiscriminatorSameFileExternalMapping() throws Exception {
    OpenAPI openAPI = new OpenAPIV3Parser().read("./discriminator-mapping-resolution/main-external-mapping.yaml");
    Assert.assertNotNull(openAPI);
    Schema cat = openAPI.getComponents().getSchemas().get("Cat");
    Assert.assertNotNull(cat);
}
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)

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