Validate generated server replies with explicit status codes - #129
Conversation
|
Thanks, the As written, the new runtime accepts only contract 4, so every stored contract-3 module fails at load, including clients and servers that never touch As far as I can tell, contract-3 code runs unchanged on this runtime. The So could const CONTRACT_VERSION = 4
# Oldest generated-code contract this runtime still serves. Raise it when a
# change removes or alters something older generated modules depend on.
const MIN_CONTRACT_VERSION = 3
function require_contract(version::Integer, generator::AbstractString)
MIN_CONTRACT_VERSION <= version <= CONTRACT_VERSION && return nothing
# ... existing error, perhaps naming the supported range
endWhat that gets us:
Test and doc changes this would need:
Downstream generators that commit their output can then set a compat floor from the contract they emit (contract 4 → Happy to push these changes to the branch if that's easier. |
|
I pushed the updates. Thanks. |
|
Thanks! Merging it now. |
Generated server handlers can now return
OpenAPI.Reply(status, body)to choose a documented status while retaining schema validation and encoding. This supports distinct typed 200/202 results, typed errors, and multiple statuses sharing one body type. Exact status takes precedence over a range and thendefault; undocumented statuses fail with a clear operation/status error. Plain results and rawHTTP.Responsereturns retain their existing behavior.Compatibility: newly generated clients and servers target contract 4. The runtime accepts contracts 3 through 4, so stored contract-3 modules continue to load and retain their behavior. Regenerate servers when adopting
Reply. Contract-4 modules require OpenAPI 1.2 or later; older runtimes still reject them at load time. Packages committing contract-4 generated output should declareOpenAPI = "1.2"compatibility.Replyaccepts final HTTP statuses 200–599 in both constructor forms. It adds no exports, dependencies, or header overrides. Generated handler comments now describe the return behavior instead of advertising a misleading union of every documented body type. A schema namedReplystill works because the wrapper is referenced throughOpenAPI.Reply.Validation:
Replyconstruction passes actual JuliaC--trim=safecompile/run on 1.12 and 1.13 with runtime code generation disabled. A separate native selector control passes exact/range/default cases. Full generated response encoding remains outside this proof: the same bounded fixture reports 153 verifier errors on unchanged main, patched plain returns, and patched explicit replies.Validation for the compatibility update: full Julia 1.10.12 and 1.12.7 suites, the small pinned corpus, native trim checks, and the strict documentation build pass locally. Contract-guard regressions cover acceptance of 3 and 4 and rejection of 1, 2, and 5. Client/server files generated from the pre-PR contract-3 code complete a live HTTP round trip on the new runtime. The actual pre-PR runtime rejects both contract-4 client and server files with its existing regeneration error.
All four hosted CI checks pass on commit
4209477: Julia 1.10, current Julia, documentation, and the OpenAPI corpus.Fixes #119.
Co-authored by Codex