org.json_schema.contrib.generate1.1.1
expand_more
module org.json_schema.contrib.generate
- Module URI:
- package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@1.1.1#/generate.pklcontent_copy
- Pkl version:
- 0.25.0 or higher
- Source code:
- generate.pkl
- Known subtypes:
- Known usages:
- All versions:
Limitations:
- Cannot generate
not
,allOf
, oranyOf
combinators correctly due to limitations in Pkl's model.- Union types exist, but they are logically the same as
oneOf
(only one subschema can match). - Intersection types do not exist (can use this to model
allOf
).
- Union types exist, but they are logically the same as
- Doesn't generate correct types for schemas that use both
JsonSchema.properties
andJsonSchema.additionalProperties
because classes cannot contain entries (known limitation, will be addressed in a future Pkl release). Some possible workarounds:- Add a child Mapping property to represent "additional properties" and add a renderer to inline them/
- Add an option to the generator to control whether a class or a Mapping gets generated.
- Cannot generate
JsonSchema.patternProperties
fully (this is a limitation of Pkl). If there is just one pattern property, it gets generated as aMapping
. Otherwise, this falls back toDynamic
, which is the loosest constraint. - Cannot generate tuple types (this is missing in Pkl).
- Properties called
default
cannot be generated (currently a limitation of the json parser). allOf
schemas have several limitationsdefault
will only be combined when all subschemas have the same valuedeprecated
will betrue
if an only if all subschemas have it set totrue
, otherwise it will be nullreadOnly
andwriteOnly
must be identical for all subschemastype
must be identical (or null) for all subschemasconst
must be identical (or null) for all subschemas- if multiple subschemas set
multipleOf
, all must be integers format
must be identical (or null) for all subschemas- overlapping
properties
andpatternProperties
entries are merged asallOf
according to these rules - fields that accept
JsonSchema.Schema
values must all beJsonSchema
values (or null) items
must beJsonSchema
or null, notListing
<JsonSchema
>- there must be precise overlap between elements of
oneOf
andanyOf
TODO:
- Copy doc comments from a class or typealias to its usage sites if there isn't a doc comment already.
- Handle if schema root is not an object type (Example: ansible's schema root has
"type": "array"
). - Handle if schema root should be a mapping (it has
additionalProperties
orpatternProperties
set).
Sample CLI usage:
pkl eval package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@<version>#/generate.pkl \
-m . \
-p source="https://json.schemastore.org/github-action.json"
Properties(show inherited)
-
expand_morelinkhidden
The output of this module.
Defaults to all module properties rendered as either Pcf or the format specified on the command line.
Methods(show inherited)
-
-
-
-
-
-
-
-
-
expand_morelinkfunction
Returns the relative, descendent directory path between this module and
other
.Throws if no such path exists.
For example, if module
mod1
has path/dir1/mod1.pkl
, and modulemod2
has path/dir1/dir2/dir3/mod2.pkl
, thenmod1.relativePathTo(mod2)
will returnList("dir2", "dir3")
.A common use case is to compute the directory path between a template located at the root of a hierarchy (say
rootModule.pkl
) and the currently evaluated module (accessible via themodule
keyword):import "rootModule.pkl" // self-import path = rootModule.relativePathTo(module)
Generate Pkl sources from JSON Schema documents.