Socket
Socket
Sign inDemoInstall

openapi-typescript

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-typescript

Convert OpenAPI 3.0 & 3.1 schemas to TypeScript


Version published
Maintainers
1
Created

What is openapi-typescript?

The openapi-typescript npm package is a tool that generates TypeScript types from OpenAPI specifications. This helps developers ensure type safety and better integration between their API definitions and TypeScript code.

What are openapi-typescript's main functionalities?

Generate TypeScript Types

This feature allows you to generate TypeScript types from an OpenAPI specification URL. The generated types are then saved to a file named 'types.ts'.

const openapiTS = require('openapi-typescript');
const fs = require('fs');

async function generateTypes() {
  const types = await openapiTS('https://api.example.com/openapi.json');
  fs.writeFileSync('types.ts', types);
}

generateTypes();

Generate Types from Local File

This feature allows you to generate TypeScript types from a local OpenAPI specification file. The generated types are saved to a file named 'types.ts'.

const openapiTS = require('openapi-typescript');
const fs = require('fs');
const path = require('path');

async function generateTypes() {
  const types = await openapiTS(path.join(__dirname, 'openapi.json'));
  fs.writeFileSync('types.ts', types);
}

generateTypes();

Custom Type Generation Options

This feature allows you to customize the type generation process by providing options such as a transform function. The transform function can be used to modify the schema before generating the types.

const openapiTS = require('openapi-typescript');
const fs = require('fs');

async function generateTypes() {
  const types = await openapiTS('https://api.example.com/openapi.json', {
    transform: (schema) => {
      // Custom transformation logic
      return schema;
    }
  });
  fs.writeFileSync('types.ts', types);
}

generateTypes();

Other packages similar to openapi-typescript

Keywords

FAQs

Package last updated on 20 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc