Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
0fe0e1e7
Commit
0fe0e1e7
authored
Oct 21, 2016
by
Tom Christie
Committed by
GitHub
Oct 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix schema base paths (#4611)
parent
d647d37a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
rest_framework/schemas.py
+13
-2
tests/test_schemas.py
+11
-0
No files found.
rest_framework/schemas.py
View file @
0fe0e1e7
import
os
import
re
import
re
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
importlib
import
import_module
from
importlib
import
import_module
...
@@ -37,6 +36,18 @@ types_lookup = ClassLookupDict({
...
@@ -37,6 +36,18 @@ types_lookup = ClassLookupDict({
})
})
def
common_path
(
paths
):
split_paths
=
[
path
.
strip
(
'/'
)
.
split
(
'/'
)
for
path
in
paths
]
s1
=
min
(
split_paths
)
s2
=
max
(
split_paths
)
common
=
s1
for
i
,
c
in
enumerate
(
s1
):
if
c
!=
s2
[
i
]:
common
=
s1
[:
i
]
break
return
'/'
+
'/'
.
join
(
common
)
def
get_pk_name
(
model
):
def
get_pk_name
(
model
):
meta
=
model
.
_meta
.
concrete_model
.
_meta
meta
=
model
.
_meta
.
concrete_model
.
_meta
return
_get_pk
(
meta
)
.
name
return
_get_pk
(
meta
)
.
name
...
@@ -292,7 +303,7 @@ class SchemaGenerator(object):
...
@@ -292,7 +303,7 @@ class SchemaGenerator(object):
# one URL that doesn't have a path prefix.
# one URL that doesn't have a path prefix.
return
'/'
return
'/'
prefixes
.
append
(
'/'
+
prefix
+
'/'
)
prefixes
.
append
(
'/'
+
prefix
+
'/'
)
return
os
.
path
.
commonprefix
(
prefixes
)
return
common_path
(
prefixes
)
def
create_view
(
self
,
callback
,
method
,
request
=
None
):
def
create_view
(
self
,
callback
,
method
,
request
=
None
):
"""
"""
...
...
tests/test_schemas.py
View file @
0fe0e1e7
...
@@ -335,3 +335,14 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
...
@@ -335,3 +335,14 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
}
}
)
)
self
.
assertEqual
(
schema
,
expected
)
self
.
assertEqual
(
schema
,
expected
)
@unittest.skipUnless
(
coreapi
,
'coreapi is not installed'
)
class
Test4605Regression
(
TestCase
):
def
test_4605_regression
(
self
):
generator
=
SchemaGenerator
()
prefix
=
generator
.
determine_path_prefix
([
'/api/v1/items/'
,
'/auth/convert-token/'
])
assert
prefix
==
'/'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment