@pusula/swagger-codegen
v1.2.0
Published
[![NPM badge](https://img.shields.io/npm/v/@pusula/swagger-codegen.svg)](https://www.npmjs.com/package/@pusula/swagger-codegen.core)
Downloads
14
Readme
@pusula/swagger-codegen
Generates swagger types and module.core providers with using swagger-typescript-api
Getting Started
Install package and dependencies
npm
npm i --save-dev @pusula/swagger-codegen swagger-typescript-api
npm i @pusula/module.core
pnpm
pnpm i -D @pusula/swagger-codegen swagger-typescript-api
pnpm i @pusula/module.core
yarn
yarn add -dev @pusula/swagger-codegen swagger-typescript-api
yarn add @pusula/module.core
Usage
This will generate api types and @pusula/module.core providers.
import { generate } from "@pusula/swagger-codegen";
generate({
//output files will be placed under /src/__generated__ if you dont provide a output param
//output: path.resolve(process.cwd(), "./src/__generated__"),
//templates: path.resolve(__dirname,"./src/templates")
url: "http://api.com/swagger.json",
});
Usage For Multiple Endpoints
This will generate api types and @pusula/module.core providers for multiple endpoints in different folders.
It detects duplicate of types and providers and adds suffix numbers like 'ProductApi2' to the end.
Provide optional wordMapForReplacingInTypeNames
object to replace some words.
import { generate, GenerateApiMultipleOptions } from "@pusula/swagger-codegen";
const endpoints: GenerateApiMultipleOptions = {
endpoints: [
{ name: "auth", url: "http://api.com/auth/swagger.json" },
{ name: "products", url: "http://api.com/products/swagger.json" },
{
name: "products-v2",
url: "http://api.com/products/swagger.json",
},
],
authorizationToken: autToken,
wordMapForReplacingInTypeNames: {'ExtraLongWord':'ELW'}
...
};
generateMultiple({
endPoints,
});
Check the @pusula/module.core documentation for more details. For more customization options check the documentation of swagger-typescript-api