use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testSecurityDeserialization.
@Test
public void testSecurityDeserialization() throws Exception {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"security\": [\n" + " {\n" + " \"api_key1\": [],\n" + " \"api_key2\": []\n" + " },\n" + " {\n" + " \"api_key3\": []\n" + " }\n" + " ]\n" + "}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<String>(messageList);
Swagger swagger = result.getSwagger();
assertNotNull(swagger);
List<SecurityRequirement> security = swagger.getSecurity();
assertTrue(security.size() == 2);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testValidatorIssue50.
@Test
public void testValidatorIssue50() {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"info\": {\n" + " \"version\": \"2.0.0\",\n" + " \"title\": \"Beanhunter API\",\n" + " \"description\": \"Description of the api goes here.\"\n" + " },\n" + " \"host\": \"local.xxx.com\",\n" + " \"schemes\": [\n" + " \"http\"\n" + " ],\n" + " \"consumes\": [\n" + " \"application/json\"\n" + " ],\n" + " \"produces\": [\n" + " \"application/json\"\n" + " ],\n" + " \"paths\": {\n" + " \"/city\": {\n" + " \"get\": {\n" + " \"description\": \"test description\",\n" + " \"responses\": {}\n" + " }\n" + " }\n" + " },\n" + " \"definitions\": {\n" + " \"Endpoints\": {\n" + " \"title\": \"Endpoints object\",\n" + " \"properties\": {\n" + " \"links\": {}\n" + " }\n" + " }\n" + " }\n" + "}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
assertTrue(result.getMessages().size() == 1);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testSecurity.
@Test
public void testSecurity() {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"security\": [\n" + " {\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }\n" + " ]\n" + "}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<String>(messageList);
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getSecurity());
List<SecurityRequirement> security = swagger.getSecurity();
Assert.assertTrue(security.size() == 1);
Assert.assertTrue(security.get(0).getRequirements().size() == 1);
List<String> requirement = security.get(0).getRequirements().get("petstore_auth");
Assert.assertTrue(requirement.size() == 2);
Set<String> requirements = new HashSet(requirement);
Assert.assertTrue(requirements.contains("read:pets"));
Assert.assertTrue(requirements.contains("write:pets"));
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testIssue360.
@Test
public void testIssue360() {
Swagger swagger = new Swagger();
ModelImpl model = new ModelImpl()._enum((String) null);
swagger.addDefinition("modelWithNullEnum", model);
String json = Json.pretty(swagger);
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
Swagger rebuilt = result.getSwagger();
assertNotNull(rebuilt);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testEmpty.
@Test
public void testEmpty() {
String json = "{}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<String>(messageList);
assertTrue(messages.contains("attribute swagger is missing"));
assertTrue(messages.contains("attribute info is missing"));
assertTrue(messages.contains("attribute paths is missing"));
}
Aggregations