Fix JSON Schema generation during JsonCodec derivation#1266
Merged
plokhotnyuk merged 1 commit intozio:mainfrom Mar 24, 2026
Merged
Fix JSON Schema generation during JsonCodec derivation#1266plokhotnyuk merged 1 commit intozio:mainfrom
JsonCodec derivation#1266plokhotnyuk merged 1 commit intozio:mainfrom
Conversation
JsonCodec derivation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts JSON Schema generation to better reflect the actual decoding/encoding semantics of the JSON codecs (notably: tuples are fixed-length, and collections/maps treat null as empty), and improves variant/union schema output.
Changes:
- Update derived JSON Schemas for
Unit, tuples, collections, and maps (e.g.,maxProperties = 0, fixed-length tuples, nullable array/object unions). - Add discriminator-related schema support for field-discriminated variants and adjust schema analysis order in
JsonSchemaToReflect. - Update test expectations to match the new generated JSON Schema shapes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| schema/shared/src/test/scala/zio/blocks/schema/json/SchemaToJsonSchemaSpec.scala | Updates schema assertions (e.g., nullable array/object types, maxProperties = 0). |
| schema/shared/src/test/scala/zio/blocks/schema/json/JsonCodecToJsonSchemaSpec.scala | Mirrors updated assertions for codec-derived schemas. |
| schema/shared/src/test/scala/zio/blocks/schema/json/JsonTestUtils.scala | Minor local rename in test helper logic. |
| schema/shared/src/test/scala/zio/blocks/schema/json/JsonCodecDeriverSpec.scala | Adds safety note for string-parsed BigInt/BigDecimal decoding in tests. |
| schema/shared/src/main/scala/zio/blocks/schema/json/JsonSchemaToReflect.scala | Reorders schema-shape analysis to detect sequences/maps earlier. |
| schema/shared/src/main/scala/zio/blocks/schema/json/JsonSchema.scala | Changes withNullable handling and adds withDiscriminatorField helper. |
| schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodecDeriver.scala | Updates JSON Schema emission for tuples/records/variants/collections/maps (titles, null unions, fixed-length tuples, discriminator injection). |
| schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodec.scala | Adjusts Unit JSON Schema to use maxProperties = 0 and removes unused import. |
schema/shared/src/main/scala/zio/blocks/schema/json/JsonSchema.scala
Outdated
Show resolved
Hide resolved
schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodecDeriver.scala
Show resolved
Hide resolved
schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodecDeriver.scala
Show resolved
Hide resolved
schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodecDeriver.scala
Show resolved
Hide resolved
schema/shared/src/main/scala/zio/blocks/schema/json/JsonSchema.scala
Outdated
Show resolved
Hide resolved
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.
No description provided.