use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testIssue343Parameter.
@Test
public void testIssue343Parameter() {
String yaml = "swagger: '2.0'\n" + "info:\n" + " description: 'bleh'\n" + " version: '2.0.0'\n" + " title: 'Test'\n" + "paths:\n" + " /foo:\n" + " post:\n" + " parameters:\n" + " - in: query\n" + " name: skip\n" + " type: integer\n" + " format: int32\n" + " multipleOf: 3\n" + " - in: body\n" + " name: body\n" + " required: true\n" + " schema:\n" + " type: object\n" + " additionalProperties:\n" + " type: string\n" + " responses:\n" + " 200:\n" + " description: 'OK'\n" + "definitions:\n" + " Fun:\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " multipleOf: 5\n" + " mySet:\n" + " type: array\n" + " uniqueItems: true\n" + " items:\n" + " type: string";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Swagger swagger = result.getSwagger();
QueryParameter qp = (QueryParameter) swagger.getPath("/foo").getPost().getParameters().get(0);
assertEquals(qp.getMultipleOf(), 3.0);
BodyParameter bp = (BodyParameter) swagger.getPath("/foo").getPost().getParameters().get(1);
ModelImpl schema = (ModelImpl) bp.getSchema();
assertTrue(schema.getAdditionalProperties() != null);
IntegerProperty id = (IntegerProperty) swagger.getDefinitions().get("Fun").getProperties().get("id");
assertEquals(id.getMultipleOf(), new BigDecimal("5"));
ArrayProperty ap = (ArrayProperty) swagger.getDefinitions().get("Fun").getProperties().get("mySet");
assertTrue(ap.getUniqueItems());
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testDeserializeWithNumericEnumDiscriminator.
@Test
public void testDeserializeWithNumericEnumDiscriminator() {
String yaml = "swagger: '2.0'\n" + "definitions: \n" + " Animal:\n" + " type: object\n" + " discriminator: petType\n" + " description: |\n" + " A basic `Animal` object which can extend to other animal types.\n" + " required:\n" + " - commonName\n" + " - petType\n" + " properties:\n" + " commonName:\n" + " description: the household name of the animal\n" + " type: string\n" + " petType:\n" + " enum:\n" + " - 1\n" + " - 2";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Map<String, Property> properties = result.getSwagger().getDefinitions().get("Animal").getProperties();
assertTrue(properties.containsKey("commonName"));
assertTrue(properties.containsKey("petType"));
assertEquals(properties.get("petType").getType(), "number");
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testPathsWithRefResponse.
@Test
public void testPathsWithRefResponse() {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"paths\": {\n" + " \"/pet\": {\n" + " \"get\": {\n" + " \"responses\": {\n" + " \"200\": {\n" + " \"$ref\": \"#/responses/OK\"" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
Swagger swagger = result.getSwagger();
Path path = swagger.getPath("/pet");
assertNotNull(path);
Operation operation = path.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().containsKey("200"));
assertEquals(RefResponse.class, operation.getResponses().get("200").getClass());
RefResponse refResponse = (RefResponse) operation.getResponses().get("200");
assertEquals("#/responses/OK", refResponse.get$ref());
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testResponses.
@Test
public void testResponses() {
String json = "{\n" + "\t\"swagger\": \"2.0\",\n" + "\t\"responses\": {\n" + "\t\t\"foo\": {\n" + "\t\t\t\"description\": \"description\",\n" + "\t\t\t\"bar\": \"baz\",\n" + "\t\t\t\"x-foo\": \"bar\"\n" + "\t\t}\n" + "\t}\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 responses.foo.bar is unexpected"));
assertEquals(result.getSwagger().getResponses().get("foo").getVendorExtensions().get("x-foo").toString(), "bar");
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testPaths.
@Test
public void testPaths() {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"paths\": {\n" + " \"/pet\": {\n" + " \"foo\": \"bar\",\n" + " \"get\": {\n" + " \"security\": [\n" + " {\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }\n" + " ]\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);
assertTrue(messages.contains("attribute paths.'/pet'.foo is unexpected"));
Swagger swagger = result.getSwagger();
Path path = swagger.getPath("/pet");
assertNotNull(path);
Operation operation = path.getGet();
assertNotNull(operation);
List<Map<String, List<String>>> security = operation.getSecurity();
assertTrue(security.size() == 1);
Map<String, List<String>> requirement = security.get(0);
assertTrue(requirement.containsKey("petstore_auth"));
List<String> scopesList = requirement.get("petstore_auth");
Set<String> scopes = new HashSet<String>(scopesList);
assertTrue(scopes.contains("read:pets"));
assertTrue(scopes.contains("write:pets"));
}
Aggregations