use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class Swagger20Parser method convertToSwagger.
private Swagger convertToSwagger(String data) throws IOException {
if (data != null) {
JsonNode rootNode;
if (data.trim().startsWith("{")) {
ObjectMapper mapper = Json.mapper();
rootNode = mapper.readTree(data);
} else {
rootNode = DeserializationUtils.readYamlTree(data);
}
if (System.getProperty("debugParser") != null) {
LOGGER.info("\n\nSwagger Tree: \n" + ReflectionToStringBuilder.toString(rootNode, ToStringStyle.MULTI_LINE_STYLE) + "\n\n");
}
if (rootNode == null) {
return null;
}
// must have swagger node set
JsonNode swaggerNode = rootNode.get("swagger");
if (swaggerNode == null) {
return null;
} else {
SwaggerDeserializationResult result = new SwaggerDeserializer().deserialize(rootNode);
Swagger convertValue = result.getSwagger();
if (System.getProperty("debugParser") != null) {
LOGGER.info("\n\nSwagger Tree convertValue : \n" + ReflectionToStringBuilder.toString(convertValue, ToStringStyle.MULTI_LINE_STYLE) + "\n\n");
}
return convertValue;
}
} else {
return null;
}
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParser method readWithInfo.
public SwaggerDeserializationResult readWithInfo(String location, List<AuthorizationValue> auths, boolean resolve) {
if (location == null) {
return null;
}
location = location.replaceAll("\\\\", "/");
List<SwaggerParserExtension> parserExtensions = getExtensions();
SwaggerDeserializationResult output;
if (auths == null) {
auths = new ArrayList<AuthorizationValue>();
}
output = new Swagger20Parser().readWithInfo(location, auths);
if (output != null) {
if (output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
if (resolve) {
output.setSwagger(new SwaggerResolver(output.getSwagger(), auths, location).resolve());
}
return output;
}
}
for (SwaggerParserExtension extension : parserExtensions) {
output = extension.readWithInfo(location, auths);
if (output != null && output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
return output;
}
}
if (output == null) {
output = new SwaggerDeserializationResult().message("The swagger definition could not be read");
}
return output;
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue323.
@Test
public void testIssue323() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-323.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/events"));
assertNotNull(swagger.getDefinitions().get("StatusResponse"));
assertNotNull(swagger.getDefinitions().get("Paging"));
assertNotNull(swagger.getDefinitions().get("Foobar"));
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue421.
@Test
public void testIssue421() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-421.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/pet/{petId}"));
assertNotNull(swagger.getPath("/pet/{petId}").getGet());
assertNotNull(swagger.getPath("/pet/{petId}").getGet().getParameters());
assertTrue(swagger.getPath("/pet/{petId}").getGet().getParameters().size() == 1);
assertTrue(swagger.getPath("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
assertTrue(swagger.getDefinitions().get("Pet") instanceof ModelImpl);
assertTrue(swagger.getDefinitions().get("Pet").getProperties().size() == 6);
assertNotNull(swagger.getPath("/pet/{petId}").getPost());
assertNotNull(swagger.getPath("/pet/{petId}").getPost().getParameters());
assertTrue(swagger.getPath("/pet/{petId}").getPost().getParameters().size() == 3);
assertTrue(swagger.getPath("/pet/{petId}").getPost().getParameters().get(1) instanceof RefParameter);
assertTrue(((RefParameter) swagger.getPath("/pet/{petId}").getPost().getParameters().get(1)).getRefFormat() == RefFormat.INTERNAL);
assertTrue(((RefParameter) swagger.getPath("/pet/{petId}").getPost().getParameters().get(1)).getSimpleRef().equals("name"));
assertNotNull(swagger.getPath("/store/order"));
assertNotNull(swagger.getPath("/store/order").getPost());
assertNotNull(swagger.getPath("/store/order").getPost().getParameters());
assertTrue(swagger.getPath("/store/order").getPost().getParameters().size() == 1);
assertTrue(swagger.getPath("/store/order").getPost().getParameters().get(0) instanceof BodyParameter);
assertNotNull(((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema());
assertTrue(((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema() instanceof RefModel);
assertTrue(((RefModel) ((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema()).getSimpleRef().equals("Order"));
assertTrue(swagger.getDefinitions().get("Order") instanceof ModelImpl);
assertTrue(swagger.getDefinitions().get("Order").getProperties().size() == 6);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue289.
@Test
public void testIssue289() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/issue-289.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/foo").getGet());
}
Aggregations