Skip to content

Commit 64426ad

Browse files
committed
[Docs Site] Support EC props in APIRequest
1 parent f10a390 commit 64426ad

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/APIRequest.astro

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
import { z } from "astro:schema";
3+
import type { ComponentProps } from "astro/types";
4+
import { Code } from "@astrojs/starlight/components";
35
import { getProperty } from "dot-prop";
46
import { getSchema } from "~/util/api.ts";
57
import type { OpenAPIV3 } from "openapi-types";
@@ -17,10 +19,11 @@ const props = z
1719
parameters: z.record(z.string(), z.any()).optional(),
1820
json: z.union([Record, z.array(Record)]).optional(),
1921
form: Record.optional(),
22+
code: z.custom<Omit<ComponentProps<typeof Code>, "title">>().optional(),
2023
})
2124
.strict();
2225
23-
let { path, method, parameters, json, form } = props.parse(Astro.props);
26+
let { path, method, parameters, json, form, code } = props.parse(Astro.props);
2427
2528
if (json && form) {
2629
throw new Error(`[APIRequest] Cannot use both "json" and "form" properties.`);
@@ -171,7 +174,5 @@ const tokenGroups = operation["x-api-token-group"];
171174
headers={headers}
172175
json={json}
173176
form={form}
174-
code={{
175-
title: operation.summary,
176-
}}
177+
code={{ ...code, title: operation.summary }}
177178
/>

src/content/docs/style-guide/components/api-request.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { APIRequest } from "~/components";
2121
json={{
2222
validation_default_mitigation_action: "block",
2323
}}
24+
code={{
25+
mark: [5, "block"]
26+
}}
2427
/>
2528

2629
<APIRequest
@@ -116,3 +119,13 @@ If required properties are missing, the component will throw an error.
116119
The FormData payload to send.
117120

118121
This field is not currently validated against the schema.
122+
123+
### `code`
124+
125+
**type:** `object`
126+
127+
An object of Expressive Code props, the following props are available:
128+
129+
- [Base Props](https://expressive-code.com/key-features/code-component/#available-props)
130+
- [Line Marker Props](https://expressive-code.com/key-features/text-markers/#props)
131+
- [Collapsible Sections Props](https://expressive-code.com/plugins/collapsible-sections/#props)

0 commit comments

Comments
 (0)