Skip to content

pnsk-lab/typia-openapi

Repository files navigation

typia-openapi

Create OpenAPI specifications from TypeScript types using typia.

Installation

This project is published on JSR

bunx jsr add @pnsk-lab/typia-openapi

Usage

import { stringify } from 'yaml'
import typia from 'typia'
import { typiaToOpenAPI } from '@pnsk-lab/typia-openapi'

const api = typiaToOpenAPI({
  openapi: '3.1.0',
  info: {
    title: 'Example API',
    version: '1.0.0',
  },
  servers: [
    {
      url: 'https://api.example.com/v1',
      description: 'Production server',
    },
  ],
  paths: {
    '/users': {
      get: {
        summary: 'Get all users',
        responses: {
          '200': {
            description: 'A list of users',
            content: {
              'application/json': {
                schema: typia.json.schema<{
                  id: string
                }[]>()
              }
            }
          }
        }
      }
    }
  }
})

await Bun.write('example/schema.yaml', stringify(api, { indent: 2 }))

Contributing

Contributions are welcome! Please open a pull request with your changes.

About

Typia to OpenAPI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published