def test_validate_spec_url_with_invalid_parameters_examples(): with pytest.raises(ValidationError) as exc_info: validate_spec_url( '{}/fixtures/failing_specs/examples_error.json'.format(TESTS_ROOT)) expected1 = "'schema': {}" expected2 = "'examples': {}" expected3 = "'example': {}" expected4 = 'is not valid under any of the given schemas' assert expected1 in exc_info.value.message assert expected2 in exc_info.value.message assert expected3 in exc_info.value.message assert expected4 in exc_info.value.message
def test_resolver_derefered_with_store_spec(): resolver = validate_spec_url( 'OpenAPI-Specification-2.1/example/swagger.json' ) spec_derefered_expected = json.load( open(os.path.join(TESTS_ROOT, 'fixtures/derefed_specs/store_example.json')) ) assert resolver.spec_derefered == spec_derefered_expected
def test_resolver_derefered_with_validation_spec(): resolver = validate_spec_url( 'tests/fixtures/validation_spec/swagger.json' ) spec_derefered_expected = json.load( open(os.path.join(TESTS_ROOT, 'fixtures/derefed_specs/validation_spec.json')) ) assert resolver.spec_derefered == spec_derefered_expected
def test_resolver_derefered_with_validation_petstore_spec(): resolver = validate_spec_url( 'OpenAPI-Specification-Official/examples/v2.0/yaml/petstore.yaml' ) ssv_validate_spec(resolver.spec_derefered) spec_derefered_expected = json.load( open(os.path.join(TESTS_ROOT, 'fixtures/derefed_specs/petstore.json')) ) assert resolver.spec_derefered == spec_derefered_expected
def main(): args = parser.parse_args() errors_count = 0 first_fail = None for spec in args.specifications: try: validate_spec_url(spec) if not args.silent: print_green("{} - OK".format(spec)) my_print('', is_error=False) except (SwaggerValidationError, _Error, RefResolutionError, UnknownType, FormatError) as e: errors_count += 1 print_red("{} - ERROR".format(spec)) if not args.show_all_messages and not first_fail: first_fail = spec, e if args.show_all_messages or args.stop_on_fail or args.silent: print_red("Message:") print_bold(e) print_red("{} - ERROR\n\n".format(spec)) if args.stop_on_fail or args.silent: return 1 else: my_print('') if first_fail: spec, error = first_fail print_red("\nValidator message for '{}':".format(spec)) print_bold(error) print_red("Above is the validator message for '{}'.\n\n".format(spec)) return errors_count
def test_validate_spec_url_with_invalid_base_path(): with pytest.raises(ValueError) as exc_info: validate_spec_url('', spec_url_base_path='..') expected = ("The 'base_path' must be an absolute path", ) assert exc_info.value.args == expected
def test_validate_spec_url_scheme(): assert validate_spec_url( 'file:{}/fixtures/validation_spec/swagger.json'.format(TESTS_ROOT))
def test_validate_spec_url_with_base_path(): assert validate_spec_url( '../OpenAPI-Specification-2.1/example/swagger.json', spec_url_base_path=TESTS_ROOT)
def test_validate_spec_url_relative_with_schema_url(): assert validate_spec_url( 'OpenAPI-Specification-2.1/example/swagger.json', schema_url='file:{}/spec/schema.json'.format(OPENAPI21_PATH))
def test_validate_spec_url_relative(): assert validate_spec_url('OpenAPI-Specification-2.1/example/swagger.json')
def test_validate_spec_url_absolute_with_schema_url(): assert validate_spec_url( 'file:{}/fixtures/validation_spec/swagger.json'.format(TESTS_ROOT), schema_url='file:{}/spec/schema.json'.format(OPENAPI21_PATH))
def test_validate_spec_url_absolute(): assert validate_spec_url( '{}/fixtures/validation_spec/swagger.json'.format(TESTS_ROOT))
def test_retrocompatibility_petstore(): assert validate_spec_url( 'OpenAPI-Specification-Official/examples/v2.0/yaml/petstore.yaml')
def test_retrocompatibility_api_with_examples(): assert validate_spec_url('OpenAPI-Specification-Official/examples/' 'v2.0/yaml/api-with-examples.yaml')
def test_retrocompatibility_petstore_separate(): assert validate_spec_url( 'OpenAPI-Specification-Official/examples/v2.0/yaml/' 'petstore-separate/spec/swagger.yaml')
def test_retrocompatibility_petstore_with_external_docs(): assert validate_spec_url('OpenAPI-Specification-Official/examples/' 'v2.0/yaml/petstore-with-external-docs.yaml')