Read const when building a body from a schema - #81
Merged
Conversation
"$.scope does not match any allowed schema", from an API validating against
the same document Fiber built the body from.
The field:
"scope": { "anyOf": [
{ "type": "string", "const": "once" },
{ "type": "string", "const": "always" }
]}
`skeleton` checks `example`, `default` and `enum`, then falls through to a
choice, takes the first branch, finds nothing to go on there either, and
prints the `string` placeholder. For a field whose only two legal values
are named right there in the schema.
`const` is JSON Schema 2020-12, which is what OpenAPI 3.1 uses, and a
literal union written as `anyOf` of `const`s is what 3.1 generators emit
where 3.0 would have written an `enum`. The spec this turned up on has 543
`const`s and no `enum` at all, across 658 paths — so the `enum` branch that
was there never ran once, and every literal field in that API came out as a
placeholder that could only ever be rejected.
Taken in `example_string` too, so a form field pinned to one value arrives
holding it rather than empty.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"$.scope does not match any allowed schema"— from an API validating against the same document Fiber built the body from.The field
skeletonchecksexample,defaultandenum, then falls through to the choice, takes the first branch, finds nothing to go on there either, and prints thestringplaceholder — for a field whose only two legal values are named right there.Why it matters more than one field
constis JSON Schema 2020-12, which is what OpenAPI 3.1 uses. A literal union written asanyOfofconsts is what 3.1 generators emit where 3.0 would have written anenum.The spec this was found on has 543
consts and zeroenums across 658 paths — so theenumbranch that already existed never fired once, and every literal field in that API came out as a placeholder that could only ever be rejected.Fix
constis taken as the value it names, alongsideexampleanddefault, inskeletonand inexample_string(so a form field pinned to one value arrives holding it rather than empty).Verified against the real 720 KB spec before and after —
/agent/deny-tool-callnow yields:{ "agentId": string, "seq": integer, "part": integer, "partIndex": integer, "scope": "once" }Placeholders still show what to type where the schema genuinely doesn't say; only the values the document states outright are filled in.
Testing
cargo fmt --check,cargo clippy --no-default-features --all-targets -- -D warnings,cargo test(134 passed, 1 new covering a choice-of-consts, a bareconst, and placeholders still appearing for everything else),pnpm check(0 errors),pnpm test:e2e(316 passed).