JSPM

  • Created
  • Published
  • Downloads 1881
  • Score
    100M100P100Q113323F
  • License MIT

Generate OpenAPI 3.0.0 spec from TypeScript code.

Package Exports

  • tspec
  • tspec/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tspec) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

tspec

Generate OpenAPI Specification from TypeScript types

How to use?

import { Tspec, generateSpec } from 'tspec'

// 1. Define API Specifications
export type PetApiSpec = Tspec.RegisterApiSpec<{
  baseUrl: '/pet',
  specs: {
    'GET /{id}': {
      summary: 'Find pet by ID',
      path: {
        /**
         * pet id
         * @examples [1234]
         * */
        id: string,
      },
      responses: { 200: Pet },
    },
  },
}>;

// 2. generate OpenAPI Spec
const openAPISpec = await generateSpec();

Philosophy

Type is all you need for generating Open API Specification

No need to tediously write OpenAPI Schema for each API.

You just need to pass your types to ApiSpec to generate an OpenAPI Specification.

Utilize ApiSpec types as a SSOT(Single Source of Truth) for type-hints, documentation and validation