diff --git a/lib/loom.libsonnet b/lib/loom.libsonnet index c351ce4..0f2446b 100644 --- a/lib/loom.libsonnet +++ b/lib/loom.libsonnet @@ -9,6 +9,8 @@ ||| # %(title)s + `[generated]` + ID: `%(uri)s` %(description)s @@ -26,6 +28,8 @@ weave_ref(object) else if get_type(object) == 'string' then weave_string_type(object) + else if get_type(object) == 'number' then + weave_number_type(object) else if get_type(object) == 'object' then weave_object_type(object) else if get_type(object) == 'array' then @@ -55,11 +59,32 @@ for constraint in string_constraints ]), + // Weave functions for `number` type schemas + local number_constraits = ['minimum', 'maximum'], + local weave_number_type(object) = + ||| + | Constraint | | + |-|-| + ||| + + std.join('', [ + (if std.objectHas(object, constraint) then ||| + | `%(constraint)s` | %(constraint_value)s | + ||| % { + constraint: constraint, + constraint_value: if std.type(object[constraint]) == 'string' then + std.format('`%s`', object[constraint]) + else + object[constraint], + }) + for constraint in number_constraits + ]), + // Weave fuctions for `object` type schemas local weave_object_type(object) = std.join('', [ if !std.objectHas(object.properties[property], '$ref') then ||| + --- #### **%(property)s** - `%(property_type)s` %(property_required)s @@ -69,10 +94,13 @@ %(property_type_docs)s ||| % { property: property, - property_required: if std.setMember(property, object.required) then '- *required*' else '', + property_required: if std.setMember(property, std.set(object.required)) then '- *required*' else '', property_description: object.properties[property].description, property_type: get_type(object.properties[property]), - property_type_docs: if get_type(object.properties[property]) != 'object' then weave_type(object.properties[property]), + property_type_docs: if get_type(object.properties[property]) != 'object' then + weave_type(object.properties[property]) + else std.join("\n", [ + std.format("> %s", line) for line in std.split(weave_type(object.properties[property]), "\n")]), } else ||| @@ -87,6 +115,9 @@ for property in std.objectFields(object.properties) ]), + // local weave_object_child(object) = + // "> a", + // Weave functions for `array` type schemas local weave_array_type(object) = |||