org.json_schema.contrib.generate1.1.5
expand_more
module org.json_schema.contrib.generate
- Module URI:
- package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@1.1.5#/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, oranyOfcombinators 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.propertiesandJsonSchema.additionalPropertiesbecause 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.patternPropertiesfully (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
defaultcannot be generated (currently a limitation of the json parser). allOfschemas have several limitationsdefaultwill only be combined when all subschemas have the same valuedeprecatedwill betrueif an only if all subschemas have it set totrue, otherwise it will be nullreadOnlyandwriteOnlymust be identical for all subschemastypemust be identical (or null) for all subschemasconstmust be identical (or null) for all subschemas- if multiple subschemas set
multipleOf, all must be integers formatmust be identical (or null) for all subschemas- overlapping
propertiesandpatternPropertiesentries are merged asallOfaccording to these rules - fields that accept
JsonSchema.Schemavalues must all beJsonSchemavalues (or null) itemsmust beJsonSchemaor null, notListing<JsonSchema>- there must be precise overlap between elements of
oneOfandanyOf
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
additionalPropertiesorpatternPropertiesset).
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
mod1has path/dir1/mod1.pkl, and modulemod2has 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 themodulekeyword):import "rootModule.pkl" // self-import path = rootModule.relativePathTo(module)
Generate Pkl sources from JSON Schema documents.