@ibabkin/openapi-to-server
v1.19.0
Published
Generates server interface from openapi
Downloads
102
Maintainers
Readme
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: [email protected]
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>>;
}