Unofficial OpenAPI schemas for some public APIs
Note
- OpenAPI 3.1
- Code examples
/example - Schemas definitions in zod
- OpenAPI Builder
jsr:@maks11060/openapi
Typescript client with openapi-fetch
deno run -A npm:openapi-typescript \
https://github.com/MAKS11060/openapi/releases/latest/download/danbooru.openapi.yaml \
-o ./danbooru.oas.tsnpx openapi-typescript \
https://github.com/MAKS11060/openapi/releases/latest/download/danbooru.openapi.yaml \
-o ./danbooru.oas.ts// danbooru.ts
import createClient from 'openapi-fetch'
import type {paths} from './danbooru.oas.ts'
// Almost all GET requests do not require authorization.
// To use 'saved searches', you need an ApiKey.
// Register api key: https://danbooru.donmai.us/profile => API Key
// const login = ''
// const apiKey = ''
// const authorization = new TextEncoder().encode(`${login}:${apiKey}`).toBase64()
// deep serializer / {search: {id: [1,2]}} => ?search[id]=1,2
function querySerializer(
obj: Record<string, unknown>,
params: URLSearchParams = new URLSearchParams(),
prefix = '',
): string {
for (const [key, value] of Object.entries(obj)) {
const encodedKey = encodeURIComponent(key)
const paramKey = prefix ? `${prefix}[${encodedKey}]` : encodedKey
if (value == null) continue
if (Array.isArray(value)) {
if (value.length === 0) continue
params.append(paramKey, value.map(String).join(','))
} else if (typeof value === 'object' && value !== null) {
querySerializer(value as Record<string, unknown>, params, paramKey)
} else {
params.append(paramKey, String(value))
}
}
return params.toString()
}
export const danbooruApi = createClient<paths>({
baseUrl: 'https://danbooru.donmai.us',
// headers: {authorization},
querySerializer,
})Typescript client with openapi-fetch
deno run -A npm:openapi-typescript \
https://github.com/MAKS11060/openapi/releases/latest/download/shikimori.openapi.yaml \
-o ./shikimori.oas.tsnpx openapi-typescript \
https://github.com/MAKS11060/openapi/releases/latest/download/shikimori.openapi.yaml \
-o ./shikimori.oas.ts// shikimori.ts
import createClient from 'openapi-fetch'
import type {paths} from './shikimori.oas.ts'
// Requirements
// Add your Oauth2 Application name to User-Agent requests header.
// Don’t mimic a browser.
// Your IP address may be banned if you use API without properly set User-Agent header.
const shikimoriUserAgent = ''
export const shikimoriApi = createClient<paths>({
baseUrl: 'https://shikimori.one',
headers: {'user-agent': shikimoriUserAgent},
})Note
Project structure
src/{service}/mod.ts- Entry pointopenapi.ts- Configschema.ts- Data models
Install Deno
Install dependencies
deno run initdeno run okdeno run buildBuild client types in example
deno run build:client