mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-03-26 04:54:10 +01:00
Do not assume additionalProperties is an object
Also resolve allOf of additionalProperties. Fixes names of objects refs and rendering of arrays Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
parent
5da2045cad
commit
4ca33aec90
|
|
@ -34,24 +34,6 @@
|
||||||
{{ range $property_name, $property := $properties }}
|
{{ range $property_name, $property := $properties }}
|
||||||
|
|
||||||
{{ $property := partial "json-schema/resolve-allof" $property }}
|
{{ $property := partial "json-schema/resolve-allof" $property }}
|
||||||
{{ $type := $property.type }}
|
|
||||||
|
|
||||||
{{ if or (eq $property.type "object") (and $property.oneOf (reflect.IsSlice .oneOf)) }}
|
|
||||||
{{ $type = partial "type-or-title" $property }}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{/*
|
|
||||||
If the property is an array, indicate this with square brackets,
|
|
||||||
like `[type]`.
|
|
||||||
*/}}
|
|
||||||
{{ if eq $property.type "array"}}
|
|
||||||
{{ $items := $property.items }}
|
|
||||||
{{ if $property.items }}
|
|
||||||
{{ $items = partial "json-schema/resolve-allof" $property.items }}
|
|
||||||
{{ end }}
|
|
||||||
{{ $inner_type := partial "type-or-title" $items }}
|
|
||||||
{{ $type = delimit (slice "[" $inner_type "]") "" }}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
Handle two ways of indicating "required", one for simple parameters,
|
Handle two ways of indicating "required", one for simple parameters,
|
||||||
|
|
@ -61,7 +43,7 @@
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ $property_name }}</code></td>
|
<td><code>{{ $property_name }}</code></td>
|
||||||
<td><code>{{ $type }}</code></td>
|
<td><code>{{ partial "partials/property-type" $property }}</code></td>
|
||||||
<td>
|
<td>
|
||||||
{{ if $required }}<strong>Required: </strong>{{end -}}
|
{{ if $required }}<strong>Required: </strong>{{end -}}
|
||||||
{{ $property.description | markdownify -}}
|
{{ $property.description | markdownify -}}
|
||||||
|
|
@ -77,6 +59,32 @@
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Computes the type to display for a property.
|
||||||
|
*/}}
|
||||||
|
{{ define "partials/property-type" }}
|
||||||
|
{{ $type := .type }}
|
||||||
|
|
||||||
|
{{ if or (eq .type "object") (and .oneOf (reflect.IsSlice .oneOf)) }}
|
||||||
|
{{ $type = partial "type-or-title" . }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
If the property is an array, indicate this with square brackets,
|
||||||
|
like `[type]`.
|
||||||
|
*/}}
|
||||||
|
{{ if eq .type "array"}}
|
||||||
|
{{ $items := .items }}
|
||||||
|
{{ if .items }}
|
||||||
|
{{ $items = partial "json-schema/resolve-allof" .items }}
|
||||||
|
{{ end }}
|
||||||
|
{{ $inner_type := partial "type-or-title" $items }}
|
||||||
|
{{ $type = delimit (slice "[" $inner_type "]") "" }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ return $type }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
Picks either the `title` of a property, or the `type`, to turn into the rendered type field.
|
Picks either the `title` of a property, or the `type`, to turn into the rendered type field.
|
||||||
Also handles `additionalProperties`, if no `title` is present.
|
Also handles `additionalProperties`, if no `title` is present.
|
||||||
|
|
@ -94,7 +102,8 @@
|
||||||
If the property uses `additionalProperties` to describe its
|
If the property uses `additionalProperties` to describe its
|
||||||
internal structure, handle this with a bit of recursion
|
internal structure, handle this with a bit of recursion
|
||||||
*/}}
|
*/}}
|
||||||
{{ $type = delimit (slice "{string: " (partial "type-or-title" .additionalProperties) "}" ) "" }}
|
{{ $additionalProperties := partial "json-schema/resolve-allof" .additionalProperties }}
|
||||||
|
{{ $type = delimit (slice "{string: " (partial "property-type" $additionalProperties) "}" ) "" }}
|
||||||
{{ else if reflect.IsSlice .type }}
|
{{ else if reflect.IsSlice .type }}
|
||||||
{{/* It's legal to specify an array of types. Join them together in that case */}}
|
{{/* It's legal to specify an array of types. Join them together in that case */}}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue