use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class AnchorTest method testBillionLaughProtectionSnakeYaml.
@Test
public void testBillionLaughProtectionSnakeYaml() {
ParseOptions opts = new ParseOptions();
opts.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("billion_laughs_snake_yaml.yaml", null, opts);
assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("a1"));
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("a1").getEnum().get(0), "AA1");
assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("c1"));
assertEquals(((Schema) result.getOpenAPI().getComponents().getSchemas().get("c1").getProperties().get("a")).getEnum().get(0), "AA1");
DeserializationUtils.getOptions().setMaxYamlAliasesForCollections(50);
DeserializationUtils.getOptions().setYamlAllowRecursiveKeys(false);
result = new OpenAPIV3Parser().readLocation("billion_laughs_snake_yaml.yaml", null, opts);
DeserializationUtils.getOptions().setMaxYamlAliasesForCollections(Integer.MAX_VALUE);
DeserializationUtils.getOptions().setYamlAllowRecursiveKeys(true);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testIssue411.
@Test
public void testIssue411() throws Exception {
final List<AuthorizationValue> auths = new ArrayList<>();
AuthorizationValue auth = new AuthorizationValue("Authorization", "OMG_SO_SEKR3T", "header");
auths.add(auth);
new Expectations() {
{
remoteUrl.urlToString("http://remote1/resources/swagger.yaml", auths);
result = issue_411_server;
remoteUrl.urlToString("http://remote2/resources/foo", auths);
result = issue_411_components;
}
};
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("http://remote1/resources/swagger.yaml", auths, options);
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/health"));
PathItem health = swagger.getPaths().get("/health");
assertTrue(health.getGet().getParameters().size() == 0);
Schema responseRef = health.getGet().getResponses().get("200").getContent().get("*/*").getSchema();
assertTrue(responseRef.get$ref() != null);
assertEquals(responseRef.get$ref(), "#/components/schemas/Success");
assertNotNull(swagger.getComponents().getSchemas().get("Success"));
Parameter param = swagger.getPaths().get("/stuff").getGet().getParameters().get(0);
assertEquals(param.getIn(), "query");
assertEquals(param.getName(), "skip");
ApiResponse response = swagger.getPaths().get("/stuff").getGet().getResponses().get("200");
assertNotNull(response);
assertTrue(response.getContent().get("*/*").getSchema() instanceof StringSchema);
ApiResponse error = swagger.getPaths().get("/stuff").getGet().getResponses().get("400");
assertNotNull(error);
Schema errorProp = error.getContent().get("*/*").getSchema();
assertNotNull(errorProp);
assertTrue(errorProp.get$ref() != null);
assertEquals(errorProp.get$ref(), "#/components/schemas/Error");
assertTrue(swagger.getComponents().getSchemas().get("Error") instanceof Schema);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue316.
@Test
public void testIssue316() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-316.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/events"));
PathItem path = swagger.getPaths().get("/events");
assertNotNull(path.getGet());
Operation get = path.getGet();
assertEquals(get.getOperationId(), "getEvents");
assertTrue(swagger.getComponents().getSchemas().size() == 3);
assertTrue(swagger.getComponents().getSchemas().get("Foobar").getProperties().size() == 1);
assertTrue(swagger.getComponents().getSchemas().get("StatusResponse").getProperties().size() == 1);
assertTrue(swagger.getComponents().getSchemas().get("Paging2").getProperties().size() == 2);
Schema model = swagger.getComponents().getSchemas().get("Paging2");
Schema property = (Schema) model.getProperties().get("foobar");
assertTrue(property.get$ref() != null);
assertEquals(property.get$ref(), "#/components/schemas/Foobar");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class FileReferenceTest method testRelativeRefIssue421.
@Test
public void testRelativeRefIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/main.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger);
assertNotNull(swagger.getPaths().get("pets"));
assertNotNull(swagger.getPaths().get("pets").getGet());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses());
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200"));
assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema());
assertTrue(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref() != null);
assertEquals(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/Pet");
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 2);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class FileReferenceTest method testIssue421.
@Test
public void testIssue421() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-421.yaml", null, options);
assertNotNull(result.getOpenAPI());
OpenAPI swagger = result.getOpenAPI();
assertNotNull(swagger.getPaths().get("/pet/{petId}"));
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 6);
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost());
assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost().getParameters());
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getParameters().size() == 1);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody() != null);
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref() != null);
assertEquals(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref(), "#/components/requestBodies/requestBody");
assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref().equals("#/components/requestBodies/requestBody"));
assertNotNull(swagger.getPaths().get("/store/order"));
assertNotNull(swagger.getPaths().get("/store/order").getPost());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody());
assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema());
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref() != null);
assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref().equals("#/components/schemas/Order"));
assertTrue(swagger.getComponents().getSchemas().get("Order") instanceof Schema);
assertTrue(swagger.getComponents().getSchemas().get("Order").getProperties().size() == 6);
}
Aggregations