
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
openapi-typescript-codegen
Advanced tools
Library that generates Typescript clients based on the OpenAPI specification.
The openapi-typescript-codegen npm package is a tool that generates TypeScript clients from OpenAPI specifications. It helps developers to create strongly-typed API clients, ensuring type safety and reducing the likelihood of runtime errors.
Generate TypeScript Client
This feature allows you to generate a TypeScript client from an OpenAPI specification file. The generated client will include all the necessary types and methods to interact with the API.
const { generate } = require('openapi-typescript-codegen');
generate({
input: './path/to/openapi.yaml',
output: './generated',
clientName: 'MyApiClient'
});
Custom Templates
This feature allows you to use custom templates for generating the TypeScript client. This can be useful if you need to adhere to specific coding standards or want to customize the generated code.
const { generate } = require('openapi-typescript-codegen');
generate({
input: './path/to/openapi.yaml',
output: './generated',
templates: './path/to/custom/templates'
});
Generate Models Only
This feature allows you to generate only the TypeScript models from an OpenAPI specification file. This can be useful if you only need the type definitions and not the full client.
const { generate } = require('openapi-typescript-codegen');
generate({
input: './path/to/openapi.yaml',
output: './generated/models',
onlyModels: true
});
OpenAPI Generator is a comprehensive tool that supports generating API clients, server stubs, API documentation, and configuration in various languages. Compared to openapi-typescript-codegen, it offers broader language support and more customization options.
swagger-typescript-api is a tool that generates TypeScript API clients from Swagger/OpenAPI definitions. It focuses on simplicity and ease of use, similar to openapi-typescript-codegen, but may offer different customization options and templates.
typescript-fetch is a generator for TypeScript clients using the Fetch API. It is part of the OpenAPI Generator project and provides a different approach to generating TypeScript clients compared to openapi-typescript-codegen, focusing on using the Fetch API for HTTP requests.
Node.js library that generates Typescript clients based on the OpenAPI specification.
npm install openapi-typescript-codegen --save-dev
$ openapi --help
Usage: openapi [options]
Options:
-V, --version output the version number
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
-o, --output <value> Output directory (required)
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
--name <value> Custom client class name
--useOptions Use options instead of arguments
--useUnionTypes Use union types instead of enums
--exportCore <value> Write core files to disk (default: true)
--exportServices <value> Write services to disk (default: true)
--exportModels <value> Write models to disk (default: true)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tab] (default: "4")
--postfixServices Service name postfix (default: "Service")
--postfixModels Model name postfix
--request <value> Path to custom request file
-h, --help display help for command
Examples
$ openapi --input ./spec.json --output ./generated
$ openapi --input ./spec.json --output ./generated --client xhr
--name
--useOptions
--useUnionTypes
--exportSchemas
[0.24.0] - 2023-04-10
--postfixModels
optionFAQs
Library that generates Typescript clients based on the OpenAPI specification.
The npm package openapi-typescript-codegen receives a total of 231,693 weekly downloads. As such, openapi-typescript-codegen popularity was classified as popular.
We found that openapi-typescript-codegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.