def test_parse_typespec_double_is_translated_to_float(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ 'type': 'number', 'format': 'double', 'description': 'foo' }) == ('float', 'foo')
def test_translate_path_template_params_leaves_paths_without_templates_unchanged( ): l = FakeLogger() t = OpenApiTranslator(logger=l) expected_warnings = [] assert t.translate_path_template_params('/foo/barr/', []) == '/foo/barr/' assert l.warnings == expected_warnings
def test_parse_typespec_int64(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ 'type': 'integer', 'format': 'int64', 'description': 'foo' }) == ('int64', 'foo')
def test_parse_typespec_datetime(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ 'type': 'string', 'format': 'date-time', 'description': 'foo' }) == ('datetime', 'foo')
def getOutputString(input): prefix = re.match('^ *', input).group(0) swag = yaml.load(re.sub(r'^' + prefix, '', input), Loader=yaml.FullLoader) w = writer.Writer('sysl') logger = FakeLogger() t = OpenApiTranslator(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 = OpenApiTranslator(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_parse_typespec_warns_and_ignores_type_if_array_items_type_has_both_type_and_ref(): l = FakeLogger() t = OpenApiTranslator(logger=l) array_type = { 'type': 'array', 'items': { '$ref': '#/components/schemas/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\': \'#/components/schemas/Barr\'}, \'type\': \'array\'}'] assert l.warnings == expected_warnings
def test_parse_typespec_ref(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ '$ref': '#/components/schemas/Barr', 'description': 'foo' }) == ('Barr', 'foo')
def test_parse_typespec_object(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ 'type': 'object', 'description': 'foo' }, '', 'Object') == ('EXTERNAL_Object_obj', 'foo')
def test_parse_typespec_boolean(): t = OpenApiTranslator(FakeLogger()) assert t.parse_typespec({ 'type': 'boolean', 'description': 'foo' }) == ('bool', 'foo')