@ -78,20 +78,20 @@
{{ end }}
{{/*
Computes the type to display for a property, given:
Computes the type to display for a property's schema , given:
* `type`: string or array of strings for the type(s) of the property
* `type`: optional string or array of strings for the type(s) of the property
* `title`: optional string for the title of the property
* `oneOf`: optional array of dictionaries describing the different formats
that the property can have
* `additionalProperties`: optional dictionary for properties with undefined
names
* `additionalProperties`: if the type is an object, optional dictionary for
properties with undefined names
* `patternProperties`: optional dictionary for properties with names
adhering to a regex pattern
* `patternProperties`: if the type is an object, optional dictionary for
properties with names adhering to a regex pattern
* `items`: if the type is an array, array of dictionaries describing the
format of the array's items
@ -100,37 +100,59 @@
*/}}
{{ define "partials/property-type" }}
{{ $type := .type }}
{{ if or (eq .type "object") (and .oneOf (reflect.IsSlice .oneOf)) }}
{{ $type = partial "type-or-title" . }}
{{ end }}
{{ $type := "" }}
{{/*
If the property is an array, indicate this with square brackets,
like `[type]`.
*/}}
{{ if eq .type "array"}}
{{ if eq .type "object" }}
{{/* Resolve the type or title of the object */}}
{{ $type = partial "object-type-or-title" . }}
{{ else if eq .type "array"}}
{{/*
If the property is an array, indicate this with square brackets,
like `[type]`.
*/}}
{{ $items := .items }}
{{ if .items }}
{{ $items = partial "json-schema/resolve-allof" .items }}
{{ end }}
{{ $inner_type := partial "type-or-titl e" $items }}
{{ $inner_type := partial "property-typ e" $items }}
{{ $type = delimit (slice "[" $inner_type "]") "" }}
{{ else if or (reflect.IsSlice .type) .oneOf }}
{{/*
It's legal to specify an array of types.
There are two ways to do that:
- Use an array of strings.
- Use oneOf, with items having a schema.
Join them together in that case, like `type|other_type`.
*/}}
{{ $types := slice }}
{{ if .oneOf }}
{{ range .oneOf }}
{{ $types = $types | append (partial "property-type" .) }}
{{ end }}
{{ else }}
{{ range .type }}
{{ $types = $types | append . }}
{{ end }}
{{ end }}
{{ $type = delimit $types "|" }}
{{ else }}
{{/* A simple type like string or boolean */}}
{{ $type = .type }}
{{ end }}
{{ return $type }}
{{ end }}
{{/*
Computes the type to display for a property's schema, given:
Computes the type to display for an object property's schema, given:
* `type`: string or array of strings for the type(s) of the property
* `type`: string equal to "object"
* `title`: optional string for the title of the property
* `oneOf`: optional array of dictionaries describing the different formats
that the property can have
* `title`: optional string for the title of the object property
* `additionalProperties`: optional dictionary for properties with undefined
names
@ -142,8 +164,8 @@
The title has a higher priority than anything else.
*/}}
{{ define "partials/type-or-title" }}
{{ $type := "" }}
{{ define "partials/object- type-or-title" }}
{{ $type := "object " }}
{{ if .title }}
{{/*
If the property has a `title`, use that rather than `type`.
@ -176,32 +198,8 @@
{{ end }}
{{ $type = delimit (slice "{string: " (delimit $types "|") "}" ) "" }}
{{ else if reflect.IsSlice .type }}
{{/* It's legal to specify an array of types. Join them together in that case */}}
{{ $types := slice }}
{{ range .type }}
{{ $types = $types | append . }}
{{ end }}
{{ $type = delimit $types "|" }}
{{ else if and .oneOf (reflect.IsSlice .oneOf) }}
{{/*
This is like an array of types except some of the types probably have a schema.
Join them together too.
*/}}
{{ $types := slice }}
{{ range .oneOf }}
{{ $types = $types | append (partial "type-or-title" .) }}
{{ end }}
{{ $type = delimit $types "|" }}
{{ else }}
{{ $type = .type }}
{{ end }}
{{ return $type }}
{{ end }}