Repository navigation
fix(plugins): set controller of listing operations - #521
Conversation
The plugin listing spec used absolute operationIds and no x-openapi-router-controller. Apps that merge SPEC_PATH into a spec with add_operation_fields setting x-openapi-router-controller gave the listing operations their own controller, so Connexion tried to import <controller>.foca.plugins.api and failed. Set x-openapi-router-controller on both operations and use relative operationIds, so that add_operation_fields keeps them. Add a regression test that merges SPEC_PATH into such a spec. Closes #515 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the generated controller module after the regression test, and document that the listing's operation IDs are taken in merged specs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR fixes plugin listing resolution in merged application specifications by declaring the FOCA controller directly on each listing operation and using relative operation IDs, which prevents app-wide add_operation_fields from redirecting those operations to the app controller. Tests cover both the packaged metadata and the merged-spec runtime scenario, while documentation explains controller precedence and operation-ID uniqueness. Sequence diagram for plugin listing resolution in a merged app specificationsequenceDiagram
participant App as Application
participant Spec as Merged OpenAPI Spec
participant Resolver as Operation Resolver
participant Controller as foca.plugins.api
App->>Spec: Merge SPEC_PATH
App->>Spec: add_operation_fields(x-openapi-router-controller)
Spec->>Resolver: Resolve listPlugins or getPlugin
Resolver->>Controller: Import foca.plugins.api.listPlugins or getPlugin
Controller-->>Resolver: Handle plugin listing request
Resolver-->>App: Successful operation response
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #521 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 55 55
Lines 6611 6611
=========================================
Hits 6611 6611
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/plugins/api.yaml" line_range="10" />
<code_context>
get:
summary: List the plugins and presets that the caller may choose.
- operationId: foca.plugins.api.listPlugins
+ operationId: listPlugins
+ # set here, so that apps' `add_operation_fields` keep it
+ x-openapi-router-controller: foca.plugins.api
</code_context>
<issue_to_address>
**Plugin operation IDs collide**
When an app's merged API spec already uses `listPlugins` or `getPlugin`, the merged specification contains an app operation with the same ID, so the operation-ID uniqueness invariant is broken and OpenAPI consumers can generate ambiguous or colliding client operations.
Use IDs that remain unique in merged specs, or reject a merged spec containing duplicate operation IDs.
Also at `foca/plugins/api.yaml:39`.
</issue_to_address>
### Comment 2
<location path="foca/plugins/api.yaml" line_range="10" />
<code_context>
get:
summary: List the plugins and presets that the caller may choose.
- operationId: foca.plugins.api.listPlugins
+ operationId: listPlugins
+ # set here, so that apps' `add_operation_fields` keep it
+ x-openapi-router-controller: foca.plugins.api
</code_context>
<issue_to_address>
**Regenerated clients rename listing methods**
When a downstream app regenerates an OpenAPI client from the changed specification and relies on generated method names, openAPI client generators that use `operationId` for method names produce different public methods from the new IDs than from `foca.plugins.api.listPlugins` and `foca.plugins.api.getPlugin`; callers using regenerated wrappers must update their source. The docs describe the new IDs but do not call out this compatibility change.
Call out the generated-client method-name change in the next release's migration notes.
Also at `foca/plugins/api.yaml:39`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: foca/plugins/api.yaml:10, foca/plugins/api.yaml:10
Rename the listing controllers and their operation IDs to listFocaPlugins and getFocaPlugin, so that they cannot clash with the operation IDs of the app in the merged specification. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Apps serve the plugin listing by merging
foca.plugins.api.SPEC_PATHinto their own spec. FOCA appliesadd_operation_fieldsafter merging, so an app that setsx-openapi-router-controllerthere also gave it to the listing operations, whose absolute operationIds then resolved to<controller>.foca.plugins.api.listPluginsand failed to import (worker fails to boot, or501withresolver_error).foca/plugins/api.yaml: both operations setx-openapi-router-controller: foca.plugins.apiand use relative operationIds, asfoca/utils/service-info.yamlalready does;add_operation_fieldsusessetdefault, so the spec's own controller wins. The controllers and operationIds are renamed tolistFocaPluginsandgetFocaPlugin, so that they stay unique in merged specs.test_spec_merged_with_app_controller: mergesSPEC_PATHinto a petstore spec withadd_operation_fields: {x-openapi-router-controller: ...}and noresolver_error; fails ondevwithModuleNotFoundError: No module named 'petstore_controllers.foca'.docs/plugins.md: says the listing keeps its own controller and that its operation IDs are taken in the merged spec.Closes #515
Verification
pytest tests/plugins/test_plugin_api.py: 34 passed; the new test fails without the fix.pytestlocally: 2790 passed; 131 errors, all MongoDB-parametrised tests (no MongoDB running locally); CI covers them.ruff check,ruff format --check,mypy,ast-grep scan,semgrep scan --config .semgrep --error,mkdocs build --strict: pass.sys.modules; operation IDs renamed to stay unique, after Sourcery and the adversarial reviewer flagged possible clashes).CI passedgate, tests with MongoDB 7.0/8.0, lint, docs, chart, integration); Sourcery check passed, both threads answered and resolved.Declined review findings
Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Preserve plugin listing controller resolution and operation identity when merging FOCA specifications into application APIs.
Bug Fixes:
Documentation:
Tests: