fix: openapi endpoint naming respect user urls path#96
Open
metaforx wants to merge 6 commits intodjango-cms:mainfrom
Open
fix: openapi endpoint naming respect user urls path#96metaforx wants to merge 6 commits intodjango-cms:mainfrom
metaforx wants to merge 6 commits intodjango-cms:mainfrom
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts OpenAPI operation_id generation for MenuSchema so that it incorporates the URL path prefix and better reflects custom mount points for nested REST endpoints. Class diagram for updated MenuSchema OpenAPI operation_id generationclassDiagram
class AutoSchema {
+get_operation_id() str
+_tokenize_path() list
}
class MenuSchema {
+get_operation_id() str
}
AutoSchema <|-- MenuSchema
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The logic that derives
prefixby matching the firsturl_nametoken to_tokenize_path()tokens is a bit opaque; consider extracting this into a small helper with a clear name (and possibly a brief docstring) to clarify the intended matching behavior and make future changes safer. - When no path token matches
first_name_token,prefixremains the full tokenized path; if this is intentional, it may be worth adding an inline comment to clarify that the operation_id will then be fully prefixed rather than truncated at a match.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic that derives `prefix` by matching the first `url_name` token to `_tokenize_path()` tokens is a bit opaque; consider extracting this into a small helper with a clear name (and possibly a brief docstring) to clarify the intended matching behavior and make future changes safer.
- When no path token matches `first_name_token`, `prefix` remains the full tokenized path; if this is intentional, it may be worth adding an inline comment to clarify that the operation_id will then be fully prefixed rather than truncated at a match.
## Individual Comments
### Comment 1
<location path="djangocms_rest/schemas.py" line_range="29-38" />
<code_context>
if url_name:
- return url_name.replace("-", "_") + "_retrieve"
+ tokenized_path = self._tokenize_path()
+ first_name_token = url_name.split("-")[0]
+ prefix = []
+ for token in tokenized_path:
+ if token.replace("-", "_") == first_name_token:
+ break
+ prefix.append(token.replace("-", "_"))
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Normalize `first_name_token` in the same way as tokens to keep comparisons consistent and avoid repeated work.
`first_name_token` comes from `url_name.split("-")[0]`, but path tokens are compared using `token.replace("-", "_")`. This can diverge if the first part of `url_name` has underscores or if normalization changes. Consider computing `normalized_first = first_name_token.replace("-", "_")` once and using that in the comparison to keep normalization consistent and avoid repeated `replace` calls.
```suggestion
if url_name:
tokenized_path = self._tokenize_path()
first_name_token = url_name.split("-")[0]
normalized_first = first_name_token.replace("-", "_")
prefix = []
for token in tokenized_path:
normalized_token = token.replace("-", "_")
if normalized_token == normalized_first:
break
prefix.append(normalized_token)
parts = prefix + [url_name.replace("-", "_"), "retrieve"]
return "_".join(parts)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #96 +/- ##
==========================================
+ Coverage 91.98% 92.10% +0.11%
==========================================
Files 19 19
Lines 886 899 +13
Branches 100 102 +2
==========================================
+ Hits 815 828 +13
Misses 44 44
Partials 27 27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #82
Summary by Sourcery
Bug Fixes: