From 23393ad8491973e65ace3659164285b8f5c74517 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 19 Jun 2024 08:26:56 +0200 Subject: [PATCH] Fix OpenAPI definition for request body of upload endpoints and eliminate slices by passing the whole content into the partial --- data/api/client-server/content-repo.yaml | 5 +++-- .../partials/openapi/render-content-type.html | 18 ++++++------------ layouts/partials/openapi/render-request.html | 12 +----------- layouts/partials/openapi/render-responses.html | 12 +----------- 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/data/api/client-server/content-repo.yaml b/data/api/client-server/content-repo.yaml index 038ac618..9224da86 100644 --- a/data/api/client-server/content-repo.yaml +++ b/data/api/client-server/content-repo.yaml @@ -712,8 +712,9 @@ components: bytes: content: application/octet-stream: - example: - description: The content to be uploaded. + schema: + description: The content to be uploaded. + example: required: true responses: uploadTooLarge: diff --git a/layouts/partials/openapi/render-content-type.html b/layouts/partials/openapi/render-content-type.html index 7c58ea6b..f63ba1a3 100644 --- a/layouts/partials/openapi/render-content-type.html +++ b/layouts/partials/openapi/render-content-type.html @@ -3,17 +3,11 @@ Render a table showing content types and their descriptions, given 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`: OpenAPI data specifying the content types */}} {{ $content_types := .content_types }} -{{ $descriptions := .descriptions}} -{{ $added_in := .added_in}} -{{ $changed_in := .changed_in}} {{ if (gt (len $content_types) 0) }} @@ -22,13 +16,13 @@ Content-Type Description - {{ range $idx, $content_type := $content_types }} + {{ range $mime, $body := $content_types }} - {{ $content_type }} + {{ $mime }} - {{ 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 -}} + {{ $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 -}} {{ end }} diff --git a/layouts/partials/openapi/render-request.html b/layouts/partials/openapi/render-request.html index 1fbfc96c..92811f12 100644 --- a/layouts/partials/openapi/render-request.html +++ b/layouts/partials/openapi/render-request.html @@ -50,17 +50,7 @@ {{/* Show the content types and description. */}} - {{ $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 "added_in" $added_in "changed_in" $changed_in) }} + {{ partial "openapi/render-content-type" (dict "content_types" $request_body.content) }} {{ end }}

Request body example

diff --git a/layouts/partials/openapi/render-responses.html b/layouts/partials/openapi/render-responses.html index 683d2c6c..fcd59911 100644 --- a/layouts/partials/openapi/render-responses.html +++ b/layouts/partials/openapi/render-responses.html @@ -121,17 +121,7 @@ {{/* Show the content types and description. */}} - {{ $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 "added_in" $added_in "changed_in" $changed_in) }} + {{ partial "openapi/render-content-type" (dict "content_types" $response.content) }} {{ end }} {{ end }} {{ end }}