Skip to content

feat(jsonschemagen): add --include-null/--no-include-null CLI option#15

Open
jdsika wants to merge 1 commit into
mainfrom
feat/jsonschemagen-include-null-cli
Open

feat(jsonschemagen): add --include-null/--no-include-null CLI option#15
jdsika wants to merge 1 commit into
mainfrom
feat/jsonschemagen-include-null-cli

Conversation

@jdsika

@jdsika jdsika commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Expose the existing JsonSchemaGenerator.include_null field (default True) on the
gen-json-schema CLI as --include-null/--no-include-null. No generator logic
changes — the option is forwarded to the existing field.

Motivation (standards)

include_null decides whether an optional slot is rendered as ["<type>", "null"]
(accepts an explicit JSON null) or as the bare "<type>".

  • JSON Schema Validation, draft 2019-09, §6.1.1 (type) — the allowed type
    tokens are the six primitive types (null, boolean, object, array, number,
    string). null is a value type, so a type array is the standard mechanism for
    declaring whether an explicit null is an acceptable value.
  • JSON Schema Validation, draft 2019-09, §6.5.3 (required) — presence/absence
    of a property is a separate concern from type.
  • RFC 8259, §3 (Values)null is a literal JSON value, distinct from an absent
    member (null ≠ absent).

Because required (§6.5.3) already expresses optionality, adding "null" to type
to model "optional" overloads the value-type keyword. --no-include-null yields the
idiomatic rendering of a non-nullable optional ({"type": "string"} + omission from
required), required for strict structural parity with normative reference schemas
that declare a bare type and forbid null.

Changes

  • One click option on gen-json-schema, forwarded to the existing include_null
    generator field.

Backward compatibility

Default remains include_null=True; output is byte-identical unless
--no-include-null is passed.

Test

test_no_include_null_omits_null_from_optional_slots: an optional slot is
["string", "null"] by default and "string" under include_null=False; required
slots are unaffected.

@jdsika jdsika force-pushed the feat/jsonschemagen-include-null-cli branch from beb4eb3 to 6180ba8 Compare June 18, 2026 08:23
Expose the existing JsonSchemaGenerator.include_null field on the gen-json-schema
CLI. --no-include-null forbids explicit JSON null in optional slots so optionality
is expressed only via absence from required (JSON Schema Validation 6.5.3), keeping
the bare value type (6.1.1) -- needed for strict parity with reference schemas that
forbid null. Default unchanged (include_null=True).

Tested at the CLI surface via CliRunner over scalar, multivalued, and required
slots; the standards rationale lives in the include_null field docstring.

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
@jdsika jdsika force-pushed the feat/jsonschemagen-include-null-cli branch from 6180ba8 to cbf901d Compare June 18, 2026 13:31
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