loom improvements

trunk
HeNine 2 years ago
parent 0151eb5386
commit d8afc56274

@ -9,6 +9,8 @@
||| |||
# %(title)s # %(title)s
`[generated]`
ID: `%(uri)s` ID: `%(uri)s`
%(description)s %(description)s
@ -26,6 +28,8 @@
weave_ref(object) weave_ref(object)
else if get_type(object) == 'string' then else if get_type(object) == 'string' then
weave_string_type(object) weave_string_type(object)
else if get_type(object) == 'number' then
weave_number_type(object)
else if get_type(object) == 'object' then else if get_type(object) == 'object' then
weave_object_type(object) weave_object_type(object)
else if get_type(object) == 'array' then else if get_type(object) == 'array' then
@ -55,11 +59,32 @@
for constraint in string_constraints 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 // Weave fuctions for `object` type schemas
local weave_object_type(object) = local weave_object_type(object) =
std.join('', [ std.join('', [
if !std.objectHas(object.properties[property], '$ref') then if !std.objectHas(object.properties[property], '$ref') then
||| |||
--- ---
#### **%(property)s** - `%(property_type)s` %(property_required)s #### **%(property)s** - `%(property_type)s` %(property_required)s
@ -69,10 +94,13 @@
%(property_type_docs)s %(property_type_docs)s
||| % { ||| % {
property: property, 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_description: object.properties[property].description,
property_type: get_type(object.properties[property]), 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 else
||| |||
@ -87,6 +115,9 @@
for property in std.objectFields(object.properties) for property in std.objectFields(object.properties)
]), ]),
// local weave_object_child(object) =
// "> a",
// Weave functions for `array` type schemas // Weave functions for `array` type schemas
local weave_array_type(object) = local weave_array_type(object) =
||| |||

Loading…
Cancel
Save