feat(schema): optional $ref-sibling rendering (EmitRefSiblings, SkipAllOfCompounding)#47
Merged
Conversation
…llOfCompounding)
A struct field whose Go type resolves to a named model becomes a $ref.
Strict JSON-Schema-draft-4 ignores siblings of a $ref, so codescan
preserves a field's description / extensions / validations by wrapping
the reference in an allOf compound. That shape is correct but breaks
downstream consumers (e.g. go-swagger codegen) that expect a bare $ref.
Two new Options give callers control, splitting $ref siblings into two
classes — siblings-eligible (description, extensions) and compound-only
(validations, externalDocs):
- EmitRefSiblings: emit description & extensions as direct $ref siblings
({$ref, description, x-*}) instead of an allOf wrap. A validation or
externalDocs still forces a compound.
- SkipAllOfCompounding: never emit an allOf compound. Validations &
externalDocs are dropped; description & extensions too, unless
EmitRefSiblings keeps them as siblings. Each drop raises one
validate.dropped-ref-sibling diagnostic via OnDiagnostic.
DescWithRef is deprecated in favour of EmitRefSiblings but kept with its
original semantics (a no-op when EmitRefSiblings is set). All defaults
are unchanged — zero golden drift. `required:` is always preserved (a
parent-side concern, not a $ref sibling).
Includes the builder logic + diagnostic code, unit A/B tests, a tested
doc-site example (docs/examples/shaping/refsiblings), and doc updates
(schema README, doc-site options table + "Descriptions beside a $ref").
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (69.49%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #47 +/- ##
==========================================
+ Coverage 81.83% 81.89% +0.05%
==========================================
Files 80 80
Lines 7433 7468 +35
==========================================
+ Hits 6083 6116 +33
- Misses 1006 1007 +1
- Partials 344 345 +1 ☔ View full report in Codecov by Harness. |
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.
A struct field whose Go type resolves to a named model becomes a $ref. Strict JSON-Schema-draft-4 ignores siblings of a $ref, so codescan preserves a field's description / extensions / validations by wrapping the reference in an allOf compound. That shape is correct but breaks downstream consumers (e.g. go-swagger codegen) that expect a bare $ref.
Two new Options give callers control, splitting $ref siblings into two classes — siblings-eligible (description, extensions) and compound-only (validations, externalDocs):
DescWithRef is deprecated in favour of EmitRefSiblings but kept with its original semantics (a no-op when EmitRefSiblings is set). All defaults are unchanged — zero golden drift.
required:is always preserved (a parent-side concern, not a $ref sibling).Includes the builder logic + diagnostic code, unit A/B tests, a tested doc-site example (docs/examples/shaping/refsiblings), and doc updates (schema README, doc-site options table + "Descriptions beside a $ref").
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist