feat: Extended Types Support (Choice, Anonymous Records, DU Encodings)#27
Merged
panesofglass merged 2 commits intomasterfrom Feb 7, 2026
Merged
feat: Extended Types Support (Choice, Anonymous Records, DU Encodings)#27panesofglass merged 2 commits intomasterfrom
panesofglass merged 2 commits intomasterfrom
Conversation
…d DU encoding styles Implements comprehensive support for extended F# type features in JSON Schema generation: **User Stories Implemented:** - US1: Anonymous Record Support - inline object schemas with no $ref - US2: Choice Type Support - anyOf schemas for all 7 Choice variants - US3: DU Encoding Styles - InternalTag, AdjacentTag, ExternalTag, Untagged - US4: Format Annotations - already implemented (DateTime, Guid, Uri, etc.) **Core Changes:** - Added isChoiceType and analyzeChoiceType for Choice<_,_> through Choice<_,_,_,_,_,_,_> - Added isAnonymousRecord (detects <>f__AnonymousType) and analyzeAnonymousRecord - Added resolveUnionEncoding using CustomAttributeData (properties are write-only) - Updated buildCaseSchema with 4 encoding styles (InternalTag default) - Extended isInlineType to include Choice and anonymous records **NJsonSchema API:** - Added unionEncoding parameter to Generator.Create() and CreateMemoized() - Updated cache key to include UnionEncodingStyle - Fixed translateProp to copy Properties/Required for nested Object schemas **Testing:** - 181 total tests (was 172): +5 Core tests, +9 main tests - All tests pass across net8.0, net9.0, net10.0 - 100% backwards compatible - default InternalTag unchanged - New snapshot tests for all encoding styles **Backwards Compatibility:** - ✅ All 167 original tests pass byte-identical - ✅ Default UnionEncoding = InternalTag (unchanged) - ✅ API fully backwards compatible (optional parameters) - ✅ No breaking changes to schemas or behavior Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Summary
Implements comprehensive support for extended F# type features in JSON Schema generation, resolving issue #22.
Features
✅ US1: Anonymous Record Support - inline object schemas with no $ref
✅ US2: Choice Type Support - anyOf schemas for all 7 Choice variants
✅ US3: DU Encoding Styles - InternalTag, AdjacentTag, ExternalTag, Untagged
✅ US4: Format Annotations - DateTime, Guid, Uri, TimeSpan, etc.
API Changes
unionEncodingparameter toGenerator.Create()andCreateMemoized()Test Results
Example Usage
```fsharp
// Use different DU encoding styles
let gen = Generator.Create(unionEncoding = AdjacentTag)
let schema = gen typeof
// Anonymous records automatically inline
type Rec = { Details: {| Name: string; Age: int |} }
// Choice types produce anyOf schemas
type Data = { Value: Choice<string, int> }
```
🤖 Generated with Claude Code