@maks11060/openapi@0.1.3Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
OpenAPI 3.1 schema builder
This package works with Cloudflare Workers, Node.js, Deno, BunIt is unknown whether this package works with Browsers




JSR Score
88%
Published
2 months ago (0.1.3)
OpenAPI 3 Builder
TODO:
- Write doc
- Add support: webhooks, callbacks, links
Create Doc
Create Doc
import { createDoc } from '@maks11060/openapi' import { zodPlugin } from '@maks11060/openapi/zod' import { z } from 'zod' const doc = createDoc({ plugins: {schema: [zodPlugin()]}, info: {title: 'Test', version: '1.0.0'}, }) console.log(doc.toDoc()) // get schema object console.log(doc.toJSON(true)) // output in json format console.log(doc.toYAML()) // output in yaml format
Usage
Usage
import { createDoc } from '@maks11060/openapi' import { zodPlugin } from '@maks11060/openapi/zod' import { z } from 'zod' const doc = createDoc({ plugins: {schema: [zodPlugin()]}, info: {title: 'Test', version: '1.0.0'}, tags: [{name: 'users'}], }) doc.server({url: 'https://example.com'}) const oauth2 = doc.addSecuritySchema.oauth2('OAuth2', { authorizationCode: { authorizationUrl: 'https://example.com/authorize', tokenUrl: 'https://example.com/api/token', scopes: { read: '', edit: '', }, }, }) const unauthorizedResponse = doc.addResponse('Unauthorized', (t) => { t.content('application/json', {}) // .example('Example', (t) => t.value({error: 'Unauthorized'})) }) const user = z.object({ id: z.string(), username: z.string(), }) doc .addPath('/user') // .get((t) => { t.tag('users') t.summary('Get the authenticated user') t.security(oauth2, ['read']) t.response(200, (t) => { t.content('application/json', user) // .example('User', (t) => t.value({id: '1', username: 'user1'})) }) t.response(401, unauthorizedResponse) }) .patch((t) => { t.tag('users') t.describe('Update user') t.security(oauth2, ['edit']) t.response(200, (t) => { t.content('application/json', user) // .example('User', (t) => t.value({id: '1', username: 'user1'})) }) t.response(401, unauthorizedResponse) })
Built and signed on
GitHub Actions
Add Package
deno add jsr:@maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";
Import directly with a jsr specifier
import * as openapi from "jsr:@maks11060/openapi";
Add Package
pnpm i jsr:@maks11060/openapi
pnpm dlx jsr add @maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";
Add Package
yarn add jsr:@maks11060/openapi
yarn dlx jsr add @maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";
Add Package
vlt install jsr:@maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";
Add Package
npx jsr add @maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";
Add Package
bunx jsr add @maks11060/openapi
Import symbol
import * as openapi from "@maks11060/openapi";