@Test public void convertingToJsonShouldNotLooseSecurityDefinitions() throws IOException { final String definition = "{\"swagger\":\"2.0\",\"securityDefinitions\": {\n" + " \"api-key-header\": {\n" + " \"type\": \"apiKey\",\n" + " \"name\": \"API-KEY\",\n" + " \"in\": \"header\"\n" + " },\n" + " \"api-key-parameter\": {\n" + " \"type\": \"apiKey\",\n" + " \"name\": \"api_key\",\n" + " \"in\": \"query\"\n" + " }\n" + " }}"; final JsonNode node = OpenApiModelParser.convertToJson(definition); final JsonNode securityDefinitions = node.get("securityDefinitions"); assertThat(securityDefinitions.get("api-key-header")).isEqualTo(newNode() .put("type", "apiKey") .put("name", "API-KEY") .put("in", "header")); assertThat(securityDefinitions.get("api-key-parameter")).isEqualTo(newNode() .put("type", "apiKey") .put("name", "api_key") .put("in", "query")); }
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);  }