use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue.
@Test
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
options.setFlattenComposedSchemas(true);
options.setCamelCaseFlattenNaming(true);
SwaggerParseResult parseResult = openApiParser.readLocation("additionalPropertiesFlatten.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
// responses
assertNotNull(openAPI.getComponents().getSchemas().get("InlineResponseMap200"));
assertEquals(((ComposedSchema) openAPI.getComponents().getSchemas().get("InlineResponseMap200")).getOneOf().get(0).get$ref(), "#/components/schemas/Macaw1");
assertNotNull(openAPI.getComponents().getSchemas().get("InlineResponseMapItems404"));
assertEquals(((ComposedSchema) openAPI.getComponents().getSchemas().get("InlineResponseMapItems404")).getAnyOf().get(0).get$ref(), "#/components/schemas/Macaw2");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testEmptyQueryParameterExample.
@Test
public void testEmptyQueryParameterExample() {
final ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/emptyQueryParameter.yaml", null, options);
assertEquals("", result.getOpenAPI().getPaths().get("/foo").getGet().getParameters().get(0).getExample());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method issue1455_testResolveFullyV2_shouldNotThrowNPE.
@Test
public void issue1455_testResolveFullyV2_shouldNotThrowNPE() throws Exception {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/swagger.json"));
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.assertNull(result.getOpenAPI());
Assert.assertNotNull(result.getMessages());
Assert.assertEquals(result.getMessages().size(), 1);
Assert.assertEquals(result.getMessages().get(0), "attribute openapi is missing");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testDeserializeExampleFlag.
@Test
public void testDeserializeExampleFlag() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(true);
options.setResolveFully(true);
options.setFlatten(true);
SwaggerParseResult parseResult = openApiParser.readLocation("exampleFlag.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertTrue(openAPI.getComponents().getSchemas().get("TestDTO").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestDTO").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("TestString").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestString").getExample());
assertTrue(openAPI.getComponents().getSchemas().get("TestNumber").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestNumber").getExample());
assertFalse(openAPI.getComponents().getSchemas().get("TestDTOMissing").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestDTOMissing").getExample());
assertFalse(openAPI.getComponents().getSchemas().get("TestStringMissing").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestStringMissing").getExample());
assertFalse(openAPI.getComponents().getSchemas().get("TestNumberMissing").getExampleSetFlag());
assertNull(openAPI.getComponents().getSchemas().get("TestNumberMissing").getExample());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue811.
@Test
public void testIssue811() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
final OpenAPI openAPI = new OpenAPIV3Parser().readLocation("oapi-reference-test/index.yaml", null, options).getOpenAPI();
Assert.assertNotNull(openAPI);
Assert.assertEquals(openAPI.getPaths().get("/").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/schema-with-reference");
}
Aggregations