Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/components/APIRequest.astro
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<Omit<ComponentProps<typeof Code>, "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.`);
Expand Down Expand Up @@ -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 }}
/>
13 changes: 13 additions & 0 deletions src/content/docs/style-guide/components/api-request.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { APIRequest } from "~/components";
json={{
validation_default_mitigation_action: "block",
}}
code={{
mark: [5, "block"]
}}
/>

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

This field is not currently validated against the schema.

### `code`

**type:** `object`

An object of Expressive Code props, the following props are available:

- [Base Props](https://expressive-code.com/key-features/code-component/#available-props)
- [Line Marker Props](https://expressive-code.com/key-features/text-markers/#props)
- [Collapsible Sections Props](https://expressive-code.com/plugins/collapsible-sections/#props)