Repository navigation
Write nil, not :null, in pre-encoded JSON; per-call nil_fields option - #47
Merged
Merged
Conversation
With nil_fields set to null, spectra writes JSON null as the atom :null in pre-encoded terms. Jason and JSON encode that atom as the string "null", so callers such as phoenix_spectral sent "null" strings. Spectral.encode now maps :null to nil in pre-encoded JSON results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spectral.encode/5 and encode!/5 now document and type the nil_fields: :null | :omit option, which spectra's unreleased nil-fields-per-call branch reads to choose, for one call, whether nil fields are written as null or left out. Pre-encoded results map :null to nil for this option too. spectra is taken from that branch until 0.17 is released. Its new default nil_fields setting, :omit_or_null, lets the schema of a nilable field allow null; config :spectra, :nil_fields, :omit keeps the old schema. Error context messages from spectra are now binaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover the list clause of null_to_nil with a [String.t() | nil] value, and stop claiming spectra sends charlist messages: it uses binaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andreashasse
marked this pull request as ready for review
October 31, 2026 08:06
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.
Draft: waiting for user feedback before merge and release. This is one of four aligned PRs. The Elixir ones depend on the others through git branches, so the whole set can be tried together. Nothing is released yet; the git dependencies go back to Hex versions after feedback. Depends on andreashasse/spectra#204.
config :spectra, :nil_fields, :null,Spectral.encode(..., [:pre_encoded])returned the atom:null, which Jason and Phoenix encode as the string"null". phoenix_spectral responses and ecto_spectral JSONB storage both go through that path. Pre-encoded JSON now holdsnil, in nested maps and lists too. Iodata output was already correct.Spectral.encode/5andencode!/5acceptnil_fields: :null | :omitand pass it to spectra. With global:omit,:nullraisesArgumentError, and with global:null,:omitdoes too.config :spectra, :nil_fields, :omit.mix.exstemporarily points:spectraat its PR branch.make cipasses (322 tests), and so doesmix docs.🤖 Generated with Claude Code