Propagate schema updates into parent objects while recursing

This commit is contained in:
Richard van der Hoff 2024-02-13 22:40:24 +00:00
parent a6ae391c98
commit 3736461cd1

View file

@ -88,11 +88,15 @@
"name" (printf "%s.additional" $name) "name" (printf "%s.additional" $name)
) }} ) }}
{{ $all_objects = $res.objects }} {{ $all_objects = $res.objects }}
/* Update the top-level schema with the updated subschemas for the additionalProperties */
{{ $this_object = merge $this_object (dict "additionalProperties" $res.schema) }}
{{ end }} {{ end }}
{{ end }} {{ end }}
/* Add any nested objects referenced in this object's `patternProperties` */ /* Add any nested objects referenced in this object's `patternProperties` */
{{ if $this_object.patternProperties }} {{ if $this_object.patternProperties }}
{{ $updated_pattern_properties := dict }}
{{ range $pattern, $object := $this_object.patternProperties}} {{ range $pattern, $object := $this_object.patternProperties}}
{{ $res := partial "get-additional-objects" (dict {{ $res := partial "get-additional-objects" (dict
"this_object" $object "this_object" $object
@ -101,21 +105,32 @@
"name" (printf "%s.pattern.%s" $name $pattern) "name" (printf "%s.pattern.%s" $name $pattern)
) }} ) }}
{{ $all_objects = $res.objects }} {{ $all_objects = $res.objects }}
{{ $updated_pattern_properties = merge $updated_pattern_properties (dict $pattern $res.schema) }}
{{ end }} {{ end }}
/* Update the top-level schema with the updated subschemas for the patternProperties */
{{ $this_object = merge $this_object (dict "patternProperties" $updated_pattern_properties) }}
{{ end }} {{ end }}
/* Add any nested objects referenced in this object's `properties` */ /* Add any nested objects referenced in this object's `properties` */
{{ range $key, $property := $this_object.properties}} {{ if $this_object.properties }}
{{ $res := partial "get-additional-objects" (dict {{ $updated_properties := dict }}
"this_object" $property {{ range $key, $property := $this_object.properties}}
"all_objects" $all_objects {{ $res := partial "get-additional-objects" (dict
"anchor_base" $anchor_base "this_object" $property
"name" (printf "%s.%s" $name $key) "all_objects" $all_objects
) }} "anchor_base" $anchor_base
{{ $all_objects = $res.objects }} "name" (printf "%s.%s" $name $key)
) }}
{{ $all_objects = $res.objects }}
{{ $updated_properties = merge $updated_properties (dict $key $res.schema) }}
{{ end }}
/* Update the top-level schema with the updated subschemas for the regular properties */
{{ $this_object = merge $this_object (dict "properties" $updated_properties) }}
{{ end }} {{ end }}
/* Finally, prepend the object we were passed onto the $all_objects array */ /* Finally, prepend the updated schema for the top-level object onto the $all_objects array */
{{ $tmp := slice $this_object }} {{ $tmp := slice $this_object }}
{{ if $all_objects }} {{ if $all_objects }}
{{ $tmp = $tmp | append $all_objects }} {{ $tmp = $tmp | append $all_objects }}
@ -143,6 +158,8 @@
"name" (printf "%s.items" $name) "name" (printf "%s.items" $name)
) }} ) }}
{{ $all_objects = $res.objects }} {{ $all_objects = $res.objects }}
/* Update the top-level schema with the updated subschema for the items */
{{ $this_object = merge $this_object (dict "items" $res.schema) }}
{{ else }} {{ else }}
{{ errorf "%s is defined as an 'array' but lacks a valid 'items'" $name }} {{ errorf "%s is defined as an 'array' but lacks a valid 'items'" $name }}
{{ end }} {{ end }}