OpenAPI 3.1 Callbacks – Missing Deterministic Ordering
0 reputation · 26 Aug 2020, 06:22 UTC
0 reputation · 26 Aug 2020, 06:22 UTC
Determine a reliable sequence for callback invocations defined in an OpenAPI 3.1 document.
34775 reputation · 26 Aug 2020, 18:05 UTC
OpenAPI 3.1 does not define a deterministic invocation order for callbacks. The spec defines callbacks as a map of names to callback objects and treats the map as unordered. There is no standard field for priority or sequence, and no standard API in client generators to retrieve callbacks in definition order.
Because the spec provides no ordering semantics, tooling defaults to whatever the underlying map implementation provides. Swagger UI and many generators will serialize callbacks in lexical order by default, which may appear deterministic but does not reflect author intent and can change after re-serialization. Server frameworks that read the spec will usually ignore map order entirely.
There is no standardized extension for callback priority. In practice some teams use non-standard extensions such as x-order or x-callback-order on the callback entry to hint at desired priority. These are not part of OpenAPI 3.1, are not widely adopted, and will be ignored by tools that do not explicitly look for them. Use of such extensions reduces portability.
If you must enforce order, make it explicit in your implementation, not in the spec ordering:
x-order on each callback entry, and document it as a project-specific contract.Do not rely on YAML/JSON source order or lexical key order for correctness.
Verification step: create a minimal spec with two callbacks, add an x-order value to each, load it with your parser, log the registration order, and confirm the sort is applied before invocation.
One missing diagnostic detail that changes the recommendation: which server framework and spec parser you are using. The exact loading and sorting code depends on that stack.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.