Skip to content

Commit

Permalink
Render response headers (#1809)
Browse files Browse the repository at this point in the history
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
  • Loading branch information
zecakeh committed Apr 30, 2024
1 parent 625999a commit 85ad0c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/internal/newsfragments/1809.clarification
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Render response headers.
18 changes: 18 additions & 0 deletions layouts/partials/openapi/render-responses.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ <h2>Responses</h2>
{{ range $code, $response := $responses }}
{{ if $response.content }}
<h3>{{$code}} response</h3>
{{/* Display defined headers */}}
{{ if $response.headers }}
{{/* build a dict mapping from name->schema, which render-object-table expects */}}
{{ $headers_dict := dict }}
{{ range $header_name,$header_props := $response.headers }}
{{/*
merge the schema at the same level as the rest of the other fields because that is
what `render-object-table` expects. Put the schema first so examples in it are
overwritten.
*/}}
{{ $header_schema := merge $header_props.schema $header_props }}
{{ $headers_dict = merge $headers_dict (dict $header_name $header_schema )}}
{{ end }}

{{/* and render the headers */}}
{{ partial "openapi/render-object-table" (dict "title" "Headers" "properties" $headers_dict) }}
{{ end }}

{{/*
A response can have several content types.
*/}}
Expand Down

0 comments on commit 85ad0c7

Please sign in to comment.