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
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_parse_typespec_int64(): t = SwaggerTranslator(None) assert t.parse_typespec({ 'type': 'integer', 'format': 'int64', 'description': 'foo' }) == ('int64', 'foo')
def test_parse_typespec_double_is_translated_to_float(): t = SwaggerTranslator(None) assert t.parse_typespec({ 'type': 'number', 'format': 'double', 'description': 'foo' }) == ('float', 'foo')
def test_parse_typespec_datetime(): t = SwaggerTranslator(None) assert t.parse_typespec({ 'type': 'string', 'format': 'date-time', 'description': 'foo' }) == ('datetime', 'foo')
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']
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
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
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
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
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}/'
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}/'
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/'
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}/'
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}/'
def test_parse_typespec_object(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
def test_parse_typespec_boolean(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms(): t = SwaggerTranslator(None) assert 'customer' in t.words()
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}/'
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']
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}/'
def test_default_vocabulary_containing_common_business_nouns_is_defined_for_non_windows_platforms( ): t = SwaggerTranslator(None) assert 'customer' in t.words()
def test_parse_typespec_boolean(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'boolean', 'description': 'foo'}) == ('bool', 'foo')
def test_parse_typespec_int64(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'integer', 'format': 'int64', 'description': 'foo'}) == ('int64', 'foo')
def test_parse_typespec_ref(): t = SwaggerTranslator(None) assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
def test_parse_typespec_ref(): t = SwaggerTranslator(None) assert t.parse_typespec({'$ref': '#/definitions/Barr', 'description': 'foo'}) == ('Barr', 'foo')
def test_parse_typespec_double_is_translated_to_float(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'number', 'format': 'double', 'description': 'foo'}) == ('float', 'foo')
def test_parse_typespec_object(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'object', 'description': 'foo'}, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
def test_parse_typespec_datetime(): t = SwaggerTranslator(None) assert t.parse_typespec({'type': 'string', 'format': 'date-time', 'description': 'foo'}) == ('datetime', 'foo')
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/'