use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParser method readWithInfo.
public SwaggerDeserializationResult readWithInfo(String swaggerAsString, boolean resolve) {
if (swaggerAsString == null) {
return new SwaggerDeserializationResult().message("empty or null swagger supplied");
}
try {
JsonNode node;
if (swaggerAsString.trim().startsWith("{")) {
ObjectMapper mapper = Json.mapper();
node = mapper.readTree(swaggerAsString);
} else {
node = DeserializationUtils.readYamlTree(swaggerAsString);
}
SwaggerDeserializationResult result = new Swagger20Parser().readWithInfo(node);
if (result != null) {
if (resolve) {
result.setSwagger(new SwaggerResolver(result.getSwagger(), new ArrayList<AuthorizationValue>(), null).resolve());
}
} else {
result = new SwaggerDeserializationResult().message("Definition does not appear to be a valid Swagger format");
}
return result;
} catch (Exception e) {
return new SwaggerDeserializationResult().message("malformed or unreadable swagger supplied");
}
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class AnchorTest method testIssue146.
@Test
public void testIssue146() {
String yaml = "swagger: '2.0'\n" + "\n" + "info:\n" + " version: \"0.0.1\"\n" + " title: API\n" + "x-types:\n" + " OperationType: &OperationType\n" + " - registration\n" + "# Describe your paths here\n" + "paths:\n" + " /checker:\n" + " get:\n" + " parameters:\n" + " - name: operations\n" + " in: query\n" + " type: array\n" + " items:\n" + " type: string\n" + " enum: *OperationType\n" + " default: [registration]\n" + " responses:\n" + " 200:\n" + " description: OK\n" + " schema:\n" + " $ref: '#/definitions/OperationType'\n" + "definitions:\n" + " OperationType:\n" + " type: string\n" + " enum: *OperationType";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
ModelImpl model = (ModelImpl) result.getSwagger().getDefinitions().get("OperationType");
assertEquals(model.getEnum(), Arrays.asList("registration"));
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue306.
@Test
public void testIssue306() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-306.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertTrue(swagger.getDefinitions().size() == 3);
// resolved from `$ref: './book.yaml'`
assertNotNull(swagger.getDefinitions().get("Inventory"));
// resolved from `$ref: 'book.yaml'`
assertNotNull(swagger.getDefinitions().get("Orders"));
// copied from `./book.yaml`
assertNotNull(swagger.getDefinitions().get("book"));
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue314.
@Test
public void testIssue314() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-314.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getPath("/events"));
Path path = swagger.getPath("/events");
assertNotNull(path.getGet());
Operation get = path.getGet();
assertEquals(get.getOperationId(), "getEvents");
assertTrue(swagger.getDefinitions().size() == 3);
assertTrue(swagger.getDefinitions().get("Foobar").getProperties().size() == 1);
assertTrue(swagger.getDefinitions().get("StatusResponse").getProperties().size() == 1);
assertTrue(swagger.getDefinitions().get("Paging").getProperties().size() == 1);
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class FileReferenceTests method testIssue310.
@Test
public void testIssue310() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-310.yaml", null, true);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertTrue(swagger.getDefinitions().size() == 2);
assertTrue(swagger.getDefinitions().get("Paging").getProperties().size() == 1);
}
Aggregations