Merge pull request #126 from jbryan/better_reference_handling

Added support for circular references and additionalProperties
This commit is contained in:
Henning Jacobs
2016-02-05 17:32:50 +01:00
6 changed files with 239 additions and 75 deletions

View File

@@ -397,6 +397,78 @@ def test_schema_list(app):
assert wrong_items_response['title'] == 'Bad Request'
assert wrong_items_response['detail'].startswith("42 is not of type 'string'")
def test_schema_map(app):
app_client = app.app.test_client()
headers = {'Content-type': 'application/json'}
valid_object = {
"foo": {
"image_version": "string"
},
"bar": {
"image_version": "string"
}
}
invalid_object = {
"foo": 42
}
wrong_type = app_client.post('/v1.0/test_schema_map', headers=headers, data=json.dumps(42)) # type: flask.Response
assert wrong_type.status_code == 400
assert wrong_type.content_type == 'application/problem+json'
wrong_type_response = json.loads(wrong_type.data.decode()) # type: dict
assert wrong_type_response['title'] == 'Bad Request'
assert wrong_type_response['detail'].startswith("42 is not of type 'object'")
wrong_items = app_client.post('/v1.0/test_schema_map', headers=headers,
data=json.dumps(invalid_object)) # type: flask.Response
assert wrong_items.status_code == 400
assert wrong_items.content_type == 'application/problem+json'
wrong_items_response = json.loads(wrong_items.data.decode()) # type: dict
assert wrong_items_response['title'] == 'Bad Request'
assert wrong_items_response['detail'].startswith("42 is not of type 'object'")
right_type = app_client.post('/v1.0/test_schema_map', headers=headers,
data=json.dumps(valid_object)) # type: flask.Response
assert right_type.status_code == 200
def test_schema_recursive(app):
app_client = app.app.test_client()
headers = {'Content-type': 'application/json'}
valid_object = {
"children": [
{"children": []},
{"children": [
{"children": []},
]},
{"children": []},
]
}
invalid_object = {
"children": [42]
}
wrong_type = app_client.post('/v1.0/test_schema_recursive', headers=headers, data=json.dumps(42)) # type: flask.Response
assert wrong_type.status_code == 400
assert wrong_type.content_type == 'application/problem+json'
wrong_type_response = json.loads(wrong_type.data.decode()) # type: dict
assert wrong_type_response['title'] == 'Bad Request'
assert wrong_type_response['detail'].startswith("42 is not of type 'object'")
wrong_items = app_client.post('/v1.0/test_schema_recursive', headers=headers,
data=json.dumps(invalid_object)) # type: flask.Response
assert wrong_items.status_code == 400
assert wrong_items.content_type == 'application/problem+json'
wrong_items_response = json.loads(wrong_items.data.decode()) # type: dict
assert wrong_items_response['title'] == 'Bad Request'
assert wrong_items_response['detail'].startswith("42 is not of type 'object'")
right_type = app_client.post('/v1.0/test_schema_recursive', headers=headers,
data=json.dumps(valid_object)) # type: flask.Response
assert right_type.status_code == 200
def test_schema_format(app):
app_client = app.app.test_client()