feat(jsonschemagen): add --include-null/--no-include-null CLI option#15
Open
jdsika wants to merge 1 commit into
Open
feat(jsonschemagen): add --include-null/--no-include-null CLI option#15jdsika wants to merge 1 commit into
jdsika wants to merge 1 commit into
Conversation
beb4eb3 to
6180ba8
Compare
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>
6180ba8 to
cbf901d
Compare
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.
Summary
Expose the existing
JsonSchemaGenerator.include_nullfield (defaultTrue) on thegen-json-schemaCLI as--include-null/--no-include-null. No generator logicchanges — the option is forwarded to the existing field.
Motivation (standards)
include_nulldecides whether an optional slot is rendered as["<type>", "null"](accepts an explicit JSON
null) or as the bare"<type>".type) — the allowed typetokens are the six primitive types (
null,boolean,object,array,number,string).nullis a value type, so atypearray is the standard mechanism fordeclaring whether an explicit
nullis an acceptable value.required) — presence/absenceof a property is a separate concern from
type.nullis a literal JSON value, distinct from an absentmember (
null≠ absent).Because
required(§6.5.3) already expresses optionality, adding"null"totypeto model "optional" overloads the value-type keyword.
--no-include-nullyields theidiomatic rendering of a non-nullable optional (
{"type": "string"}+ omission fromrequired), required for strict structural parity with normative reference schemasthat declare a bare type and forbid
null.Changes
gen-json-schema, forwarded to the existinginclude_nullgenerator field.
Backward compatibility
Default remains
include_null=True; output is byte-identical unless--no-include-nullis passed.Test
test_no_include_null_omits_null_from_optional_slots: an optional slot is["string", "null"]by default and"string"underinclude_null=False; requiredslots are unaffected.