@ibabkin/openapi-to-server
TypeScript icon, indicating that this package has built-in type declarations

1.17.8 • Public • Published

NPM version:latest npm downloads Coverage Status License

Description

Generates typescript interfaces for operations from OpenAPI 3.0 specification. Recommended to use with @ibabkin/openapi-to-zod

Usage

  • supported version of OpenAPI: 3.0.0
  • supports yaml-import
  • --json - emit json file alongside with typescript file
openapi-to-server --input ./swagger.yaml --output ./operations.d.ts --json
import api from './swagger.json';
import { OpenAPIV3 } from 'openapi-types';
import { renderDocument } from '../lib';
import fs from 'fs';

fs.writeFileSync('./operations.d.ts', renderDocument(api as OpenAPIV3.Document));

Input example:

openapi: 3.0.0
info:
  title: Simple Inventory API
  description: This is a simple API
  contact:
    email: you@your-company.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
  - url: https://virtserver.swaggerhub.com/DOSAKANTIVENKATESH/smp/1.0.0
    description: SwaggerHub API Auto Mocking
tags:
  - name: admins
    description: Secured Admin-only calls
  - name: developers
    description: Operations available to regular developers
paths:
  !!import/merge
    - paths.yaml

components:
  schemas:
    !!import/merge
      - components.yaml

Output example:

export type SearchInventoryPayload = {
  query: {
    searchString?: string,
    skip: number,
    limit: number,
  }
};

export type SearchInventoryResponse = InventoryItem[]

export type Operations = {
  searchInventory: IRoute<SearchInventoryPayload, Ok<SearchInventoryResponse>>;
}

Package Sidebar

Install

npm i @ibabkin/openapi-to-server

Weekly Downloads

82

Version

1.17.8

License

ISC

Unpacked Size

90.2 kB

Total Files

39

Last publish

Collaborators

  • igorbabkin