* Remove redundant call to resolve-allof All of the callers to resolve-additional-types already call resolve-allof (or if not, they should), so this is redundant. * Update `resolve-additional-types` to take a dict I want to add more params to this, so first make it take a dict. * `render-object-table`: take a "title" rather than a "caption" ... which means we can use the result from resolve-additional-types directly. * render-object-table: support adding an anchor to generated tables. * resolve-additional-types: generate an id for each returned type * render-event: pass an anchor_base into resolve-additional-types This means that it will generate an anchor for each type, whihc will then be passed into render-object-table and used as an `id` for the table. * render-operation: pass an anchor_base into resolve-additional-types * newsfiles
63 lines
2.3 KiB
HTML
63 lines
2.3 KiB
HTML
{{/*
|
|
|
|
Render the request part of a single HTTP API operation, given:
|
|
|
|
* `parameters`: OpenAPI/Swagger data specifying the parameters
|
|
* `path`: the path where this definition was found, to enable us to resolve "$ref"
|
|
* `anchor_base`: a prefix to add to the HTML anchors generated for each object
|
|
|
|
This template renders:
|
|
* the "simple parameters" (header, path, query parameters)
|
|
* body parameters, which may be more complex, containing nested objects
|
|
* response body examples
|
|
|
|
*/}}
|
|
|
|
{{ $parameters := .parameters }}
|
|
{{ $path := .path }}
|
|
{{ $anchor_base := .anchor_base }}
|
|
|
|
<h2>Request</h2>
|
|
|
|
{{ if $parameters }}
|
|
|
|
{{ $simple_parameters := where $parameters "in" "!=" "body"}}
|
|
{{ if $simple_parameters }}
|
|
<h3>Request parameters</h3>
|
|
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $simple_parameters "type" "header" "caption" "header parameters") }}
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $simple_parameters "type" "path" "caption" "path parameters") }}
|
|
{{ partial "openapi/render-parameters" (dict "parameters" $simple_parameters "type" "query" "caption" "query parameters") }}
|
|
|
|
{{ end }}
|
|
|
|
{{ $body_parameters := where $parameters "in" "body"}}
|
|
{{ if $body_parameters }}
|
|
<h3>Request body</h3>
|
|
|
|
{{/* at most one body param is allowed by the spec */}}
|
|
{{ $body_parameter := index $body_parameters 0 }}
|
|
{{ $schema := partial "json-schema/resolve-refs" (dict "schema" $body_parameter.schema "path" $path) }}
|
|
{{ $schema := partial "json-schema/resolve-allof" $schema }}
|
|
|
|
{{ $additional_types := partial "json-schema/resolve-additional-types" (dict "schema" $schema "anchor_base" $anchor_base) }}
|
|
{{ $additional_types = uniq $additional_types }}
|
|
{{ range $additional_types }}
|
|
{{ partial "openapi/render-object-table" . }}
|
|
{{ end }}
|
|
|
|
<h3>Request body example</h3>
|
|
|
|
{{ $example := partial "json-schema/resolve-example" $schema }}
|
|
{{ $example_json := jsonify (dict "indent" " ") $example }}
|
|
{{ $example_json = replace $example_json "\\u003c" "<" }}
|
|
{{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }}
|
|
|
|
```json
|
|
{{ $example_json }}
|
|
```
|
|
{{ end }}
|
|
|
|
{{ else }}
|
|
<p>No request parameters or request body.</p>
|
|
{{ end }}
|