fix(jsonschema): preserve recursive scalar unions #4

Merged
deranjer merged 2 commits from agent/fix-recursive-scalar-unions into main 2026-07-24 14:42:12 +00:00
deranjer commented 2026-07-23 23:17:49 +00:00 (Migrated from github.com)

What changed

  • Recursively flatten nested scalar anyOf/oneOf variants before determining whether a schema is a scalar union.
  • Add a regression test matching NVUE peer-group BGP timers: (integer | "none") | "auto".

Root cause

PR #3 preserved scalar unions nested inside a single-branch wrapper, but NVUE BGP peer timers have two outer branches and one of those branches is itself a scalar union. The outer schema therefore fell through to FlattenComposite, which selected the first inner string branch and discarded the integer type. This made valid integer timer values fail validation while quoted numeric strings incorrectly passed.

Impact

Generated JSON Schema now preserves all three alternatives and their numeric bounds. Integer BGP peer-group timers validate correctly; quoted numeric strings are rejected.

Validation

  • go test ./...
  • Built the CLI from this branch.
  • Validated integer peer-group timers against cached NVUE 5.12–5.15 OpenAPI specs.
  • Validated two complete Phoenix NVUE 5.13 T2 aggregate configurations.
  • Confirmed quoted numeric timer values fail validation.
## What changed - Recursively flatten nested scalar `anyOf`/`oneOf` variants before determining whether a schema is a scalar union. - Add a regression test matching NVUE peer-group BGP timers: `(integer | "none") | "auto"`. ## Root cause PR #3 preserved scalar unions nested inside a single-branch wrapper, but NVUE BGP peer timers have two outer branches and one of those branches is itself a scalar union. The outer schema therefore fell through to `FlattenComposite`, which selected the first inner string branch and discarded the integer type. This made valid integer timer values fail validation while quoted numeric strings incorrectly passed. ## Impact Generated JSON Schema now preserves all three alternatives and their numeric bounds. Integer BGP peer-group timers validate correctly; quoted numeric strings are rejected. ## Validation - `go test ./...` - Built the CLI from this branch. - Validated integer peer-group timers against cached NVUE 5.12–5.15 OpenAPI specs. - Validated two complete Phoenix NVUE 5.13 T2 aggregate configurations. - Confirmed quoted numeric timer values fail validation.
nemith (Migrated from github.com) reviewed 2026-07-24 00:00:31 +00:00
@ -31,22 +31,31 @@ func sortedProperties(s *Config) []propertyEntry {
// scalarUnionVariants returns the anyOf or oneOf variants for a scalar union,
nemith (Migrated from github.com) commented 2026-07-24 00:00:12 +00:00

Duplicate check here smells. robably need to return nil or not?

Duplicate check here smells. robably need to return nil or not?
nemith (Migrated from github.com) approved these changes 2026-07-24 14:42:06 +00:00
Sign in to join this conversation.
No description provided.