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
Example #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
Example #3
0
def test_parse_typespec_int64():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({
        'type': 'integer',
        'format': 'int64',
        'description': 'foo'
    }) == ('int64', 'foo')
Example #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')
Example #5
0
def test_parse_typespec_datetime():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({
        'type': 'string',
        'format': 'date-time',
        'description': 'foo'
    }) == ('datetime', 'foo')
Example #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']
Example #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
Example #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
Example #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
Example #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
Example #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}/'
Example #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}/'
Example #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/'
Example #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}/'
Example #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}/'
Example #17
0
def test_parse_typespec_object():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
Example #18
0
def test_parse_typespec_boolean():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
Example #19
0
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms():
    t = SwaggerTranslator(None)
    assert 'customer' in t.words()
Example #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}/'
Example #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']
Example #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}/'
Example #23
0
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms(
):
    t = SwaggerTranslator(None)
    assert 'customer' in t.words()
Example #24
0
def test_parse_typespec_boolean():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
Example #25
0
def test_parse_typespec_int64():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'integer', 'format': 'int64', 'description': 'foo'}) == ('int64', 'foo')
Example #26
0
def test_parse_typespec_ref():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
Example #27
0
def test_parse_typespec_ref():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
Example #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')
Example #29
0
def test_parse_typespec_object():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
Example #30
0
def test_parse_typespec_datetime():
    t = SwaggerTranslator(None)
    assert t.parse_typespec({'type': 'string', 'format': 'date-time', 'description': 'foo'}) == ('datetime', 'foo')
Example #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/'