def test_translate_path_template_params_leaves_paths_without_templates_unchanged(
):
    l = FakeLogger()
    t = SwaggerTranslator(logger=l)
    expected_warnings = []
    assert t.translate_path_template_params('/foo/barr/', []) == '/foo/barr/'
    assert l.warnings == expected_warnings
Esempio n. 2
0
def getOutputString(input):
    swag = yaml.load(input)
    w = writer.Writer('sysl')
    logger = FakeLogger()
    t = SwaggerTranslator(logger)
    t.translate(swag, appname='', package='', w=w)
    return str(w), logger
Esempio n. 3
0
def test_parse_typespec_int64():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({
        'type': 'integer',
        'format': 'int64',
        'description': 'foo'
    }) == ('int64', 'foo')
Esempio n. 4
0
def test_parse_typespec_double_is_translated_to_float():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({
        'type': 'number',
        'format': 'double',
        'description': 'foo'
    }) == ('float', 'foo')
Esempio n. 5
0
def test_parse_typespec_datetime():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({
        'type': 'string',
        'format': 'date-time',
        'description': 'foo'
    }) == ('datetime', 'foo')
Esempio n. 6
0
def test_translate_path_template_params_wont_rewrite_names_of_things_ending_with_id_suffix_as_camelcase_if_no_vocabulary_present():
    l = FakeLogger()
    t = SwaggerTranslator(logger=l, vocabulary_factory=(lambda: []))
    # perhaps breadid is a valid word. we dont know, we have no vocab.
    assert t.translate_path_template_params('/foo/{breadid}/', []) == '/foo/{breadid<:string}/'
    expected_warnings = ['not enough path params path: /foo/{breadid}/', 'could not find type for path param: {breadid} in params[]']
    assert l.warnings == expected_warnings + ['could not load any vocabulary, janky environment-specific heuristics for renaming path template names may fail']
Esempio n. 7
0
def getOutputString(input):
    swag = yaml.load(input)
    w = writer.Writer('sysl')
    logger = FakeLogger()
    t = SwaggerTranslator(logger)
    t.translate(swag, appname='', package='', w=w)
    return str(w), logger
def test_translate_path_template_params_rewrites_dashed_template_names_as_camelcase_string_typed_parameters(
):
    l = FakeLogger()
    t = SwaggerTranslator(logger=l)
    assert t.translate_path_template_params('/foo/{fizz-buzz}/',
                                            []) == '/foo/{fizzBuzz<:string}/'
    expected_warnings = [
        'not enough path params path: /foo/{fizz-buzz}/',
        'could not find type for path param: {fizz-buzz} in params[]'
    ]
    assert l.warnings == expected_warnings
Esempio n. 9
0
def test_translate_path_template_params_rewrites_names_of_things_that_look_like_a_dictionary_word_ending_with_id_suffix_as_camelcase(
):
    l = FakeLogger()
    t = SwaggerTranslator(logger=l, vocabulary_factory=(lambda: ['bread']))
    assert t.translate_path_template_params('/foo/{breadid}/',
                                            []) == '/foo/{breadId<:string}/'
    expected_warnings = [
        'not enough path params path: /foo/{breadid}/',
        'could not find type for path param: {breadid} in params[]'
    ]
    assert l.warnings == expected_warnings
Esempio n. 10
0
def test_parse_typespec_warns_and_ignores_type_if_array_items_type_has_both_type_and_ref():
    l = FakeLogger()
    t = SwaggerTranslator(logger=l)

    array_type = {
        'type': 'array',
        'items': {
            '$ref': '#/definitions/Barr',
            'type': 'Foo',
        },
        'description': 'this is where we keep our ill-specified things'
    }
    assert t.parse_typespec(array_type) == ('sequence of Barr', 'this is where we keep our ill-specified things')
    expected_warnings = ['Ignoring unexpected "type". Schema has "$ref" but also has unexpected "type". Note: {\'items\': {\'type\': \'Foo\', \'$ref\': \'#/definitions/Barr\'}, \'type\': \'array\'}']
    assert l.warnings == expected_warnings
Esempio n. 11
0
def test_parse_typespec_warns_and_ignores_type_if_array_items_type_has_both_type_and_ref():
    l = FakeLogger()
    t = SwaggerTranslator(logger=l)

    array_type = {
        'type': 'array',
        'items': {
            '$ref': '#/definitions/Barr',
            'type': 'Foo',
        },
        'description': 'this is where we keep our ill-specified things'
    }
    assert t.parse_typespec(array_type) == ('sequence of Barr', 'this is where we keep our ill-specified things')
    expected_warnings = ['Ignoring unexpected "type". Schema has "$ref" but also has unexpected "type". Note: {\'items\': {\'type\': \'Foo\', \'$ref\': \'#/definitions/Barr\'}, \'type\': \'array\'}']
    assert l.warnings == expected_warnings
Esempio n. 12
0
def test_translate_path_template_params_rewrites_names_of_things_that_look_like_a_dictionary_word_ending_with_id_suffix_as_camelcase(
):
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['bread']))
    assert t.translate_path_template_params(
        '/foo/{breadid}/') == '/foo/{breadId<:string}/'
Esempio n. 13
0
def test_translate_path_template_params_rewrites_dashed_template_names_as_camelcase_string_typed_parameters(
):
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['x']))
    assert t.translate_path_template_params(
        '/foo/{fizz-buzz}/') == '/foo/{fizzBuzz<:string}/'
Esempio n. 14
0
def test_translate_path_template_params_leaves_paths_without_templates_unchanged(
):
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['x']))
    assert t.translate_path_template_params('/foo/barr/') == '/foo/barr/'
Esempio n. 15
0
def test_translate_path_template_params_rewrites_dashed_template_names_as_camelcase_string_typed_parameters():
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['x']))
    assert t.translate_path_template_params('/foo/{fizz-buzz}/') == '/foo/{fizzBuzz<:string}/'
Esempio n. 16
0
def test_translate_path_template_params_doesnt_rewrite_nonwords_ending_in_id_typed_parameters():
    l = FakeLogger()
    t = SwaggerTranslator(logger=l, vocabulary_factory=(lambda: ['bread']))
    assert t.translate_path_template_params('/foo/{braedid}/', []) == '/foo/{braedid<:string}/'
Esempio n. 17
0
def test_parse_typespec_object():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
Esempio n. 18
0
def test_parse_typespec_boolean():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
Esempio n. 19
0
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms():
    t = SwaggerTranslator(None)
    assert 'customer' in t.words()
Esempio n. 20
0
def test_translate_path_template_params_doesnt_rewrite_nonwords_ending_in_id_typed_parameters():
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['bread']))
    assert t.translate_path_template_params('/foo/{braedid}/') == '/foo/{braedid<:string}/'
Esempio n. 21
0
def test_translate_path_template_params_wont_rewrite_names_of_things_ending_with_id_suffix_as_camelcase_if_no_vocabulary_present():
    l = FakeLogger()
    t = SwaggerTranslator(logger=l, vocabulary_factory=(lambda: []))
    # perhaps breadid is a valid word. we dont know, we have no vocab.
    assert t.translate_path_template_params('/foo/{breadid}/') == '/foo/{breadid<:string}/'
    assert l.warnings == ['could not load any vocabulary, janky environment-specific heuristics for renaming path template names may fail']
Esempio n. 22
0
def test_translate_path_template_params_rewrites_names_of_things_that_look_like_a_dictionary_word_ending_with_id_suffix_as_camelcase():
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['bread']))
    assert t.translate_path_template_params('/foo/{breadid}/') == '/foo/{breadId<:string}/'
Esempio n. 23
0
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms(
):
    t = SwaggerTranslator(None)
    assert 'customer' in t.words()
Esempio n. 24
0
def test_parse_typespec_boolean():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
Esempio n. 25
0
def test_parse_typespec_int64():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'integer', 'format': 'int64', 'description': 'foo'}) == ('int64', 'foo')
Esempio n. 26
0
def test_parse_typespec_ref():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
Esempio n. 27
0
def test_parse_typespec_ref():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
Esempio n. 28
0
def test_parse_typespec_double_is_translated_to_float():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'number', 'format': 'double', 'description': 'foo'}) == ('float', 'foo')
Esempio n. 29
0
def test_parse_typespec_object():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
Esempio n. 30
0
def test_parse_typespec_datetime():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'string', 'format': 'date-time', 'description': 'foo'}) == ('datetime', 'foo')
Esempio n. 31
0
def test_translate_path_template_params_leaves_paths_without_templates_unchanged():
    t = SwaggerTranslator(logger=None, vocabulary_factory=(lambda: ['x']))
    assert t.translate_path_template_params('/foo/barr/') == '/foo/barr/'