Search in sources :

Example 51 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.

the class SwaggerDeserializerTest method testIssue161.

@Test
public void testIssue161() {
    String yaml = "swagger: '2.0'\n" + "paths:\n" + "  /users:\n" + "    get:\n" + "      parameters:\n" + "        - in: query\n" + "          name: name\n" + "          type: string\n" + "          minLength: 10\n" + "          maxLength: 100\n" + "          required: false\n" + "      responses:\n" + "        default:\n" + "          description: ok";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Set<String> messages = new HashSet<String>(result.getMessages());
    assertFalse(messages.contains("attribute paths.'/users'(get).[name].maxLength is unexpected"));
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 52 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.

the class SwaggerDeserializerTest method testRootInfo.

@Test
public void testRootInfo() {
    String json = "{\n" + "\t\"swagger\": \"2.0\",\n" + "\t\"foo\": \"bar\",\n" + "\t\"info\": \"invalid\"\n" + "}";
    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 foo is unexpected"));
    assertTrue(messages.contains("attribute info is not of type `object`"));
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 53 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.

the class SwaggerDeserializerTest method testContact.

@Test
public void testContact() {
    String json = "{\n" + "\t\"swagger\": \"2.0\",\n" + "\t\"info\": {\n" + "\t\t\"title\": \"title\",\n" + "\t\t\"bad\": \"bad\",\n" + "\t\t\"x-foo\": \"bar\",\n" + "\t\t\"description\": \"description\",\n" + "\t\t\"termsOfService\": \"tos\",\n" + "\t\t\"contact\": {\n" + "\t\t\t\"name\": \"tony\",\n" + "\t\t\t\"url\": \"url\",\n" + "\t\t\t\"email\": \"email\",\n" + "\t\t\t\"invalid\": \"invalid\",\n" + "\t\t\t\"x-fun\": true\n" + "\t\t},\n" + "\t\t\"version\": \"version\"\n" + "\t}\n" + "}";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(json);
    List<String> messageList = result.getMessages();
    Set<String> messages = new HashSet<String>(messageList);
    assertEquals(result.getSwagger().getInfo().getTitle(), "title");
    assertEquals(result.getSwagger().getInfo().getDescription(), "description");
    assertEquals(result.getSwagger().getInfo().getTermsOfService(), "tos");
    assertEquals(result.getSwagger().getInfo().getVersion(), "version");
    Contact contact = result.getSwagger().getInfo().getContact();
    assertEquals(contact.getName(), "tony");
    assertEquals(contact.getUrl(), "url");
    assertEquals(contact.getEmail(), "email");
    assertTrue(messages.contains("attribute info.contact.x-fun is unexpected"));
    assertTrue(messages.contains("attribute info.bad is unexpected"));
    assertTrue(messages.contains("attribute info.contact.invalid is unexpected"));
    assertEquals(result.getSwagger().getInfo().getVendorExtensions().get("x-foo").toString(), "bar");
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 54 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.

the class SwaggerDeserializerTest method testArrayQueryParam.

@Test
public void testArrayQueryParam() throws Exception {
    String json = "{\n" + "  \"swagger\": \"2.0\",\n" + "  \"paths\": {\n" + "    \"/pet/findByStatus\": {\n" + "      \"get\": {\n" + "        \"parameters\": [\n" + "          {\n" + "            \"name\": \"status\",\n" + "            \"in\": \"query\",\n" + "            \"description\": \"Status values that need to be considered for filter\",\n" + "            \"required\": false,\n" + "            \"type\": \"array\",\n" + "            \"items\": {\n" + "              \"type\": \"string\"\n" + "            },\n" + "            \"collectionFormat\": \"pipes\",\n" + "            \"default\": \"available\"\n" + "          }\n" + "        ],\n" + "        \"responses\": {\n" + "          \"200\": {\n" + "            \"description\": \"successful operation\",\n" + "            \"schema\": {\n" + "              \"$ref\": \"#/definitions/PetArray\"\n" + "            }\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(json);
    Swagger swagger = result.getSwagger();
    Parameter param = swagger.getPath("/pet/findByStatus").getGet().getParameters().get(0);
    assertTrue(param instanceof QueryParameter);
    QueryParameter qp = (QueryParameter) param;
    Property p = qp.getItems();
    assertEquals(qp.getType(), "array");
    assertTrue(p instanceof StringProperty);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 55 with SwaggerParser

use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.

the class SwaggerDeserializerTest method testToplevelExtension.

@Test(description = "it should read a top-level extension per https://github.com/swagger-api/validator-badge/issues/59")
public void testToplevelExtension() throws Exception {
    String json = "\n" + "{\n" + "    \"swagger\": \"2.0\",\n" + "\t\"x-foo\" : \"woof\",\n" + "    \"info\": {\n" + "        \"version\": \"0.0.0\",\n" + "        \"title\": \"Simple API\"\n" + "    },\n" + "    \"paths\": {\n" + "        \"/\": {\n" + "            \"get\": {\n" + "                \"responses\": {\n" + "                    \"200\": {\n" + "                        \"description\": \"OK\"\n" + "                    }\n" + "                }\n" + "            }\n" + "        }\n" + "    }\n" + "}";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(json);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) Test(org.testng.annotations.Test)

Aggregations

SwaggerParser (io.swagger.parser.SwaggerParser)65 Test (org.testng.annotations.Test)37 Swagger (io.swagger.models.Swagger)25 HashSet (java.util.HashSet)19 HashMap (java.util.HashMap)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 ArrayList (java.util.ArrayList)7 List (java.util.List)7 SecuritySchemeDefinition (io.swagger.models.auth.SecuritySchemeDefinition)6 IOException (java.io.IOException)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 Path (io.swagger.models.Path)5 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)5 Map (java.util.Map)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 HttpMethod (io.swagger.models.HttpMethod)4 Operation (io.swagger.models.Operation)4 BodyParameter (io.swagger.models.parameters.BodyParameter)4 File (java.io.File)4