Skip to content

fix: openapi endpoint naming respect user urls path#96

Open
metaforx wants to merge 6 commits intodjango-cms:mainfrom
metaforx:fix/openapi-endpoint-naming
Open

fix: openapi endpoint naming respect user urls path#96
metaforx wants to merge 6 commits intodjango-cms:mainfrom
metaforx:fix/openapi-endpoint-naming

Conversation

@metaforx
Copy link
Collaborator

@metaforx metaforx commented Mar 12, 2026

fix #82

  • OpenAPI schema respects custom user URLs when customizing/nesting REST endpoints.

Summary by Sourcery

Bug Fixes:

  • Ensure generated OpenAPI operation IDs for menu endpoints respect custom or nested URL paths instead of using a fixed suffix.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts 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 generation

classDiagram
    class AutoSchema {
        +get_operation_id() str
        +_tokenize_path() list
    }

    class MenuSchema {
        +get_operation_id() str
    }

    AutoSchema <|-- MenuSchema
Loading

File-Level Changes

Change Details Files
Update OpenAPI operation_id generation to respect custom URL path prefixes when deriving operation IDs for menu endpoints.
  • Extend MenuSchema.get_operation_id docstring to document path-prefix-aware behavior and relation to custom mount points.
  • Compute tokenized path via _tokenize_path and derive a prefix of path segments before the first segment matching the URL name base token.
  • Normalize hyphens to underscores in both path tokens and url_name, and build the final operation_id as prefix segments + url_name + 'retrieve' joined with underscores, falling back to the superclass implementation when no url_name is available.
djangocms_rest/schemas.py

Assessment against linked issues

Issue Objective Addressed Explanation
#82 Modify OpenAPI menu operationIds so they include the app URL path prefix (e.g., cms/ produces CmsMenuLevelsRetrieve instead of MenuLevelsRetrieve).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.10%. Comparing base (7f76592) to head (ab1b8f9).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metaforx metaforx requested a review from fsbraun March 12, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenApi - Add appi urls path as prefix to menu operationIds

1 participant