Skip to content

Fix JSON Schema generation during JsonCodec derivation#1266

Merged
plokhotnyuk merged 1 commit intozio:mainfrom
plokhotnyuk:main
Mar 24, 2026
Merged

Fix JSON Schema generation during JsonCodec derivation#1266
plokhotnyuk merged 1 commit intozio:mainfrom
plokhotnyuk:main

Conversation

@plokhotnyuk
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 24, 2026 12:49
@plokhotnyuk plokhotnyuk changed the title Fix JSON Schema generation Fix JSON Schema generation during JsonCodec derivation Mar 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@plokhotnyuk plokhotnyuk merged commit 48c8abf into zio:main Mar 24, 2026
14 checks passed
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.

2 participants