Skip to content

Commit

Permalink
bugfix leaking path var names in operationId #137
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Sep 9, 2020
1 parent 9e9a40a commit 8876f39
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def get_operation_id(self):
else:
action = self.method_mapping[self.method.lower()]

if re.search(r'<drf_format_suffix\w*:\w+>', self.path_regex):
tokenized_path.append('formatted')

return '_'.join(tokenized_path + [action])

def is_deprecated(self):
Expand All @@ -271,10 +274,11 @@ def _tokenize_path(self):
string=self.path,
flags=re.IGNORECASE
)
# remove path variables
path = re.sub(pattern=r'\{[\w\-]+\}', repl='', string=path)
# cleanup and tokenize remaining parts.
path = path.rstrip('/').lstrip('/').split('/')
# remove path variables and empty tokens
return [t for t in path if t and not t.startswith('{')]
return [t for t in path if t]

def _resolve_path_parameters(self, variables):
model = getattr(getattr(self.view, 'queryset', None), 'model', None)
Expand Down

0 comments on commit 8876f39

Please sign in to comment.