diff --git a/src/components/APIRequest.astro b/src/components/APIRequest.astro index 11718e0ffb6ec28..18af3c6a582fac3 100644 --- a/src/components/APIRequest.astro +++ b/src/components/APIRequest.astro @@ -1,5 +1,7 @@ --- import { z } from "astro:schema"; +import type { ComponentProps } from "astro/types"; +import { Code } from "@astrojs/starlight/components"; import { getProperty } from "dot-prop"; import { getSchema } from "~/util/api.ts"; import type { OpenAPIV3 } from "openapi-types"; @@ -17,10 +19,11 @@ const props = z parameters: z.record(z.string(), z.any()).optional(), json: z.union([Record, z.array(Record)]).optional(), form: Record.optional(), + code: z.custom, "title">>().optional(), }) .strict(); -let { path, method, parameters, json, form } = props.parse(Astro.props); +let { path, method, parameters, json, form, code } = props.parse(Astro.props); if (json && form) { throw new Error(`[APIRequest] Cannot use both "json" and "form" properties.`); @@ -171,7 +174,5 @@ const tokenGroups = operation["x-api-token-group"]; headers={headers} json={json} form={form} - code={{ - title: operation.summary, - }} + code={{ ...code, title: operation.summary }} /> diff --git a/src/content/docs/style-guide/components/api-request.mdx b/src/content/docs/style-guide/components/api-request.mdx index c679d537ae97d2b..16b566e08358838 100644 --- a/src/content/docs/style-guide/components/api-request.mdx +++ b/src/content/docs/style-guide/components/api-request.mdx @@ -21,6 +21,9 @@ import { APIRequest } from "~/components"; json={{ validation_default_mitigation_action: "block", }} + code={{ + mark: [5, "block"] + }} />