Skip to content

fix: return nil from open_api_operation/1 for an action without a spec - #711

Open
erszcz wants to merge 1 commit into
open-api-spex:masterfrom
erszcz:fix/open-api-operation-nil
Open

erszcz wants to merge 1 commit into
open-api-spex:masterfrom
erszcz:fix/open-api-operation-nil

Conversation

@erszcz

@erszcz erszcz commented Oct 30, 2026 •

Copy link
Copy Markdown

Fixes #712

For an action with no operation declaration, the fallback clause that OpenApiSpex.ControllerSpecs generates warned and then returned the result of IO.warn/1, which is :ok. PathItem.from_routes/1 drops only nil operations, so the action appeared in the spec as %PathItem{get: :ok}.

Changes

  • ControllerSpecs: the fallback open_api_operation/1 returns nil after the warning. This matches operation :action, false and OpenApiSpex.Controller.
  • ControllerSpecs and Controller: the injected open_api_operation/1 specs are now OpenApiSpex.Operation.t() | nil. This matches __api_operation__/2 and Operation.from_plug/2.

Tests

  • controller_specs_test.exs: the existing warning test also asserts that the result is nil.
  • path_item_test.exs: new test, from_routes skips an action without an operation spec.

Without the fix, both tests fail with :ok and %PathItem{get: :ok}. With the fix, the full suite passes (399 tests, Elixir 1.20.4 / OTP 29).

This was found when running an eqWAlizer type check on our Elixir project.


Drafted with AI assistance.

For an action with no `operation` declaration, the fallback clause that
`OpenApiSpex.ControllerSpecs` generates warned and then returned the
result of `IO.warn/1`, which is `:ok`. `PathItem.from_routes/1` drops
only `nil` operations, so such an action appeared in the spec as
`%PathItem{get: :ok}`.

The fallback now returns `nil` after the warning, as
`operation :action, false` and `OpenApiSpex.Controller` already do for
"no operation". The injected `open_api_operation/1` specs in both
modules now say `OpenApiSpex.Operation.t() | nil`, which matches
`__api_operation__/2` and `Operation.from_plug/2`.

This was found when [running an eqWAlizer type check on our Elixir project][elixir-elp].

[elixir-elp]: WhatsApp/erlang-language-platform#303
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.

ControllerSpecs: open_api_operation/1 returns :ok for an action without an operation

1 participant