Search in sources :

Example 51 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testResolveFullyExample.

@Test
public void testResolveFullyExample() throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, new ArrayList<>(), options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    Components components = result.getOpenAPI().getComponents();
    ApiResponse response = result.getOpenAPI().getPaths().get("/mockResponses/objectMultipleExamples").getGet().getResponses().get("200");
    assertEquals(response.getContent().get("application/json").getExamples().get("ArthurDent"), components.getExamples().get("Arthur"));
    assertEquals(response.getContent().get("application/xml").getExamples().get("Trillian"), components.getExamples().get("Trillian"));
}
Also used : Components(io.swagger.v3.oas.models.Components) 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) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 52 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testResolveFullyMap.

@Test
public void testResolveFullyMap() {
    ParseOptions options = new ParseOptions();
    options.setResolveFully(false);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
    String yaml = Yaml.pretty(openAPI);
    assertTrue(yaml.contains("$ref"));
    options = new ParseOptions();
    options.setResolveFully(true);
    openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
    yaml = Yaml.pretty(openAPI);
    assertFalse(yaml.contains("$ref"));
}
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 53 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method checkAllOfWithRelativeReferencesAreFound.

@Test(description = "Issue #616 Relative references inside of 'allOf'")
public void checkAllOfWithRelativeReferencesAreFound() {
    OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/allOf-relative-file-references/parent.yaml");
    assertEquals(4, openAPI.getComponents().getSchemas().size());
}
Also used : OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 54 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testIssue1309.

@Test
public void testIssue1309() {
    OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult parseResult = openApiParser.readLocation("issue-1309.yaml", null, options);
    OpenAPI openAPI = parseResult.getOpenAPI();
    assertNotNull(openAPI);
    assertEquals(parseResult.getMessages().get(0), "attribute components.schemas.customer-not-found.examples is unexpected");
}
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 55 with OpenAPIV3Parser

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

the class OpenAPIV3ParserTest method testIssue1039.

@Test
public void testIssue1039() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue_1039.yaml", null, options);
    OpenAPI apispec = parseResult.getOpenAPI();
    assertNotNull(apispec);
    assertEquals(apispec.getPaths().get("/pets").getGet().getParameters().get(0).getSchema().getType(), "array");
}
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)

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