Skip to content

Commit

Permalink
Render added/changed in info on request and response content types
Browse files Browse the repository at this point in the history
Fixes: matrix-org#1774
Signed-off-by: Johannes Marbach <[email protected]>
  • Loading branch information
Johennes committed Jun 18, 2024
1 parent 5f47b96 commit eeca7af
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelogs/internal/newsfragments/1876.clarification
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Render added/changed in info on request and response content types.
11 changes: 9 additions & 2 deletions layouts/partials/openapi/render-content-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
two arrays with equal length:

* `content_types`: the content type strings

* `descriptions`: the description strings
* `added_in`: the "added in" version
* `changed_in`: the "changed in" dictionary

*/}}

{{ $content_types := .content_types }}
{{ $descriptions := .descriptions}}
{{ $added_in := .added_in}}
{{ $changed_in := .changed_in}}

{{ if (gt (len $content_types) 0) }}

Expand All @@ -22,7 +25,11 @@
{{ range $idx, $content_type := $content_types }}
<tr>
<td><code>{{ $content_type }}</code></td>
<td>{{ index $descriptions $idx | markdownify -}}</td>
<td>
{{ index $descriptions $idx | markdownify -}}
{{ if (index $added_in $idx) }}{{ partial "added-in" (dict "v" (index $added_in $idx)) }}{{ end -}}
{{ if (index $changed_in $idx) }}{{ partial "changed-in" (dict "changes_dict" (index $changed_in $idx)) }}{{ end -}}
</td>
</tr>
{{ end }}
</table>
Expand Down
6 changes: 5 additions & 1 deletion layouts/partials/openapi/render-request.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ <h3>Request body</h3>
*/}}
{{ $mimes := slice }}
{{ $descriptions := slice }}
{{ $added_in := slice }}
{{ $changed_in := slice }}
{{ range $mime, $body := $request_body.content }}
{{ $mimes = $mimes | append $mime }}
{{ $descriptions = $descriptions | append $request_body.description }}
{{ $added_in = $added_in | append (index $request_body "x-addedInMatrixVersion") }}
{{ $changed_in = $changed_in | append (index $request_body "x-changedInMatrixVersion") }}
{{ end }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions) }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions "added_in" $added_in "changed_in" $changed_in) }}
{{ end }}

<h3>Request body example</h3>
Expand Down
6 changes: 5 additions & 1 deletion layouts/partials/openapi/render-responses.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ <h3>{{$code}} response</h3>
*/}}
{{ $mimes := slice }}
{{ $descriptions := slice }}
{{ $added_in := slice }}
{{ $changed_in := slice }}
{{ range $mime, $body := $response.content }}
{{ $mimes = $mimes | append $mime }}
{{ $descriptions = $descriptions | append $body.schema.description }}
{{ $added_in = $added_in | append (index $body.schema "x-addedInMatrixVersion") }}
{{ $changed_in = $changed_in | append (index $body.schema "x-changedInMatrixVersion") }}
{{ end }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions) }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions "added_in" $added_in "changed_in" $changed_in) }}
{{ end }}
{{ end }}
{{ end }}

0 comments on commit eeca7af

Please sign in to comment.