Skip to content

Commit 991e519

Browse files
committed
docs(json-schema): document --include-null/--no-include-null
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
1 parent 845cb31 commit 991e519

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/generators/json-schema.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,27 @@ This is what the underlying JSON-Schema looks like:
322322
323323
324324
325+
Optional slots and null
326+
^^^^^^^^^^^^^^^^^^^^^^^
327+
328+
By default, optional (non-required) slots accept an explicit JSON ``null`` in
329+
addition to their base type — the generator emits ``"type": ["string", "null"]``
330+
for an optional string slot. This is convenient for producers that serialise
331+
missing values as ``null``.
332+
333+
Some target schemas forbid explicit ``null`` on optional properties (a property
334+
must either be present with a typed value or absent). Use
335+
``--no-include-null`` to restrict optional slots to their base type:
336+
337+
.. code:: bash
338+
339+
gen-json-schema --no-include-null personinfo.yaml
340+
341+
With ``--no-include-null`` the optional string slot above is emitted as
342+
``"type": "string"``, so instance documents carrying ``"slot": null`` fail
343+
validation. The default (``--include-null``) preserves the previous behaviour.
344+
345+
325346
Patterns
326347
^^^^^^^^
327348

0 commit comments

Comments
 (0)