use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testDeserializeWithMessages.
@Test
public void testDeserializeWithMessages() {
String yaml = "swagger: '2.0'\n" + "info:\n" + " version: 0.0.0\n" + " title:\n" + " - bar";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Set<String> messages = new HashSet<String>(result.getMessages());
assertTrue(messages.size() == 2);
assertTrue(messages.contains("attribute info.title is not of type `string`"));
assertTrue(messages.contains("attribute paths is missing"));
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testDeserializeEnum.
@Test
public void testDeserializeEnum() {
String yaml = "swagger: '2.0'\n" + "info:\n" + " version: 0.0.0\n" + " title: your title\n" + "paths:\n" + " /persons:\n" + " get:\n" + " description: a test\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " schema:\n" + " type: object\n" + " properties:\n" + " se:\n" + " $ref: '#/definitions/StringEnum'\n" + " ie:\n" + " $ref: '#/definitions/IntegerEnum'\n" + " ne:\n" + " $ref: '#/definitions/NumberEnum'\n" + "definitions:\n" + " StringEnum:\n" + " type: string\n" + " default: foo\n" + " enum:\n" + " - First\n" + " - Second\n" + " IntegerEnum:\n" + " type: integer\n" + " default: 1\n" + " enum:\n" + " - -1\n" + " - 0\n" + " - 1\n" + " NumberEnum:\n" + " type: number\n" + " default: 3.14\n" + " enum:\n" + " - -1.151\n" + " - 0.0\n" + " - 1.6161\n" + " - 3.14";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
final Swagger resolved = new SwaggerResolver(result.getSwagger(), null).resolve();
Model stringModel = resolved.getDefinitions().get("StringEnum");
assertTrue(stringModel instanceof ModelImpl);
ModelImpl stringImpl = (ModelImpl) stringModel;
List<String> stringValues = stringImpl.getEnum();
assertEquals(2, stringValues.size());
assertEquals("First", stringValues.get(0));
assertEquals("Second", stringValues.get(1));
Model integerModel = resolved.getDefinitions().get("IntegerEnum");
assertTrue(integerModel instanceof ModelImpl);
ModelImpl integerImpl = (ModelImpl) integerModel;
List<String> integerValues = integerImpl.getEnum();
assertEquals(3, integerValues.size());
assertEquals("-1", integerValues.get(0));
assertEquals("0", integerValues.get(1));
assertEquals("1", integerValues.get(2));
Model numberModel = resolved.getDefinitions().get("NumberEnum");
assertTrue(numberModel instanceof ModelImpl);
ModelImpl numberImpl = (ModelImpl) numberModel;
List<String> numberValues = numberImpl.getEnum();
assertEquals(4, numberValues.size());
assertEquals("-1.151", numberValues.get(0));
assertEquals("0.0", numberValues.get(1));
assertEquals("1.6161", numberValues.get(2));
assertEquals("3.14", numberValues.get(3));
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testDeserializeBinaryString.
@Test
public void testDeserializeBinaryString() {
String json = "{\n" + " \"swagger\": \"2.0\",\n" + " \"info\": {\n" + " \"title\": \"foo\"\n" + " },\n" + " \"paths\": {\n" + " \"/test\": {\n" + " \"post\": {\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"AnyName\",\n" + " \"in\": \"body\",\n" + " \"schema\": {\n" + " \"type\": \"string\",\n" + " \"format\": \"binary\"\n" + " }\n" + " }\n" + " ],\n" + " \"responses\": {\n" + " \"200\": {\n" + " \"description\": \"ok\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(json);
final Swagger resolved = new SwaggerResolver(result.getSwagger(), null).resolve();
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testLicense.
@Test
public void testLicense() {
String json = "{\n" + "\t\"swagger\": \"2.0\",\n" + "\t\"info\": {\n" + "\t\t\"license\": {\n" + "\t\t\t\"invalid\": true,\n" + "\t\t\t\"x-valid\": {\n" + "\t\t\t\t\"isValid\": true\n" + "\t\t\t}\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 info.license.invalid is unexpected"));
assertTrue(messages.contains("attribute info.title is missing"));
assertTrue(messages.contains("attribute paths is missing"));
assertEquals(((Map) result.getSwagger().getInfo().getLicense().getVendorExtensions().get("x-valid")).get("isValid"), true);
}
use of io.swagger.parser.SwaggerParser in project swagger-parser by swagger-api.
the class SwaggerDeserializerTest method testDeserializeWithDiscriminator.
@Test
public void testDeserializeWithDiscriminator() {
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" + " description: |\n" + " The discriminator for the animal type. It _must_\n" + " match one of the concrete schemas by name (i.e. `Cat`)\n" + " for proper deserialization\n" + " type: string";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Set<String> messages = new HashSet<String>(result.getMessages());
assertFalse(messages.contains("attribute definitions.Animal.discriminator is unexpected"));
}
Aggregations