From e9c2532882f36cc2a746793961e1df207917ef0d Mon Sep 17 00:00:00 2001 From: Devon Grove Date: Tue, 21 Apr 2026 19:42:24 -0700 Subject: [PATCH] Render OpenAPI request/response examples from native mediaType.example Reintroduces cURL request bodies and example response JSON on the generated REST API pages. Reads route-level examples from the native OpenAPI 3 mediaType.example slot, which the upstream service spec now populates via @PulumiRouteProperty(requestExample / responseExample) text blocks (see pulumi/pulumi-service#41680). No Hugo-side synthesis: the authoritative example shape lives in the spec, rendered as-is. Co-Authored-By: Claude Opus 4.7 (1M context) --- layouts/partials/openapi/endpoint.html | 6 ++--- layouts/partials/openapi/request-example.html | 26 +++++++++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/layouts/partials/openapi/endpoint.html b/layouts/partials/openapi/endpoint.html index da9cb3be57af..37c83be4360d 100644 --- a/layouts/partials/openapi/endpoint.html +++ b/layouts/partials/openapi/endpoint.html @@ -84,9 +84,7 @@

Request Body

{{ end }} {{ end }} - {{/* Request/response examples hidden for now — revisit once example - quality is validated across the full public spec. */}} - {{/* {{ template "openapi/request-example.html" (dict "method" .method "path" .path "details" .details) }} */}} + {{ template "openapi/request-example.html" (dict "method" .method "path" .path "details" .details) }}

Responses

{{/* Split responses: inline-rendered (all 2xx + any 4xx/5xx with a JSON schema) vs. stock errors (4xx/5xx with no schema, rendered as compact chip row). */}} @@ -129,7 +127,7 @@

Responses

{{ if isset $responseDetails.content "application/json" }} {{ $schema := index $responseDetails.content "application/json" "schema" }} {{ template "openapi/response-schema.html" (dict "schema" $schema "openapi" $.openapi) }} - {{/* {{ template "openapi/examples.html" (dict "responseDetails" $responseDetails "responseCode" $responseCode "openapi" $.openapi) }} */}} + {{ template "openapi/examples.html" (dict "responseDetails" $responseDetails "responseCode" $responseCode) }} {{ end }} {{ end }} diff --git a/layouts/partials/openapi/request-example.html b/layouts/partials/openapi/request-example.html index 391434aac0a6..adf88ddd1657 100644 --- a/layouts/partials/openapi/request-example.html +++ b/layouts/partials/openapi/request-example.html @@ -16,23 +16,27 @@

Example Request

{{- $url = printf "%s?%s" $url (delimit $queryParts "&") }} {{- end }} -{{/* Build the curl command line by line. */}} +{{/* Read the request body example from the native OpenAPI 3 mediaType.example slot. */}} +{{- $bodyData := "" }} +{{- with .details.requestBody }} + {{- with index .content "application/json" }} + {{- if .example }} + {{- $bodyData = .example | jsonify (dict "indent" " ") }} + {{- end }} + {{- end }} +{{- end }} + {{- $lines := slice "curl \\" }} {{- $lines = $lines | append " -H \"Accept: application/vnd.pulumi+8\" \\" }} -{{- $lines = $lines | append " -H \"Content-Type: application/json\" \\" }} +{{- if $bodyData }} + {{- $lines = $lines | append " -H \"Content-Type: application/json\" \\" }} +{{- end }} {{- $lines = $lines | append " -H \"Authorization: token $PULUMI_ACCESS_TOKEN\" \\" }} {{- if ne $method "GET" }} {{- $lines = $lines | append (printf " --request %s \\" $method) }} {{- end }} -{{- with .details.requestBody }} - {{- $jsonContent := index .content "application/json" }} - {{- with $jsonContent }} - {{- $bodyData := "{}" }} - {{- if .example }} - {{- $bodyData = .example | jsonify }} - {{- end }} - {{- $lines = $lines | append (printf " --data '%s' \\" $bodyData) }} - {{- end }} +{{- if $bodyData }} + {{- $lines = $lines | append (printf " --data '%s' \\" $bodyData) }} {{- end }} {{- $lines = $lines | append (printf " %s" $url) }}
{{ delimit $lines "\n" }}