Search in sources :

Example 11 with SwaggerParser

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);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with SwaggerParser

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);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) Test(org.testng.annotations.Test)

Example 13 with SwaggerParser

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"));
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 14 with SwaggerParser

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);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) Test(org.testng.annotations.Test)

Example 15 with SwaggerParser

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"));
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SwaggerParser (io.swagger.parser.SwaggerParser)91 Swagger (io.swagger.models.Swagger)44 Test (org.testng.annotations.Test)37 HashSet (java.util.HashSet)21 HashMap (java.util.HashMap)14 Path (io.swagger.models.Path)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Operation (io.swagger.models.Operation)9 List (java.util.List)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)8 Test (org.junit.Test)8 HttpMethod (io.swagger.models.HttpMethod)7 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)7 File (java.io.File)7 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)6 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6