use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method doRelativeFileTest.
private Swagger doRelativeFileTest(String location) {
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult readResult = parser.readWithInfo(location, null, true);
if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final Swagger swagger = readResult.getSwagger();
final Path path = swagger.getPath("/health");
// we successfully converted the RefPath to a Path
assertEquals(path.getClass(), Path.class);
final List<Parameter> parameters = path.getParameters();
assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
final Operation operation = path.getGet();
final List<Parameter> operationParams = operation.getParameters();
assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
assertParamDetails(operationParams, 2, BodyParameter.class, "body", "body");
final BodyParameter bodyParameter = (BodyParameter) operationParams.get(2);
assertEquals(((RefModel) bodyParameter.getSchema()).get$ref(), "#/definitions/health");
final Map<String, Response> responsesMap = operation.getResponses();
assertResponse(swagger, responsesMap, "200", "Health information from the server", "#/definitions/health");
assertResponse(swagger, responsesMap, "400", "Your request was not valid", "#/definitions/error");
assertResponse(swagger, responsesMap, "500", "An unexpected error occur during processing", "#/definitions/error");
final Map<String, Model> definitions = swagger.getDefinitions();
final ModelImpl refInDefinitions = (ModelImpl) definitions.get("refInDefinitions");
assertEquals(refInDefinitions.getDescription(), "The example model");
expectedPropertiesInModel(refInDefinitions, "foo", "bar");
final ArrayModel arrayModel = (ArrayModel) definitions.get("arrayModel");
final RefProperty arrayModelItems = (RefProperty) arrayModel.getItems();
assertEquals(arrayModelItems.get$ref(), "#/definitions/foo");
final ModelImpl fooModel = (ModelImpl) definitions.get("foo");
assertEquals(fooModel.getDescription(), "Just another model");
expectedPropertiesInModel(fooModel, "hello", "world");
final ComposedModel composedCat = (ComposedModel) definitions.get("composedCat");
final ModelImpl child = (ModelImpl) composedCat.getChild();
expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
final ArrayProperty reflexes = (ArrayProperty) child.getProperties().get("reflexes");
final RefProperty reflexItems = (RefProperty) reflexes.getItems();
assertEquals(reflexItems.get$ref(), "#/definitions/reflex");
assertTrue(definitions.containsKey(reflexItems.getSimpleRef()));
final MapProperty reflexMap = (MapProperty) child.getProperties().get("reflexMap");
final RefProperty reflexMapAdditionalProperties = (RefProperty) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/definitions/reflex");
assertEquals(composedCat.getInterfaces().size(), 2);
assertEquals(composedCat.getInterfaces().get(0).get$ref(), "#/definitions/pet");
assertEquals(composedCat.getInterfaces().get(1).get$ref(), "#/definitions/foo_2");
return swagger;
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue292WithNoCollectionFormat.
@Test
public void testIssue292WithNoCollectionFormat() {
String yaml = "swagger: '2.0'\n" + "info:\n" + " version: '0.0.0'\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " 200:\n" + " description: Successful response";
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo(yaml);
Swagger swagger = result.getSwagger();
Parameter param = swagger.getPaths().get("/persons").getGet().getParameters().get(0);
QueryParameter qp = (QueryParameter) param;
assertNull(qp.getCollectionFormat());
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIncompatibleRefs.
@Test
public void testIncompatibleRefs() {
String yaml = "swagger: '2.0'\n" + "paths:\n" + " /test:\n" + " post:\n" + " parameters:\n" + " # this is not the correct reference type\n" + " - $ref: '#/definitions/Model'\n" + " - in: body\n" + " name: incorrectType\n" + " required: true\n" + " schema:\n" + " $ref: '#/definitions/Model'\n" + " responses:\n" + " 200:\n" + " # this is not the correct reference type\n" + " $ref: '#/definitions/Model'\n" + " 400:\n" + " definitions: this is right\n" + " schema:\n" + " $ref: '#/definitions/Model'\n" + "definitions:\n" + " Model:\n" + " type: object";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(yaml);
assertNotNull(result.getSwagger());
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue393.
@Test
public void testIssue393() {
SwaggerParser parser = new SwaggerParser();
String yaml = "swagger: '2.0'\n" + "info:\n" + " title: x\n" + " version: 1.0.0\n" + "paths:\n" + " /test:\n" + " get:\n" + " parameters: []\n" + " responses:\n" + " '400':\n" + " description: |\n" + " The account could not be created because a credential didn't meet the complexity requirements.\n" + " x-error-refs:\n" + " - '$ref': '#/x-error-defs/credentialTooShort'\n" + " - '$ref': '#/x-error-defs/credentialTooLong'\n" + "x-error-defs:\n" + " credentialTooShort:\n" + " errorID: credentialTooShort";
final SwaggerDeserializationResult result = parser.readWithInfo(yaml);
assertNotNull(result.getSwagger());
Swagger swagger = result.getSwagger();
assertNotNull(swagger.getVendorExtensions().get("x-error-defs"));
}
use of io.swagger.parser.util.SwaggerDeserializationResult in project swagger-parser by swagger-api.
the class SwaggerReaderTest method testIssue192.
@Test
public void testIssue192() {
String spec = "swagger: '2.0'\n" + "info:\n" + " title: issue 192\n" + "paths:\n" + " /foo:\n" + " get:\n" + " parameters:\n" + " - name: Code\n" + " in: path\n" + " description: The code\n" + " required: true\n" + " type: string\n" + " minLength: 4\n" + " maxLength: 5\n" + " pattern: '^[a-zA-Z]'\n" + " responses:\n" + " 200:\n" + " description: 'the pet'";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
Swagger swagger = result.getSwagger();
Parameter param = swagger.getPath("/foo").getGet().getParameters().get(0);
assertTrue(param instanceof PathParameter);
PathParameter pathParameter = (PathParameter) param;
assertEquals(pathParameter.getMinLength(), new Integer(4));
assertEquals(pathParameter.getMaxLength(), new Integer(5));
assertNull(pathParameter.isReadOnly());
assertEquals(pathParameter.getPattern(), "^[a-zA-Z]");
}
Aggregations