@Test public void convertingToJsonShouldNotLooseSecurityRequirements() throws IOException { final String definition = "{\"swagger\":\"2.0\",\"paths\":{\"/api\":{\"get\":{\"security\":[{\"secured\":[\"scope\"]}]}}}}"; final JsonNode node = OpenApiModelParser.convertToJson(definition); assertThat(node.get("paths").get("/api").get("get").get("security")) .hasOnlyOneElementSatisfying(securityRequirement -> assertThat(securityRequirement.get("secured")) .hasOnlyOneElementSatisfying(scope -> assertThat(scope.asText()).isEqualTo("scope"))); }
static JsonNode convertToJson(final String specification) throws IOException { final JsonNode specRoot; if (isJsonSpec(specification)) { specRoot = JsonUtils.reader().readTree(specification); } else { specRoot = JsonUtils.convertValue(YAML_PARSER.load(specification), JsonNode.class); } return specRoot; }
OpenApiModelParser { static JsonNode convertToJson(final String specification) throws IOException { final JsonNode specRoot; if (isJsonSpec(specification)) { specRoot = JsonUtils.reader().readTree(specification); } else { specRoot = JsonUtils.convertValue(YAML_PARSER.load(specification), JsonNode.class); } return specRoot; } }
OpenApiModelParser { static JsonNode convertToJson(final String specification) throws IOException { final JsonNode specRoot; if (isJsonSpec(specification)) { specRoot = JsonUtils.reader().readTree(specification); } else { specRoot = JsonUtils.convertValue(YAML_PARSER.load(specification), JsonNode.class); } return specRoot; } private  OpenApiModelParser(); }
OpenApiModelParser { static JsonNode convertToJson(final String specification) throws IOException { final JsonNode specRoot; if (isJsonSpec(specification)) { specRoot = JsonUtils.reader().readTree(specification); } else { specRoot = JsonUtils.convertValue(YAML_PARSER.load(specification), JsonNode.class); } return specRoot; } private  OpenApiModelParser(); static OpenApiModelInfo parse(final String specification, final APIValidationContext validationContext); static boolean isJsonSpec(final String specification); static String resolve(URL url); }
OpenApiModelParser { static JsonNode convertToJson(final String specification) throws IOException { final JsonNode specRoot; if (isJsonSpec(specification)) { specRoot = JsonUtils.reader().readTree(specification); } else { specRoot = JsonUtils.convertValue(YAML_PARSER.load(specification), JsonNode.class); } return specRoot; } private  OpenApiModelParser(); static OpenApiModelInfo parse(final String specification, final APIValidationContext validationContext); static boolean isJsonSpec(final String specification); static String resolve(URL url);  }