OpenAPI: Support custom authorization field

This commit is contained in:
fuma-nama
2024-07-27 13:02:50 +08:00
parent 25b849f71a
commit 40728a125e
10 changed files with 191 additions and 144 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': minor
---
Support custom authorization field
+2 -1
View File
@@ -46,6 +46,8 @@ export async function renderOperation(
}
if (method.description) info.push(p(method.description));
info.push(renderPlayground(path, method, ctx));
if (security) {
info.push(heading(level, 'Authorization'));
info.push(getAuthSection(security, ctx));
@@ -112,7 +114,6 @@ export async function renderOperation(
}
info.push(getResponseTable(method));
info.push(renderPlayground(path, method, ctx));
const samples: CodeSample[] = dedupe([
{
+92 -51
View File
@@ -1,8 +1,20 @@
import { type HTMLAttributes, useMemo, useRef, useState } from 'react';
import { useForm } from 'react-hook-form';
import {
type ReactElement,
type HTMLAttributes,
useMemo,
useRef,
useState,
type ReactNode,
} from 'react';
import { Controller, useForm } from 'react-hook-form';
import useSWRImmutable from 'swr/immutable';
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
import { cn, buttonVariants } from 'fumadocs-ui/components/api';
import type {
UseFormStateReturn,
ControllerFieldState,
ControllerRenderProps,
} from 'react-hook-form';
import { useApiContext } from '@/ui/contexts/api';
import { Form } from '@/ui/components/form';
import { createBodyFromValue, getStatusInfo } from '@/ui/fetcher';
@@ -12,12 +24,24 @@ import type { APIPlaygroundProps } from '@/render/playground';
import { CodeBlock } from '@/ui/components/codeblock';
import { type DynamicField, SchemaContext } from './contexts/schema';
interface APIPlaygroundFormData {
authorization?: string | undefined;
path?: Record<string, string>;
query?: Record<string, string>;
header?: Record<string, string>;
body?: Record<string, unknown>;
interface FormValues {
authorization: string;
path: Record<string, unknown>;
query: Record<string, unknown>;
header: Record<string, unknown>;
body: unknown;
}
interface CustomField<TName extends keyof FormValues> {
render: ({
field,
fieldState,
formState,
}: {
field: ControllerRenderProps<FormValues, TName>;
fieldState: ControllerFieldState;
formState: UseFormStateReturn<FormValues>;
}) => ReactElement;
}
export function APIPlayground({
@@ -28,12 +52,17 @@ export function APIPlayground({
header = [],
query = [],
body,
fields: { auth } = {},
schemas,
}: APIPlaygroundProps & HTMLAttributes<HTMLFormElement>): React.ReactElement {
}: APIPlaygroundProps & {
fields?: {
auth?: CustomField<'authorization'>;
};
} & HTMLAttributes<HTMLFormElement>): React.ReactElement {
const { baseUrl } = useApiContext();
const dynamicRef = useRef(new Map<string, DynamicField>());
const [input, setInput] = useState<APIPlaygroundFormData>();
const form = useForm({
const [input, setInput] = useState<FormValues>();
const form = useForm<FormValues>({
defaultValues: {
authorization: authorization?.defaultValue,
path: getDefaultValues(path, schemas),
@@ -49,16 +78,18 @@ export function APIPlayground({
if (!input) return;
let pathname = route;
Object.keys(input.path ?? {}).forEach((key) => {
const paramValue = input.path?.[key];
Object.keys(input.path).forEach((key) => {
const paramValue = input.path[key];
if (paramValue) pathname = pathname.replace(`{${key}}`, paramValue);
if (typeof paramValue === 'string')
pathname = pathname.replace(`{${key}}`, paramValue);
});
const url = new URL(pathname, baseUrl ?? window.location.origin);
Object.keys(input.query ?? {}).forEach((key) => {
const paramValue = input.query?.[key];
if (paramValue) url.searchParams.append(key, paramValue);
Object.keys(input.query).forEach((key) => {
const paramValue = input.query[key];
if (typeof paramValue === 'string')
url.searchParams.append(key, paramValue);
});
const headers = new Headers({
@@ -69,10 +100,10 @@ export function APIPlayground({
headers.append('Authorization', input.authorization);
}
Object.keys(input.header ?? {}).forEach((key) => {
const paramValue = input.header?.[key];
Object.keys(input.header).forEach((key) => {
const paramValue = input.header[key];
if (paramValue) headers.append(key, paramValue);
if (typeof paramValue === 'string') headers.append(key, paramValue);
});
const bodyValue =
@@ -94,14 +125,24 @@ export function APIPlayground({
},
);
const statusInfo = testQuery.data
? getStatusInfo(testQuery.data.status)
: undefined;
const onSubmit = form.handleSubmit((value) => {
setInput(value as APIPlaygroundFormData);
setInput(value);
});
let authField: ReactNode | undefined;
if (authorization) {
authField = auth ? (
<Controller render={auth.render} name="authorization" />
) : (
<InputField
name="Authorization"
fieldName="authorization"
field={authorization}
/>
);
}
return (
<Form {...form}>
<SchemaContext.Provider
@@ -128,15 +169,7 @@ export function APIPlayground({
</div>
<Accordions type="multiple" className="-m-4 mt-2 border-0 text-sm">
{authorization ? (
<Accordion title="Authorization">
<InputField
name="Authorization"
fieldName="authorization"
field={authorization}
/>
</Accordion>
) : null}
{authField}
{path.length > 0 ? (
<Accordion title="Path">
@@ -190,25 +223,33 @@ export function APIPlayground({
) : null}
</Accordions>
{testQuery.data && statusInfo ? (
<div className="flex flex-col gap-3 rounded-lg border bg-fd-card p-4">
<div className="inline-flex items-center gap-1.5 text-sm font-medium text-fd-foreground">
<statusInfo.icon className={cn('size-4', statusInfo.color)} />
{statusInfo.description}
</div>
<p className="text-sm text-fd-muted-foreground">
{testQuery.data.status}
</p>
{testQuery.data.data ? (
<CodeBlock
code={JSON.stringify(testQuery.data.data, null, 2)}
className="max-h-[288px]"
/>
) : null}
</div>
) : null}
{testQuery.data ? <ResultDisplay data={testQuery.data} /> : null}
</form>
</SchemaContext.Provider>
</Form>
);
}
function ResultDisplay({
data,
}: {
data: { status: number; data: unknown };
}): ReactElement {
const statusInfo = useMemo(() => getStatusInfo(data.status), [data.status]);
return (
<div className="flex flex-col gap-3 rounded-lg border bg-fd-card p-4">
<div className="inline-flex items-center gap-1.5 text-sm font-medium text-fd-foreground">
<statusInfo.icon className={cn('size-4', statusInfo.color)} />
{statusInfo.description}
</div>
<p className="text-sm text-fd-muted-foreground">{data.status}</p>
{data.data ? (
<CodeBlock
code={JSON.stringify(data.data, null, 2)}
className="max-h-[288px]"
/>
) : null}
</div>
);
}
+20 -20
View File
@@ -16,6 +16,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
Return a list of upcoming special events at the museum.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/special-events"} path={[]} query={[{"name":"startDate","type":"string","defaultValue":"2023-02-23","isRequired":false},{"name":"endDate","type":"string","defaultValue":"2023-04-18","isRequired":false},{"name":"page","type":"number","defaultValue":2,"isRequired":false},{"name":"limit","type":"number","defaultValue":15,"isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -74,10 +78,6 @@ The number of days per page.
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/special-events"} path={[]} query={[{"name":"startDate","type":"string","defaultValue":"2023-02-23","isRequired":false},{"name":"endDate","type":"string","defaultValue":"2023-04-18","isRequired":false},{"name":"page","type":"number","defaultValue":2,"isRequired":false},{"name":"limit","type":"number","defaultValue":15,"isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -185,6 +185,10 @@ export type Response = {
Creates a new special event for the museum.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/special-events"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload for creating new special events at the museum.","properties":{"name":{"type":"ref","isRequired":true,"schema":"0"},"location":{"type":"ref","isRequired":true,"schema":"1"},"eventDescription":{"type":"ref","isRequired":true,"schema":"2"},"dates":{"type":"ref","isRequired":true,"schema":"3"},"price":{"type":"ref","isRequired":true,"schema":"5"}}}} schemas={{"0":{"type":"string","defaultValue":"Pirate Coding Workshop","isRequired":false,"description":"Name of the special event"},"1":{"type":"string","defaultValue":"Computer Room","isRequired":false,"description":"Location where the special event is held"},"2":{"type":"string","defaultValue":"Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).","isRequired":false,"description":"Description of the special event"},"3":{"type":"array","description":"List of planned dates for the special event","isRequired":false,"items":"4"},"4":{"type":"string","defaultValue":"2023-10-29","isRequired":false},"5":{"type":"number","defaultValue":25,"isRequired":false,"description":"Price of a ticket for the special event"}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -241,10 +245,6 @@ Price of a ticket for the special event
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/special-events"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload for creating new special events at the museum.","properties":{"name":{"type":"ref","isRequired":true,"schema":"0"},"location":{"type":"ref","isRequired":true,"schema":"1"},"eventDescription":{"type":"ref","isRequired":true,"schema":"2"},"dates":{"type":"ref","isRequired":true,"schema":"3"},"price":{"type":"ref","isRequired":true,"schema":"5"}}}} schemas={{"0":{"type":"string","defaultValue":"Pirate Coding Workshop","isRequired":false,"description":"Name of the special event"},"1":{"type":"string","defaultValue":"Computer Room","isRequired":false,"description":"Location where the special event is held"},"2":{"type":"string","defaultValue":"Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).","isRequired":false,"description":"Description of the special event"},"3":{"type":"array","description":"List of planned dates for the special event","isRequired":false,"items":"4"},"4":{"type":"string","defaultValue":"2023-10-29","isRequired":false},"5":{"type":"number","defaultValue":25,"isRequired":false,"description":"Price of a ticket for the special event"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -359,6 +359,10 @@ export interface Response {
Get details about a special event.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -385,10 +389,6 @@ An identifier for a special event.
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -494,6 +494,10 @@ export interface Response {
Update the details of a special event
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"PATCH"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload for updating an existing special event. Only included fields are updated in the event.","properties":{"name":{"type":"ref","isRequired":false,"schema":"0"},"location":{"type":"ref","isRequired":false,"schema":"1"},"eventDescription":{"type":"ref","isRequired":false,"schema":"2"},"dates":{"type":"ref","isRequired":false,"schema":"3"},"price":{"type":"ref","isRequired":false,"schema":"5"}}}} schemas={{"0":{"type":"string","defaultValue":"Pirate Coding Workshop","isRequired":false,"description":"Name of the special event"},"1":{"type":"string","defaultValue":"Computer Room","isRequired":false,"description":"Location where the special event is held"},"2":{"type":"string","defaultValue":"Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).","isRequired":false,"description":"Description of the special event"},"3":{"type":"array","description":"List of planned dates for the special event","isRequired":false,"items":"4"},"4":{"type":"string","defaultValue":"2023-10-29","isRequired":false},"5":{"type":"number","defaultValue":25,"isRequired":false,"description":"Price of a ticket for the special event"}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -562,10 +566,6 @@ An identifier for a special event.
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"PATCH"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload for updating an existing special event. Only included fields are updated in the event.","properties":{"name":{"type":"ref","isRequired":false,"schema":"0"},"location":{"type":"ref","isRequired":false,"schema":"1"},"eventDescription":{"type":"ref","isRequired":false,"schema":"2"},"dates":{"type":"ref","isRequired":false,"schema":"3"},"price":{"type":"ref","isRequired":false,"schema":"5"}}}} schemas={{"0":{"type":"string","defaultValue":"Pirate Coding Workshop","isRequired":false,"description":"Name of the special event"},"1":{"type":"string","defaultValue":"Computer Room","isRequired":false,"description":"Location where the special event is held"},"2":{"type":"string","defaultValue":"Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).","isRequired":false,"description":"Description of the special event"},"3":{"type":"array","description":"List of planned dates for the special event","isRequired":false,"items":"4"},"4":{"type":"string","defaultValue":"2023-10-29","isRequired":false},"5":{"type":"number","defaultValue":25,"isRequired":false,"description":"Price of a ticket for the special event"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -680,6 +680,10 @@ export interface Response {
Delete a special event from the collection. Allows museum to cancel planned events.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"DELETE"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -707,10 +711,6 @@ An identifier for a special event.
| `401` | Unauthorized |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"DELETE"} route={"/special-events/{eventId}"} path={[{"name":"eventId","type":"string","defaultValue":"dad4bce8-f5cb-4078-a211-995864315e39","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -16,6 +16,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
Get upcoming museum operating hours
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/museum-hours"} path={[]} query={[{"name":"startDate","type":"string","defaultValue":"2023-02-23","isRequired":false},{"name":"page","type":"number","defaultValue":2,"isRequired":false},{"name":"limit","type":"number","defaultValue":15,"isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -64,10 +68,6 @@ The number of days per page.
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/museum-hours"} path={[]} query={[{"name":"startDate","type":"string","defaultValue":"2023-02-23","isRequired":false},{"name":"page","type":"number","defaultValue":2,"isRequired":false},{"name":"limit","type":"number","defaultValue":15,"isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
+8 -8
View File
@@ -16,6 +16,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
Purchase museum tickets for general entry or special events.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/tickets"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload used for purchasing museum tickets.","properties":{"ticketType":{"type":"ref","isRequired":true,"schema":"0"},"eventId":{"type":"ref","isRequired":false,"schema":"1"},"ticketDate":{"type":"ref","isRequired":true,"schema":"2"},"email":{"type":"ref","isRequired":true,"schema":"3"},"phone":{"type":"ref","isRequired":false,"schema":"4"}}}} schemas={{"0":{"type":"string","defaultValue":"event","isRequired":false,"description":"Type of ticket being purchased. Use `general` for regular museum entry and `event` for tickets to special events."},"1":{"type":"string","defaultValue":"3be6453c-03eb-4357-ae5a-984a0e574a54","isRequired":false,"description":"Identifier for a special event."},"2":{"type":"string","defaultValue":"2023-10-29","isRequired":false,"description":"Date that the ticket is valid for."},"3":{"type":"string","defaultValue":"[email protected]","isRequired":false,"description":"Email address for ticket purchaser."},"4":{"type":"string","defaultValue":"+1(234)-567-8910","isRequired":false,"description":"Phone number for the ticket purchaser (optional)."}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -80,10 +84,6 @@ Phone number for the ticket purchaser (optional).
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/tickets"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"description":"Request payload used for purchasing museum tickets.","properties":{"ticketType":{"type":"ref","isRequired":true,"schema":"0"},"eventId":{"type":"ref","isRequired":false,"schema":"1"},"ticketDate":{"type":"ref","isRequired":true,"schema":"2"},"email":{"type":"ref","isRequired":true,"schema":"3"},"phone":{"type":"ref","isRequired":false,"schema":"4"}}}} schemas={{"0":{"type":"string","defaultValue":"event","isRequired":false,"description":"Type of ticket being purchased. Use `general` for regular museum entry and `event` for tickets to special events."},"1":{"type":"string","defaultValue":"3be6453c-03eb-4357-ae5a-984a0e574a54","isRequired":false,"description":"Identifier for a special event."},"2":{"type":"string","defaultValue":"2023-10-29","isRequired":false,"description":"Date that the ticket is valid for."},"3":{"type":"string","defaultValue":"[email protected]","isRequired":false,"description":"Email address for ticket purchaser."},"4":{"type":"string","defaultValue":"+1(234)-567-8910","isRequired":false,"description":"Phone number for the ticket purchaser (optional)."}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -194,6 +194,10 @@ export interface Response {
Return an image of your ticket with scannable QR code. Used for event entry.
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/tickets/{ticketId}/qr"} path={[{"name":"ticketId","type":"string","defaultValue":"a54a57ca-36f8-421b-a6b4-2e8f26858a4c","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Basic <token>"} required={true}>
@@ -220,10 +224,6 @@ An identifier for a ticket to a museum event. Used to generate ticket image.
| `400` | Bad request |
| `404` | Not found |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Basic","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/tickets/{ticketId}/qr"} path={[{"name":"ticketId","type":"string","defaultValue":"a54a57ca-36f8-421b-a6b4-2e8f26858a4c","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
+12 -12
View File
@@ -13,6 +13,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
## List all pets
<APIPlayground authorization={undefined} method={"GET"} route={"/pets"} path={[]} query={[{"name":"limit","type":"number","defaultValue":"","isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Query Parameters
<Property name={"limit"} type={"integer"} required={false} deprecated={false}>
@@ -30,10 +34,6 @@ How many items to return at one time (max 100)
| `200` | A paged array of pets |
| `default` | unexpected error |
<APIPlayground authorization={undefined} method={"GET"} route={"/pets"} path={[]} query={[{"name":"limit","type":"number","defaultValue":"","isRequired":false}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -141,6 +141,10 @@ export interface Response {
## Create a pet
<APIPlayground authorization={undefined} method={"POST"} route={"/pets"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"id":{"type":"ref","isRequired":true,"schema":"0"},"name":{"type":"ref","isRequired":true,"schema":"1"},"tag":{"type":"ref","isRequired":false,"schema":"2"}}}} schemas={{"0":{"type":"number","defaultValue":"","isRequired":false},"1":{"type":"string","defaultValue":"","isRequired":false},"2":{"type":"string","defaultValue":"","isRequired":false}}}>
</APIPlayground>
### Request Body
<Property name={"id"} type={"integer"} required={true} deprecated={undefined}>
@@ -162,10 +166,6 @@ export interface Response {
| `201` | Null response |
| `default` | unexpected error |
<APIPlayground authorization={undefined} method={"POST"} route={"/pets"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"id":{"type":"ref","isRequired":true,"schema":"0"},"name":{"type":"ref","isRequired":true,"schema":"1"},"tag":{"type":"ref","isRequired":false,"schema":"2"}}}} schemas={{"0":{"type":"number","defaultValue":"","isRequired":false},"1":{"type":"string","defaultValue":"","isRequired":false},"2":{"type":"string","defaultValue":"","isRequired":false}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -241,6 +241,10 @@ export interface Response {
## Info for a specific pet
<APIPlayground authorization={undefined} method={"GET"} route={"/pets/{petId}"} path={[{"name":"petId","type":"string","defaultValue":"","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Path Parameters
<Property name={"petId"} type={"string"} required={true} deprecated={false}>
@@ -254,10 +258,6 @@ The id of the pet to retrieve
| `200` | Expected response to a valid request |
| `default` | unexpected error |
<APIPlayground authorization={undefined} method={"GET"} route={"/pets/{petId}"} path={[{"name":"petId","type":"string","defaultValue":"","isRequired":true}]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
+16 -16
View File
@@ -13,6 +13,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
## Get Api
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/apis.getApi"} path={[]} query={[{"name":"apiId","type":"string","defaultValue":"api_1234","isRequired":true,"description":"The id of the api to fetch"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -44,10 +48,6 @@ The id of the api to fetch
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/apis.getApi"} path={[]} query={[{"name":"apiId","type":"string","defaultValue":"api_1234","isRequired":true,"description":"The id of the api to fetch"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -479,6 +479,10 @@ export interface Response {
## Create Api
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/apis.createApi"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"name":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"my-api","isRequired":false,"description":"The name for your API. This is not customer facing."}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -510,10 +514,6 @@ The name for your API. This is not customer facing.
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/apis.createApi"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"name":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"my-api","isRequired":false,"description":"The name for your API. This is not customer facing."}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -938,6 +938,10 @@ export interface Response {
## List Keys
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/apis.listKeys"} path={[]} query={[{"name":"apiId","type":"string","defaultValue":"api_1234","isRequired":true,"description":"The id of the api to fetch"},{"name":"limit","type":"number","defaultValue":100,"isRequired":false,"description":"The maximum number of keys to return"},{"name":"cursor","type":"string","defaultValue":"","isRequired":false,"description":"Use this to fetch the next page of results. A new cursor will be returned in the response if there are more results."},{"name":"ownerId","type":"string","defaultValue":"","isRequired":false,"description":"If provided, this will only return keys where the `ownerId` matches."}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -997,10 +1001,6 @@ If provided, this will only return keys where the `ownerId` matches.
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/apis.listKeys"} path={[]} query={[{"name":"apiId","type":"string","defaultValue":"api_1234","isRequired":true,"description":"The id of the api to fetch"},{"name":"limit","type":"number","defaultValue":100,"isRequired":false,"description":"The maximum number of keys to return"},{"name":"cursor","type":"string","defaultValue":"","isRequired":false,"description":"Use this to fetch the next page of results. A new cursor will be returned in the response if there are more results."},{"name":"ownerId","type":"string","defaultValue":"","isRequired":false,"description":"If provided, this will only return keys where the `ownerId` matches."}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -1559,6 +1559,10 @@ export interface Response {
## Delete Api
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/apis.deleteApi"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"api_1234","isRequired":false,"description":"The id of the api to delete"}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -1590,10 +1594,6 @@ The id of the api to delete
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/apis.deleteApi"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"api_1234","isRequired":false,"description":"The id of the api to delete"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
+28 -28
View File
@@ -13,6 +13,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
## Get Key
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/keys.getKey"} path={[]} query={[{"name":"keyId","type":"string","defaultValue":"key_1234","isRequired":true,"description":"The id of the key to fetch"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -44,10 +48,6 @@ The id of the key to fetch
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/keys.getKey"} path={[]} query={[{"name":"keyId","type":"string","defaultValue":"key_1234","isRequired":true,"description":"The id of the key to fetch"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -590,6 +590,10 @@ export interface Response {
## Delete Key
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.deleteKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"key_1234","isRequired":false,"description":"The id of the key to revoke"}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -621,10 +625,6 @@ The id of the key to revoke
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.deleteKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"}}}} schemas={{"0":{"type":"string","defaultValue":"key_1234","isRequired":false,"description":"The id of the key to revoke"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -1042,6 +1042,10 @@ export interface Response {
## Create Key
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.createKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":true,"schema":"0"},"prefix":{"type":"ref","isRequired":false,"schema":"1"},"name":{"type":"ref","isRequired":false,"schema":"2"},"byteLength":{"type":"ref","isRequired":false,"schema":"3"},"ownerId":{"type":"ref","isRequired":false,"schema":"4"},"meta":{"type":"ref","isRequired":false,"schema":"5"},"roles":{"type":"ref","isRequired":false,"schema":"6"},"expires":{"type":"ref","isRequired":false,"schema":"8"},"remaining":{"type":"ref","isRequired":false,"schema":"9"},"refill":{"type":"ref","isRequired":false,"schema":"10"},"ratelimit":{"type":"ref","isRequired":false,"schema":"13"},"enabled":{"type":"ref","isRequired":false,"schema":"18"}}}} schemas={{"0":{"type":"string","defaultValue":"api_123","isRequired":false,"description":"Choose an `API` where this key should be created."},"1":{"type":"string","defaultValue":"","isRequired":false,"description":"To make it easier for your users to understand which product an api key belongs to, you can add prefix them.\n\nFor example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.\n\nThe underscore is automatically added if you are defining a prefix, for example: \"prefix\": \"abc\" will result in a key like abc_xxxxxxxxx\n"},"2":{"type":"string","defaultValue":"my key","isRequired":false,"description":"The name for your Key. This is not customer facing."},"3":{"type":"number","defaultValue":"","isRequired":false,"description":"The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations."},"4":{"type":"string","defaultValue":"team_123","isRequired":false,"description":"Your user’s Id. This will provide a link between Unkey and your customer record.\nWhen validating a key, we will return this back to you, so you can clearly identify your user from their api key."},"5":{"type":"object","isRequired":false,"description":"This is a place for dynamic meta data, anything that feels useful for you should go here","properties":{},"additionalProperties":true},"6":{"type":"array","description":"A list of roles that this key should have. New roles will be created if they don't exist yet.","isRequired":false,"items":"7"},"7":{"type":"string","defaultValue":"","isRequired":false},"8":{"type":"number","defaultValue":1623869797161,"isRequired":false,"description":"You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again."},"9":{"type":"number","defaultValue":1000,"isRequired":false,"description":"You can limit the number of requests a key can make. Once a key reaches 0 remaining requests, it will automatically be disabled and is no longer valid unless you update it."},"10":{"type":"object","isRequired":false,"description":"Unkey enables you to refill verifications for each key at regular intervals.","properties":{"interval":{"type":"ref","isRequired":true,"schema":"11"},"amount":{"type":"ref","isRequired":true,"schema":"12"}}},"11":{"type":"string","defaultValue":"","isRequired":false,"description":"Unkey will automatically refill verifications at the set interval."},"12":{"type":"number","defaultValue":"","isRequired":false,"description":"The number of verifications to refill for each occurrence is determined individually for each key."},"13":{"type":"object","isRequired":false,"description":"Unkey comes with per-key ratelimiting out of the box.","properties":{"type":{"type":"ref","isRequired":true,"schema":"14"},"limit":{"type":"ref","isRequired":true,"schema":"15"},"refillRate":{"type":"ref","isRequired":true,"schema":"16"},"refillInterval":{"type":"ref","isRequired":true,"schema":"17"}}},"14":{"type":"string","defaultValue":"","isRequired":false,"description":"Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate."},"15":{"type":"number","defaultValue":"","isRequired":false,"description":"The total amount of burstable requests."},"16":{"type":"number","defaultValue":"","isRequired":false,"description":"How many tokens to refill during each refillInterval."},"17":{"type":"number","defaultValue":"","isRequired":false,"description":"Determines the speed at which tokens are refilled, in milliseconds."},"18":{"type":"boolean","defaultValue":false,"isRequired":false,"description":"Sets if key is enabled or disabled. Disabled keys are not valid."}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -1237,10 +1241,6 @@ Sets if key is enabled or disabled. Disabled keys are not valid.
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.createKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":true,"schema":"0"},"prefix":{"type":"ref","isRequired":false,"schema":"1"},"name":{"type":"ref","isRequired":false,"schema":"2"},"byteLength":{"type":"ref","isRequired":false,"schema":"3"},"ownerId":{"type":"ref","isRequired":false,"schema":"4"},"meta":{"type":"ref","isRequired":false,"schema":"5"},"roles":{"type":"ref","isRequired":false,"schema":"6"},"expires":{"type":"ref","isRequired":false,"schema":"8"},"remaining":{"type":"ref","isRequired":false,"schema":"9"},"refill":{"type":"ref","isRequired":false,"schema":"10"},"ratelimit":{"type":"ref","isRequired":false,"schema":"13"},"enabled":{"type":"ref","isRequired":false,"schema":"18"}}}} schemas={{"0":{"type":"string","defaultValue":"api_123","isRequired":false,"description":"Choose an `API` where this key should be created."},"1":{"type":"string","defaultValue":"","isRequired":false,"description":"To make it easier for your users to understand which product an api key belongs to, you can add prefix them.\n\nFor example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.\n\nThe underscore is automatically added if you are defining a prefix, for example: \"prefix\": \"abc\" will result in a key like abc_xxxxxxxxx\n"},"2":{"type":"string","defaultValue":"my key","isRequired":false,"description":"The name for your Key. This is not customer facing."},"3":{"type":"number","defaultValue":"","isRequired":false,"description":"The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations."},"4":{"type":"string","defaultValue":"team_123","isRequired":false,"description":"Your user’s Id. This will provide a link between Unkey and your customer record.\nWhen validating a key, we will return this back to you, so you can clearly identify your user from their api key."},"5":{"type":"object","isRequired":false,"description":"This is a place for dynamic meta data, anything that feels useful for you should go here","properties":{},"additionalProperties":true},"6":{"type":"array","description":"A list of roles that this key should have. New roles will be created if they don't exist yet.","isRequired":false,"items":"7"},"7":{"type":"string","defaultValue":"","isRequired":false},"8":{"type":"number","defaultValue":1623869797161,"isRequired":false,"description":"You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again."},"9":{"type":"number","defaultValue":1000,"isRequired":false,"description":"You can limit the number of requests a key can make. Once a key reaches 0 remaining requests, it will automatically be disabled and is no longer valid unless you update it."},"10":{"type":"object","isRequired":false,"description":"Unkey enables you to refill verifications for each key at regular intervals.","properties":{"interval":{"type":"ref","isRequired":true,"schema":"11"},"amount":{"type":"ref","isRequired":true,"schema":"12"}}},"11":{"type":"string","defaultValue":"","isRequired":false,"description":"Unkey will automatically refill verifications at the set interval."},"12":{"type":"number","defaultValue":"","isRequired":false,"description":"The number of verifications to refill for each occurrence is determined individually for each key."},"13":{"type":"object","isRequired":false,"description":"Unkey comes with per-key ratelimiting out of the box.","properties":{"type":{"type":"ref","isRequired":true,"schema":"14"},"limit":{"type":"ref","isRequired":true,"schema":"15"},"refillRate":{"type":"ref","isRequired":true,"schema":"16"},"refillInterval":{"type":"ref","isRequired":true,"schema":"17"}}},"14":{"type":"string","defaultValue":"","isRequired":false,"description":"Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate."},"15":{"type":"number","defaultValue":"","isRequired":false,"description":"The total amount of burstable requests."},"16":{"type":"number","defaultValue":"","isRequired":false,"description":"How many tokens to refill during each refillInterval."},"17":{"type":"number","defaultValue":"","isRequired":false,"description":"Determines the speed at which tokens are refilled, in milliseconds."},"18":{"type":"boolean","defaultValue":false,"isRequired":false,"description":"Sets if key is enabled or disabled. Disabled keys are not valid."}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -1695,6 +1695,10 @@ export interface Response {
## Verify Key
<APIPlayground authorization={undefined} method={"POST"} route={"/v1/keys.verifyKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":false,"schema":"0"},"key":{"type":"ref","isRequired":true,"schema":"1"}}}} schemas={{"0":{"type":"string","defaultValue":"api_1234","isRequired":false,"description":"The id of the api where the key belongs to. This is optional for now but will be required soon.\nThe key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail."},"1":{"type":"string","defaultValue":"sk_1234","isRequired":false,"description":"The key to verify"}}}>
</APIPlayground>
### Request Body
<Property name={"apiId"} type={"string"} required={false} deprecated={undefined}>
@@ -1727,10 +1731,6 @@ The key to verify
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={undefined} method={"POST"} route={"/v1/keys.verifyKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"apiId":{"type":"ref","isRequired":false,"schema":"0"},"key":{"type":"ref","isRequired":true,"schema":"1"}}}} schemas={{"0":{"type":"string","defaultValue":"api_1234","isRequired":false,"description":"The id of the api where the key belongs to. This is optional for now but will be required soon.\nThe key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail."},"1":{"type":"string","defaultValue":"sk_1234","isRequired":false,"description":"The key to verify"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -2245,6 +2245,10 @@ export interface Response {
## Update Key
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.updateKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"},"name":{"type":"ref","isRequired":false,"schema":"1"},"ownerId":{"type":"ref","isRequired":false,"schema":"2"},"meta":{"type":"ref","isRequired":false,"schema":"3"},"expires":{"type":"ref","isRequired":false,"schema":"4"},"ratelimit":{"type":"ref","isRequired":false,"schema":"5"},"remaining":{"type":"ref","isRequired":false,"schema":"10"},"refill":{"type":"ref","isRequired":false,"schema":"11"},"enabled":{"type":"ref","isRequired":false,"schema":"14"}}}} schemas={{"0":{"type":"string","defaultValue":"key_123","isRequired":false,"description":"The id of the key you want to modify"},"1":{"type":"string","defaultValue":"Customer X","isRequired":false,"description":"The name of the key"},"2":{"type":"string","defaultValue":"user_123","isRequired":false,"description":"The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API."},"3":{"type":"object","isRequired":false,"description":"Any additional metadata you want to store with the key","properties":{},"additionalProperties":true},"4":{"type":"number","defaultValue":0,"isRequired":false,"description":"The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring."},"5":{"type":"object","isRequired":false,"description":"Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.","properties":{"type":{"type":"ref","isRequired":true,"schema":"6"},"limit":{"type":"ref","isRequired":true,"schema":"7"},"refillRate":{"type":"ref","isRequired":true,"schema":"8"},"refillInterval":{"type":"ref","isRequired":true,"schema":"9"}}},"6":{"type":"string","defaultValue":"","isRequired":false,"description":"Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate."},"7":{"type":"number","defaultValue":"","isRequired":false,"description":"The total amount of burstable requests."},"8":{"type":"number","defaultValue":"","isRequired":false,"description":"How many tokens to refill during each refillInterval."},"9":{"type":"number","defaultValue":"","isRequired":false,"description":"Determines the speed at which tokens are refilled, in milliseconds."},"10":{"type":"number","defaultValue":1000,"isRequired":false,"description":"The number of requests that can be made with this key before it becomes invalid. Set `null` to disable."},"11":{"type":"object","isRequired":false,"description":"Unkey enables you to refill verifications for each key at regular intervals.","properties":{"interval":{"type":"ref","isRequired":true,"schema":"12"},"amount":{"type":"ref","isRequired":true,"schema":"13"}}},"12":{"type":"string","defaultValue":"","isRequired":false,"description":"Unkey will automatically refill verifications at the set interval. If null is used the refill functionality will be removed from the key."},"13":{"type":"number","defaultValue":"","isRequired":false,"description":"The amount of verifications to refill for each occurrence is determined individually for each key."},"14":{"type":"boolean","defaultValue":true,"isRequired":false,"description":"Set if key is enabled or disabled. If disabled, the key cannot be used to verify."}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -2402,10 +2406,6 @@ Set if key is enabled or disabled. If disabled, the key cannot be used to verify
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.updateKey"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"},"name":{"type":"ref","isRequired":false,"schema":"1"},"ownerId":{"type":"ref","isRequired":false,"schema":"2"},"meta":{"type":"ref","isRequired":false,"schema":"3"},"expires":{"type":"ref","isRequired":false,"schema":"4"},"ratelimit":{"type":"ref","isRequired":false,"schema":"5"},"remaining":{"type":"ref","isRequired":false,"schema":"10"},"refill":{"type":"ref","isRequired":false,"schema":"11"},"enabled":{"type":"ref","isRequired":false,"schema":"14"}}}} schemas={{"0":{"type":"string","defaultValue":"key_123","isRequired":false,"description":"The id of the key you want to modify"},"1":{"type":"string","defaultValue":"Customer X","isRequired":false,"description":"The name of the key"},"2":{"type":"string","defaultValue":"user_123","isRequired":false,"description":"The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API."},"3":{"type":"object","isRequired":false,"description":"Any additional metadata you want to store with the key","properties":{},"additionalProperties":true},"4":{"type":"number","defaultValue":0,"isRequired":false,"description":"The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring."},"5":{"type":"object","isRequired":false,"description":"Unkey comes with per-key ratelimiting out of the box. Set `null` to disable.","properties":{"type":{"type":"ref","isRequired":true,"schema":"6"},"limit":{"type":"ref","isRequired":true,"schema":"7"},"refillRate":{"type":"ref","isRequired":true,"schema":"8"},"refillInterval":{"type":"ref","isRequired":true,"schema":"9"}}},"6":{"type":"string","defaultValue":"","isRequired":false,"description":"Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate."},"7":{"type":"number","defaultValue":"","isRequired":false,"description":"The total amount of burstable requests."},"8":{"type":"number","defaultValue":"","isRequired":false,"description":"How many tokens to refill during each refillInterval."},"9":{"type":"number","defaultValue":"","isRequired":false,"description":"Determines the speed at which tokens are refilled, in milliseconds."},"10":{"type":"number","defaultValue":1000,"isRequired":false,"description":"The number of requests that can be made with this key before it becomes invalid. Set `null` to disable."},"11":{"type":"object","isRequired":false,"description":"Unkey enables you to refill verifications for each key at regular intervals.","properties":{"interval":{"type":"ref","isRequired":true,"schema":"12"},"amount":{"type":"ref","isRequired":true,"schema":"13"}}},"12":{"type":"string","defaultValue":"","isRequired":false,"description":"Unkey will automatically refill verifications at the set interval. If null is used the refill functionality will be removed from the key."},"13":{"type":"number","defaultValue":"","isRequired":false,"description":"The amount of verifications to refill for each occurrence is determined individually for each key."},"14":{"type":"boolean","defaultValue":true,"isRequired":false,"description":"Set if key is enabled or disabled. If disabled, the key cannot be used to verify."}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -2845,6 +2845,10 @@ export interface Response {
## Update Remaining
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.updateRemaining"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"},"op":{"type":"ref","isRequired":true,"schema":"1"},"value":{"type":"ref","isRequired":true,"schema":"2"}}}} schemas={{"0":{"type":"string","defaultValue":"key_123","isRequired":false,"description":"The id of the key you want to modify"},"1":{"type":"string","defaultValue":"","isRequired":false,"description":"The operation you want to perform on the remaining count"},"2":{"type":"number","defaultValue":1,"isRequired":false,"description":"The value you want to set, add or subtract the remaining count by"}}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -2890,10 +2894,6 @@ The value you want to set, add or subtract the remaining count by
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"POST"} route={"/v1/keys.updateRemaining"} path={[]} query={[]} header={[]} body={{"type":"object","isRequired":true,"properties":{"keyId":{"type":"ref","isRequired":true,"schema":"0"},"op":{"type":"ref","isRequired":true,"schema":"1"},"value":{"type":"ref","isRequired":true,"schema":"2"}}}} schemas={{"0":{"type":"string","defaultValue":"key_123","isRequired":false,"description":"The id of the key you want to modify"},"1":{"type":"string","defaultValue":"","isRequired":false,"description":"The operation you want to perform on the remaining count"},"2":{"type":"number","defaultValue":1,"isRequired":false,"description":"The value you want to set, add or subtract the remaining count by"}}}>
</APIPlayground>
</APIInfo>
<APIExample>
@@ -3320,6 +3320,10 @@ export interface Response {
## Get Verifications
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/keys.getVerifications"} path={[]} query={[{"name":"keyId","type":"string","defaultValue":"key_1234","isRequired":false,"description":"The id of the key to fetch, either `keyId` or `ownerId` must be provided"},{"name":"ownerId","type":"string","defaultValue":"chronark","isRequired":false,"description":"The owner id to fetch keys for, either `keyId` or `ownerId` must be provided"},{"name":"start","type":"number","defaultValue":1620000000000,"isRequired":false,"description":"The start of the period to fetch usage for as unix milliseconds timestamp"},{"name":"end","type":"number","defaultValue":1620000000000,"isRequired":false,"description":"The end of the period to fetch usage for as unix milliseconds timestamp"},{"name":"granularity","type":"string","defaultValue":"day","isRequired":false,"description":"The granularity of the usage data to fetch, currently only `day` is supported"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
### Authorization
<Property name={"Authorization"} type={"Bearer <token>"} required={true}>
@@ -3385,10 +3389,6 @@ The granularity of the usage data to fetch, currently only `day` is supported
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={{"type":"string","name":"Authorization","defaultValue":"Bearer","isRequired":true,"description":"The Authorization access token"}} method={"GET"} route={"/v1/keys.getVerifications"} path={[]} query={[{"name":"keyId","type":"string","defaultValue":"key_1234","isRequired":false,"description":"The id of the key to fetch, either `keyId` or `ownerId` must be provided"},{"name":"ownerId","type":"string","defaultValue":"chronark","isRequired":false,"description":"The owner id to fetch keys for, either `keyId` or `ownerId` must be provided"},{"name":"start","type":"number","defaultValue":1620000000000,"isRequired":false,"description":"The start of the period to fetch usage for as unix milliseconds timestamp"},{"name":"end","type":"number","defaultValue":1620000000000,"isRequired":false,"description":"The end of the period to fetch usage for as unix milliseconds timestamp"},{"name":"granularity","type":"string","defaultValue":"day","isRequired":false,"description":"The granularity of the usage data to fetch, currently only `day` is supported"}]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>
+4 -4
View File
@@ -13,6 +13,10 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
## Check Liveness
<APIPlayground authorization={undefined} method={"GET"} route={"/v1/liveness"} path={[]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
| Status code | Description |
| ----------- | ----------- |
| `200` | The configured services and their status |
@@ -24,10 +28,6 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
| `500` | The server has encountered a situation it does not know how to handle. |
<APIPlayground authorization={undefined} method={"GET"} route={"/v1/liveness"} path={[]} query={[]} header={[]} body={undefined} schemas={{}}>
</APIPlayground>
</APIInfo>
<APIExample>