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"));
}
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`"));
}
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");
}
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);
}
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);
}
Aggregations