diff --git a/changelogs/client_server/newsfragments/1162.clarification b/changelogs/client_server/newsfragments/1162.clarification new file mode 100644 index 000000000..e589f114d --- /dev/null +++ b/changelogs/client_server/newsfragments/1162.clarification @@ -0,0 +1 @@ +Use the `additionalProperties` field from the OpenAPI schemas to indicate that some JSON objects permit additional arbitrary key-value pairs. diff --git a/layouts/partials/json-schema/resolve-additional-types.html b/layouts/partials/json-schema/resolve-additional-types.html index 63a15beee..e0df56f49 100644 --- a/layouts/partials/json-schema/resolve-additional-types.html +++ b/layouts/partials/json-schema/resolve-additional-types.html @@ -15,6 +15,7 @@ * required * enum * anchor: a string suitable for using as an html anchor for this object (if `anchor_base` was set, and the object has a title) + * additionalProperties: either nil, a boolean, or an OpenAPI schema object (https://swagger.io/specification/#schema-object). Note that the returned array may contain duplicate objects. @@ -101,5 +102,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 "anchor" .anchor) }} + {{ return (dict "title" .title "properties" .properties "required" .required "enum" .enum "anchor" .anchor "additionalProperties" .additionalProperties) }} {{ end }} diff --git a/layouts/partials/openapi/render-object-table.html b/layouts/partials/openapi/render-object-table.html index 7de880714..85597e142 100644 --- a/layouts/partials/openapi/render-object-table.html +++ b/layouts/partials/openapi/render-object-table.html @@ -13,11 +13,21 @@ In some cases (such as response body specifications) this isn't used, and instead properties have a `required` boolean attribute. We support this too. + * `additionalProperties`: one of + + - `false` (no additional properties are permitted); + - `true` (additional properties pairs are permitted, with no constraints); + - an OpenAPI schema object [1] (additional properties are permitted, but + with constraints on `property_data`); or + - `nil` (not specified in schema, use `true` as a default value). + + [1]: https://swagger.io/specification/#schema-object */}} {{ $title := .title }} {{ $properties := .properties}} {{ $required := .required}} +{{ $additionalProperties := .additionalProperties }} {{ if $properties }} @@ -97,6 +107,27 @@ {{ end }} + {{/* If additionalProperties is true, do nothing. + If additionalProperties is nil, treat is as the default (true) and do nothing. + If additionalProperties is false, raise a build-time error: + "Everything is extensible in Matrix unless otherwise noted". + Otherwise, it should be an OpenAPI schema object. Include the description + of that schema object, if it exists. */}} + {{ if (and (ne $additionalProperties nil) (ne $additionalProperties true)) }} + {{ if (and (reflect.IsMap $additionalProperties)) -}} + {{ if (index $additionalProperties "description") -}} +