diff --git a/assets/scss/custom.scss b/assets/scss/custom.scss index 35b4e3dc..3e4e44c8 100644 --- a/assets/scss/custom.scss +++ b/assets/scss/custom.scss @@ -370,6 +370,10 @@ footer { width: 75%; } + .row-additional-properties { + font-style: italic; + } + } pre { diff --git a/layouts/partials/json-schema/resolve-additional-types.html b/layouts/partials/json-schema/resolve-additional-types.html index 26df52e5..fa73c1bc 100644 --- a/layouts/partials/json-schema/resolve-additional-types.html +++ b/layouts/partials/json-schema/resolve-additional-types.html @@ -88,5 +88,5 @@ but with (for example) different examples will be considered different. */}} {{ define "partials/clean-object" }} - {{ return (dict "title" .title "properties" .properties "required" .required "enum" .enum) }} + {{ return (dict "title" .title "properties" .properties "required" .required "enum" .enum "additionalProperties" .additionalProperties) }} {{ end }} diff --git a/layouts/partials/openapi/render-object-table.html b/layouts/partials/openapi/render-object-table.html index e132af30..6caca375 100644 --- a/layouts/partials/openapi/render-object-table.html +++ b/layouts/partials/openapi/render-object-table.html @@ -14,6 +14,7 @@ {{ $caption := .caption }} {{ $properties := .properties}} {{ $required := .required}} +{{ $additionalProperties := .additionalProperties }} {{ if $properties }} @@ -93,6 +94,29 @@ {{ end }} + {{/* NB: the OpenAPI spec says "Consistent with JSON Schema, additionalProperties + defaults to true." Our schemas tend to omit additionalProperties; I think we + effectively assume it defaults to false. Therefore: we only output regarding + additionalProperties if it is explicitly set (i.e. is non-nil). */}} + {{ if (ne $additionalProperties nil )}} + + + {{ if (and (reflect.IsMap $additionalProperties)) -}} + {{ if (index $additionalProperties "description") -}} +May have additional properties: {{ $additionalProperties.description }} + {{ end }} + {{/* TODO: should we handle the case where additional properties are permitted, + but must follow an explicit schema? */}} + {{ else if $additionalProperties -}} +May have additional properties. + {{ else if (not $additionalProperties) -}} + {{/* At present we don't have any schema with additionalProperties: false. + But if we ever do, let's support it. */}} +May **not** have additional properties. + {{ end }} + + + {{ end }} {{ end }} diff --git a/layouts/partials/openapi/render-request.html b/layouts/partials/openapi/render-request.html index 5e801299..345820f0 100644 --- a/layouts/partials/openapi/render-request.html +++ b/layouts/partials/openapi/render-request.html @@ -41,7 +41,7 @@ {{ $additional_types := partial "json-schema/resolve-additional-types" $schema }} {{ $additional_types = uniq $additional_types }} {{ range $additional_types }} - {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required) }} + {{ partial "openapi/render-object-table" (dict "caption" .title "properties" .properties "required" .required "additionalProperties" .additionalProperties) }} {{ end }}

Request body example