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
…1876)

* Render added/changed in info on request and response content types

Fixes: #1774
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
Co-authored-by: Kévin Commaille <76261501+zecakeh@users.noreply.github.com>
  • Loading branch information
Johennes and zecakeh authored Jun 20, 2024
1 parent 5fbfdd6 commit 27e71ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 25 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.
5 changes: 3 additions & 2 deletions data/api/client-server/content-repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,9 @@ components:
bytes:
content:
application/octet-stream:
example: <bytes>
description: The content to be uploaded.
schema:
description: The content to be uploaded.
example: <bytes>
required: true
responses:
uploadTooLarge:
Expand Down
18 changes: 9 additions & 9 deletions layouts/partials/openapi/render-content-type.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{{/*

Render a table showing content types and their descriptions, given
two arrays with equal length:
Render a table showing content types and their descriptions, given:

* `content_types`: the content type strings

* `descriptions`: the description strings
* `content_types`: OpenAPI data specifying the content types as a dictionary of the form {string: {"schema": JsonSchema}}

*/}}

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

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

Expand All @@ -21,10 +17,14 @@
<th class="col-description">Description</th>
</tr>
</thead>
{{ range $idx, $content_type := $content_types }}
{{ range $mime, $body := $content_types }}
<tr>
<td><code>{{ $content_type }}</code></td>
<td>{{ index $descriptions $idx | markdownify -}}</td>
<td><code>{{ $mime }}</code></td>
<td>
{{ $body.schema.description | markdownify -}}
{{ if (index $body.schema "x-addedInMatrixVersion") }}{{ partial "added-in" (dict "v" (index $body.schema "x-addedInMatrixVersion")) }}{{ end -}}
{{ if (index $body.schema "x-changedInMatrixVersion") }}{{ partial "changed-in" (dict "changes_dict" (index $body.schema "x-changedInMatrixVersion")) }}{{ end -}}
</td>
</tr>
{{ end }}
</table>
Expand Down
8 changes: 1 addition & 7 deletions layouts/partials/openapi/render-request.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ <h3>Request body</h3>
{{/*
Show the content types and description.
*/}}
{{ $mimes := slice }}
{{ $descriptions := slice }}
{{ range $mime, $body := $request_body.content }}
{{ $mimes = $mimes | append $mime }}
{{ $descriptions = $descriptions | append $request_body.description }}
{{ end }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions) }}
{{ partial "openapi/render-content-type" (dict "content_types" $request_body.content) }}
{{ end }}

<h3>Request body example</h3>
Expand Down
8 changes: 1 addition & 7 deletions layouts/partials/openapi/render-responses.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,7 @@ <h3>{{$code}} response</h3>
{{/*
Show the content types and description.
*/}}
{{ $mimes := slice }}
{{ $descriptions := slice }}
{{ range $mime, $body := $response.content }}
{{ $mimes = $mimes | append $mime }}
{{ $descriptions = $descriptions | append $body.schema.description }}
{{ end }}
{{ partial "openapi/render-content-type" (dict "content_types" $mimes "descriptions" $descriptions) }}
{{ partial "openapi/render-content-type" (dict "content_types" $response.content) }}
{{ end }}
{{ end }}
{{ end }}

0 comments on commit 27e71ff

Please sign in to comment.