Skip to content

Commit 056e0bf

Browse files
authored
[Docs Site] Add roles prop to APIRequest (#23539)
1 parent 31d057d commit 056e0bf

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/components/APIRequest.astro

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ const props = z
2020
json: z.union([Record, z.array(Record)]).optional(),
2121
form: Record.optional(),
2222
code: z.custom<Omit<ComponentProps<typeof Code>, "title">>().optional(),
23+
roles: z.union([z.boolean(), z.string()]).default(true),
2324
})
2425
.strict();
2526
26-
let { path, method, parameters, json, form, code } = props.parse(Astro.props);
27+
let { path, method, parameters, json, form, code, roles } = props.parse(
28+
Astro.props,
29+
);
2730
2831
if (json && form) {
2932
throw new Error(`[APIRequest] Cannot use both "json" and "form" properties.`);
@@ -146,11 +149,17 @@ if (jsonSchema?.required) {
146149
}
147150
}
148151
149-
const tokenGroups = operation["x-api-token-group"];
152+
let tokenGroups = operation["x-api-token-group"];
153+
154+
if (typeof roles === "string") {
155+
tokenGroups = tokenGroups?.filter((group) =>
156+
group.toLowerCase().includes(roles.toLowerCase()),
157+
);
158+
}
150159
---
151160

152161
{
153-
tokenGroups && (
162+
tokenGroups && roles && (
154163
<Details header="Required API token permissions">
155164
<span>
156165
At least one of the following{" "}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { APIRequest } from "~/components";
2424
code={{
2525
mark: [5, "block"],
2626
}}
27+
roles="Domain"
2728
/>
2829

2930
<APIRequest
@@ -131,3 +132,15 @@ An object of Expressive Code props, the following props are available:
131132
- [Base Props](https://expressive-code.com/key-features/code-component/#available-props)
132133
- [Line Marker Props](https://expressive-code.com/key-features/text-markers/#props)
133134
- [Collapsible Sections Props](https://expressive-code.com/plugins/collapsible-sections/#props)
135+
136+
### `roles`
137+
138+
**type:** `string | boolean`
139+
140+
**default:** `true`
141+
142+
If set to `true`, which is the default, all API token roles will show.
143+
144+
If set to `false`, API token roles will not be displayed.
145+
146+
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`).

0 commit comments

Comments
 (0)