Skip to content

feat(api)!: keep operation fields set in specs - #310

Merged
uniqueg merged 3 commits into
devfrom
feat/operation-fields
Oct 19, 2026
Merged

uniqueg merged 3 commits into
devfrom
feat/operation-fields

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

add_operation_fields replaced fields that operations set themselves. For example, with x-openapi-router-controller: my_app.controllers in add_operation_fields (the usual way to route all operations), a single operation could not be routed to another controller module via its own x-openapi-router-controller. This came up in elixir-cloud-aai/cloud-registry#66, which had to re-export controllers from the configured module as a workaround.

Fields are now only added to operations that do not set them.

Breaking: fields set by operations are no longer replaced. Noted in the 0.14.0 migration guide; docstrings and the API configuration docs are updated.

Verification

  • New test test_add_operation_fields_kept (merges an addition setting the controller of one operation): fails before, passes after.
  • pytest: all pass except the 7 tests marked mongodb, which need a live MongoDB (CI runs them). ruff check, ruff format --check, mypy foca, mkdocs build --strict: pass.
  • CI: pending. Jobs with MongoDB 8.0 may fail at random until ci: test with MongoDB 7.0 by default #309 is merged (MongoDB 8.0 does not start on some runners' kernels).

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Preserve fields defined by individual operations when applying shared operation-field defaults.

Bug Fixes:

  • Preserve operation-level fields when applying configured default operation fields, allowing individual operations to override shared routing configuration.

Documentation:

  • Update API configuration documentation and the 0.14 migration guide to describe the non-overriding operation-field behavior and breaking change.

Tests:

  • Add coverage verifying operation-specific controller fields are retained while defaults apply to other operations.

add_operation_fields replaced fields that operations set themselves, so
that, e.g., single operations could not be routed to another controller
module than the one configured for all operations. Only add fields that
operations do not set.

BREAKING CHANGE: fields set by operations are no longer replaced by
add_operation_fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR changes add_operation_fields from an overwrite operation to a defaulting operation: each configured field is applied only when absent, allowing individual OpenAPI operations to retain their own values while others inherit shared defaults. Documentation and migration guidance explain the breaking behavior, and a regression test covers both preservation and default application.

Flow diagram for preserving operation-level OpenAPI fields

flowchart TD
    A[OpenAPI operation] --> B{Field already set?}
    B -->|Yes| C[Keep operation value]
    B -->|No| D[Apply add_operation_fields default]
Loading

File-Level Changes

Change Details Files
Preserve operation-level fields while applying configured defaults.
  • Replace unconditional operation updates with per-field set-if-missing behavior.
  • Continue applying shared fields to operations that do not define them.
foca/api/register_openapi.py
Document the non-overriding behavior and its breaking-change impact.
  • Update API configuration docstrings and usage guidance.
  • Update the 0.14 migration guide with the changed semantics and routing example.
foca/models/config.py
docs/configuration/api.md
docs/migration-0.14.md
Add regression coverage for operation-specific overrides and defaults.
  • Verify an operation's controller remains unchanged while another operation receives the configured controller.
tests/api/test_register_openapi.py

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 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b11cb41) to head (6b8b422).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #310   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1356      1357    +1     
=========================================
+ Hits          1356      1357    +1     
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 pushed a commit to elixir-cloud-aai/cloud-registry that referenced this pull request Oct 19, 2026
Use FOCA options proposed for 0.14.0: policy rules are set via
security.access_control.policies instead of being added in code on
startup (elixir-cloud-aai/foca#311), and the permission endpoints are
routed to their own controller module via x-openapi-router-controller
instead of being re-exported from the server module
(elixir-cloud-aai/foca#310).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review October 19, 2026 21:21

@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 reviewed your changes and they look great!

Sourcery assessment

Approved.


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

@uniqueg
uniqueg merged commit 9f0ba7c into dev Oct 19, 2026
12 of 13 checks passed
@uniqueg
uniqueg deleted the feat/operation-fields branch October 19, 2026 23:26
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.

1 participant