fix(elm): reject null for optional non-nullable properties by schani · Pull Request #3474 · glideapps/quicktype · GitHub
Skip to content

fix(elm): reject null for optional non-nullable properties - #3474

Merged
schani merged 1 commit into
masterfrom
fix/elm-optional-null
Sep 6, 2026
Merged

fix(elm): reject null for optional non-nullable properties#3474
schani merged 1 commit into
masterfrom
fix/elm-optional-null

Conversation

@schani

@schani schani commented Sep 6, 2026

Copy link
Copy Markdown
Member

A JSON Schema optional property with a non-nullable type ("value": { "type": "string" } under additionalProperties: false) accepted an explicit {"value":null}: Elm generated optionalField "value" (Jdec.nullable Jdec.string) Nothing, so null decoded to Nothing and round-tripped as {} instead of failing. It now generates optionalField "value" (Jdec.map Just Jdec.string) Nothing, which rejects null while an absent key still yields Nothing. Nullable property types keep Jdec.nullable.

Coverage: removes optional-property.schema from Elm's skipSchema, enabling the shared fixture's three samples, including the expected-failure input optional-property.1.fail.json.

Validation: npm run build; CPUs=1 QUICKTEST=true FIXTURE=schema-elm npm run test:fixtures -- test/inputs/schema/optional-property.schema (3 files); CPUs=2 QUICKTEST=true FIXTURE=schema-elm npm run test:fixtures (87 tests); CPUs=2 QUICKTEST=true FIXTURE=elm npm run test:fixtures (57 tests, includes the array-type: array renderer-option variant); npm run lint.

Production change: 1 line added, 1 removed.

🤖 Generated with Claude Code

An optional property with a non-nullable type decoded with
`Jdec.nullable`, so an explicit `null` silently became `Nothing`.
Use `Jdec.map Just` instead: absent keys still yield `Nothing`,
but `null` is rejected.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

@schani
schani merged commit 0b98950 into master Sep 6, 2026
35 checks passed
@schani
schani deleted the fix/elm-optional-null branch September 6, 2026 14:36
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.

1 participant