def test_invalid_inline_models_in_api_body_parameters_fails(): apis = { '/endpoint': { 'parameters': [ { 'in': 'body', 'name': 'body', 'schema': { 'type': 'object', 'properties': {'prop': {'type': 'array'}}, }, } ], 'get': { 'responses': { '200': { 'description': 'desc', }, }, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) assert str(excinfo.value) == 'Definition of type array must define `items` property ' \ '(definition #/paths//endpoint/parameters/0/schema/properties/prop).'
def test_invalid_inline_models_in_api_body_parameters_fails(): apis = { '/endpoint': { 'parameters': [{ 'in': 'body', 'name': 'body', 'schema': { 'type': 'object', 'properties': { 'prop': { 'type': 'array' } }, }, }], 'get': { 'responses': { '200': { 'description': 'desc', }, }, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) assert str(excinfo.value) == 'Definition of type array must define `items` property ' \ '(definition #/paths//endpoint/parameters/0/schema/properties/prop).'
def test_duplicate_operationIds_fails(apis): with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) swagger_validation_error = excinfo.value error_message = swagger_validation_error.args[0] assert error_message == "Duplicate operationId: duplicateOperationId"
def test_duplicate_operationIds_fails(apis): with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) swagger_validation_error = excinfo.value error_message = swagger_validation_error.args[0] assert error_message == "Duplicate operationId: duplicateOperationId"
def test_api_level_params_ok(): # Parameters defined at the API level apply to all operations within that # API. Make sure we don't treat the API level parameters as an operation # since they are peers. apis = { "/tags/{tag-name}": { "parameters": [{"name": "tag-name", "in": "path", "type": "string", "required": True}], "get": {}, } } # Success == no exception thrown validate_apis(apis)
def test_api_check_default_succeed(partial_parameter_spec): apis = { '/api': { 'get': { 'parameters': [ dict({'name': 'param', 'in': 'query'}, **partial_parameter_spec), ], 'responses': RESPONSES, }, }, } # Success if no exception are raised validate_apis(apis, lambda x: x)
def test_api_level_x_hyphen_ok(): # Elements starting with "x-" should be ignored apis = { '/tags/{tag-name}': { 'x-ignore-me': 'DO NOT LOOK AT ME!', 'get': { 'parameters': [{ 'name': 'tag-name', 'in': 'path', 'type': 'string', }] } } } # Success == no exception thrown validate_apis(apis, lambda x: x)
def test_api_check_default_succeed(partial_parameter_spec): apis = { '/api': { 'get': { 'parameters': [ dict({ 'name': 'param', 'in': 'query' }, **partial_parameter_spec), ], }, }, } # Success if no exception are raised validate_apis(apis, lambda x: x)
def test_api_check_default_fails(partial_parameter_spec, validator, instance): apis = { '/api': { 'get': { 'parameters': [ dict({'name': 'param', 'in': 'query'}, **partial_parameter_spec), ], 'responses': RESPONSES, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) validation_error = excinfo.value.args[1] assert validation_error.instance == instance assert validation_error.validator == validator
def test_api_level_x_hyphen_ok(): # Elements starting with "x-" should be ignored apis = { '/tags/{tag-name}': { 'x-ignore-me': 'DO NOT LOOK AT ME!', 'get': { 'parameters': [ { 'name': 'tag-name', 'in': 'path', 'type': 'string', } ] } } } # Success == no exception thrown validate_apis(apis, lambda x: x)
def test_api_level_params_ok(): # Parameters defined at the API level apply to all operations within that # API. Make sure we don't treat the API level parameters as an operation # since they are peers. apis = { '/tags/{tag-name}': { 'parameters': [ { 'name': 'tag-name', 'in': 'path', 'type': 'string', }, ], 'get': {} } } # Success == no exception thrown validate_apis(apis, lambda x: x)
def test_api_level_params_ok(): # Parameters defined at the API level apply to all operations within that # API. Make sure we don't treat the API level parameters as an operation # since they are peers. apis = { '/tags/{tag-name}': { 'parameters': [ { 'name': 'tag-name', 'in': 'path', 'type': 'string', }, ], 'get': { } } } # Success == no exception thrown validate_apis(apis, lambda x: x)
def test_api_check_default_fails(partial_parameter_spec, validator, instance): apis = { '/api': { 'get': { 'parameters': [ dict({ 'name': 'param', 'in': 'query' }, **partial_parameter_spec), ], }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_apis(apis, lambda x: x) validation_error = excinfo.value.args[1] assert validation_error.instance == instance assert validation_error.validator == validator
def test_duplicate_operationIds_succeeds_if_tags_differ(apis): validate_apis(apis, lambda x: x)
def test_duplicate_operationIds_succeeds_if_tags_differ(apis): validate_apis(apis, lambda x: x)