Skip to content

Read const when building a body from a schema - #81

Merged
MathiasWP merged 1 commit into
mainfrom
fiber-openapi-const
Aug 24, 2026
Merged

Read const when building a body from a schema#81
MathiasWP merged 1 commit into
mainfrom
fiber-openapi-const

Conversation

@MathiasWP

Copy link
Copy Markdown
Owner

"$.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 the 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.

Why it matters more than one field

const is JSON Schema 2020-12, which is what OpenAPI 3.1 uses. A literal union written as anyOf of consts is what 3.1 generators emit where 3.0 would have written an enum.

The spec this was found on has 543 consts and zero enums across 658 paths — so the enum branch 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

const is taken as the value it names, alongside example and default, in skeleton and in example_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-call now 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 bare const, and placeholders still appearing for everything else), pnpm check (0 errors), pnpm test:e2e (316 passed).

"$.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.
@MathiasWP
MathiasWP merged commit a7def54 into main Aug 24, 2026
4 checks passed
@MathiasWP
MathiasWP deleted the fiber-openapi-const branch August 24, 2026 14:22
@github-actions github-actions Bot mentioned this pull request Aug 24, 2026
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