def test_get_collapsed_properties_type_mapping_allOf_add_not_required_property():
    file_path = './tests/data/v2.0/test_polymorphic_specs/swagger.json'
    swagger_dict, _ = get_spec_json_and_url(file_path)

    required_parameters, not_required_parameters = get_collapsed_properties_type_mappings(
        definition=swagger_dict['definitions']['Cat'],
        deref=get_deref(swagger_dict),
    )
    assert required_parameters == {'type': 'string', 'weight': 'integer'}
    assert not_required_parameters == {'name': 'string', 'color': 'string'}
Пример #2
0
def test_fails_on_invalid_external_ref_in_list():
    # The external ref in petstore.json is valid.
    # The contents of the external ref (pet.json#/get_all_parameters) is not
    # - the 'name' key in the parameter is missing.
    petstore_spec, petstore_url = get_spec_json_and_url(
        './tests/data/v2.0/test_fails_on_invalid_external_ref_in_list/petstore.json'
    )

    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_spec(petstore_spec, petstore_url)

    assert "is not valid under any of the given schemas" in str(excinfo.value)
Пример #3
0
def test_api_parameters_as_refs():
    # Verify issue #29 - instragram.json comes from:
    #
    # http://editor.swagger.io/#/
    #    -> File
    #       -> Open Example...
    #          -> instagram.yaml
    #
    # and then export it to a json file.
    instagram_specs, _ = get_spec_json_and_url(
        './tests/data/v2.0/instagram.json')
    validate_spec(instagram_specs)
def test_get_collapsed_properties_type_mapping_allOf_add_required_property():
    file_path = './tests/data/v2.0/test_polymorphic_specs/swagger.json'
    swagger_dict, _ = get_spec_json_and_url(file_path)

    required_parameters, not_required_parameters = get_collapsed_properties_type_mappings(
        definition=swagger_dict['definitions']['Dog'],
        deref=get_deref(swagger_dict),
    )
    assert required_parameters == {
        'type': 'string',
        'weight': 'integer',
        'birth_date': 'string'
    }
    assert not_required_parameters == {'name': 'string'}
Пример #5
0
def test_complicated_refs():
    # Split the swagger spec into a bunch of different json files and use
    # $refs all over to place to wire stuff together - see the test-data
    # files or this will make no sense whatsoever.
    file_path = '../../tests/data/v2.0/test_complicated_refs/swagger.json'
    swagger_dict, origin_url = get_spec_json_and_url(file_path)
    resolver = validate_spec(swagger_dict, spec_url=origin_url)

    # Hokey verification but better than nothing:
    #   If all the files with $refs were ingested and validated and an
    #   exception was not thrown, there should be 8 cached refs in the
    #   resolver's store:
    #
    #   6 json files from ../../tests/data/v2.0/tests_complicated_refs/*
    #   1 draft3 spec
    #   1 draft4 spec
    assert len(resolver.store) == 8
Пример #6
0
def test_complicated_refs():
    # Split the swagger spec into a bunch of different json files and use
    # $refs all over to place to wire stuff together - see the test-data
    # files or this will make no sense whatsoever.
    file_path = './tests/data/v2.0/test_complicated_refs/swagger.json'
    swagger_dict, origin_url = get_spec_json_and_url(file_path)
    resolver = validate_spec(swagger_dict, spec_url=origin_url)

    # Hokey verification but better than nothing:
    #   If all the files with $refs were ingested and validated and an
    #   exception was not thrown, there should be 7 cached file references
    #   in the resolver's store:
    #       6 json files from tests/data/v2.0/tests_complicated_refs/*
    #       1 yaml files from tests/data/v2.0/tests_complicated_refs/*
    assert len([
        uri for uri in resolver.store.keys() if uri.startswith('file://')
    ]) == 7
def test_specs_with_discriminator_in_allOf():
    file_path = './tests/data/v2.0/test_polymorphic_specs/swagger.json'
    swagger_dict, _ = get_spec_json_and_url(file_path)

    validate_spec(swagger_dict)