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
15 changes: 12 additions & 3 deletions src/components/APIRequest.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const props = z
json: z.union([Record, z.array(Record)]).optional(),
form: Record.optional(),
code: z.custom<Omit<ComponentProps<typeof Code>, "title">>().optional(),
roles: z.union([z.boolean(), z.string()]).default(true),
})
.strict();

let { path, method, parameters, json, form, code } = props.parse(Astro.props);
let { path, method, parameters, json, form, code, roles } = props.parse(
Astro.props,
);

if (json && form) {
throw new Error(`[APIRequest] Cannot use both "json" and "form" properties.`);
Expand Down Expand Up @@ -146,11 +149,17 @@ if (jsonSchema?.required) {
}
}

const tokenGroups = operation["x-api-token-group"];
let tokenGroups = operation["x-api-token-group"];

if (typeof roles === "string") {
tokenGroups = tokenGroups?.filter((group) =>
group.toLowerCase().includes(roles.toLowerCase()),
);
}
---

{
tokenGroups && (
tokenGroups && roles && (
<Details header="Required API token permissions">
<span>
At least one of the following{" "}
Expand Down
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 @@ -24,6 +24,7 @@ import { APIRequest } from "~/components";
code={{
mark: [5, "block"],
}}
roles="Domain"
/>

<APIRequest
Expand Down Expand Up @@ -131,3 +132,15 @@ 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)

### `roles`

**type:** `string | boolean`

**default:** `true`

If set to `true`, which is the default, all API token roles will show.

If set to `false`, API token roles will not be displayed.

If set to a string, the API token roles will be filtered using it as a substring (i.e, `roles="domain"` to filter out `Account API Gateway` and only leave `Domain API Gateway`).