Skip to content

fix(plugins): set controller of listing operations - #521

Merged
uniqueg merged 4 commits into
devfrom
fix/plugin-api-router-controller
Oct 26, 2026
Merged

uniqueg merged 4 commits into
devfrom
fix/plugin-api-router-controller

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Apps serve the plugin listing by merging foca.plugins.api.SPEC_PATH into their own spec. FOCA applies add_operation_fields after merging, so an app that sets x-openapi-router-controller there also gave it to the listing operations, whose absolute operationIds then resolved to <controller>.foca.plugins.api.listPlugins and failed to import (worker fails to boot, or 501 with resolver_error).

  • foca/plugins/api.yaml: both operations set x-openapi-router-controller: foca.plugins.api and use relative operationIds, as foca/utils/service-info.yaml already does; add_operation_fields uses setdefault, so the spec's own controller wins. The controllers and operationIds are renamed to listFocaPlugins and getFocaPlugin, so that they stay unique in merged specs.
  • Regression test test_spec_merged_with_app_controller: merges SPEC_PATH into a petstore spec with add_operation_fields: {x-openapi-router-controller: ...} and no resolver_error; fails on dev with ModuleNotFoundError: 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.
  • Full pytest locally: 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.
  • Reviewer subagents (adversarial, quality): no high or medium findings; lows fixed (generated module removed from sys.modules; operation IDs renamed to stay unique, after Sourcery and the adversarial reviewer flagged possible clashes).
  • CI: all checks passed on 8b25d55 (CI passed gate, tests with MongoDB 7.0/8.0, lint, docs, chart, integration); Sourcery check passed, both threads answered and resolved.

Declined review findings

  • Sourcery: call out the operationId change in migration notes: declined; the listing came in with feat(plugins): list plugins for clients #506 and is unreleased.
  • Commit trailer model name: the trailer follows the session's attribution instruction.

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:

  • Ensure plugin listing operations continue resolving to FOCA’s controllers when application specifications assign a controller to all operations.
  • Use unique plugin listing operation IDs to prevent collisions in merged OpenAPI specifications.

Documentation:

  • Document the plugin listing operations’ controller ownership and unique operation IDs in merged specifications.

Tests:

  • Add regression coverage for resolving plugin listing operations in specifications with application-wide controllers.

uniqueg and others added 2 commits October 26, 2026 17:36
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]>
@uniqueg uniqueg added this to the v0.18.0 milestone Oct 26, 2026
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 specification

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Make plugin-listing operations retain their own controller when an application applies operation fields to a merged OpenAPI specification.
  • Changed listing operation IDs to relative names and explicitly set the FOCA controller extension on both operations.
  • Added regression coverage for merging the plugin spec into an app spec whose operations use an application-wide controller, including authorization-protected listing requests.
  • Updated specification tests to verify relative IDs, controller metadata, and callable controller functions.
  • Documented controller precedence and the requirement that application operation IDs remain unique in the merged specification.
foca/plugins/api.yaml
tests/plugins/test_plugin_api.py
docs/plugins.md

Assessment against linked issues

Issue Objective Addressed Explanation
#515 Ensure both plugin listing operations retain the FOCA controller when merged with an app spec that adds a controller to all operations, using relative operation IDs. ✅
#515 Add a regression test that merges the plugin spec with an app spec using add_operation_fields for its controller and verifies the plugin endpoints resolve. ✅
#515 Document the plugin operations’ controller and operation ID behavior when the listing spec is merged into an app’s specification. ✅

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

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (23825a2) to head (5a0fb1b).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #521   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         6611      6611           
=========================================
  Hits          6611      6611           
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@uniqueg
uniqueg marked this pull request as ready for review October 26, 2026 17:43

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread foca/plugins/api.yaml Resolved
Comment thread foca/plugins/api.yaml Resolved
uniqueg and others added 2 commits October 26, 2026 19:21
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]>
@uniqueg
uniqueg merged commit 8444dea into dev Oct 26, 2026
30 checks passed
@uniqueg
uniqueg deleted the fix/plugin-api-router-controller branch October 26, 2026 18:45
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.

fix: plugin listing breaks with app router controller

1 participant