diff --git a/rest_framework/schemas/generators.py b/rest_framework/schemas/generators.py index 66afcca94..22b989c87 100644 --- a/rest_framework/schemas/generators.py +++ b/rest_framework/schemas/generators.py @@ -97,6 +97,9 @@ def insert_into(target, keys, value): target = target[key] try: + if len(keys) == 1: + target[keys[-1]] = LinkNode() + target = target[keys[-1]] target.links.append((keys[-1], value)) except TypeError: msg = INSERT_INTO_COLLISION_FMT.format( diff --git a/tests/test_schema_with_single_common_prefix.py b/tests/test_schema_with_single_common_prefix.py index d3bacede7..02c2a54b8 100644 --- a/tests/test_schema_with_single_common_prefix.py +++ b/tests/test_schema_with_single_common_prefix.py @@ -65,11 +65,13 @@ class AnotherTestRouterGeneratedSchema(TestCase): url='http://testserver/', title='Example API', content={ - 'example': { + 'test1': { 'test1': coreapi.Link( url='/example/example/test1/', action='get' - ), + ) + }, + 'test2': { 'test2': coreapi.Link( url='/example/example/test2/', action='get' @@ -77,7 +79,6 @@ class AnotherTestRouterGeneratedSchema(TestCase): } } ) - print(response.data) assert response.data == expected def test_authenticated_request(self): @@ -90,11 +91,13 @@ class AnotherTestRouterGeneratedSchema(TestCase): url='http://testserver/', title='Example API', content={ - 'example': { + 'test1': { 'test1': coreapi.Link( url='/example/example/test1/', action='get' - ), + ) + }, + 'test2': { 'test2': coreapi.Link( url='/example/example/test2/', action='get' diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 230f8f012..748fc17c0 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -1191,24 +1191,25 @@ class TestURLNamingCollisions(TestCase): schema = generator.get_schema() # not important here - desc_0 = schema['detail']['detail_export'].description - desc_1 = schema['detail_0'].description + desc_0 = schema['detail']['detail'].description + desc_1 = schema['detail']['detail_export'].description expected = coreapi.Document( url='', title='Naming Colisions', content={ 'detail': { + 'detail': coreapi.Link( + url='/from-routercollision/detail/', + action='get', + description=desc_0 + ), 'detail_export': coreapi.Link( url='/from-routercollision/detail/export/', action='get', - description=desc_0) - }, - 'detail_0': coreapi.Link( - url='/from-routercollision/detail/', - action='get', - description=desc_1 - ) + description=desc_1 + ) + } } )