Types and Interfaces
Installโ
- npm
- yarn
- pnpm
npm install @basketry/typescript
yarn add @basketry/typescript
pnpm add @basketry/typescript
Basic Usageโ
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"generators": ["@basketry/typescript"],
"output": "src"
}
File Structureโ
This generator will create a types.ts
file that contains all the types and interfaces for the API. By default, the file will be nested within a directory named after the API major version. This behavior can be disabled by using the includeVersion
option described below.
my-project/
โโโ node_modules/
โโโ src/
โ โโโ v1/ <-- generated
โ โ โโโ types.ts <-- generated
โ โโโ index.ts
โโโ .gitignore
โโโ basketry.config.json
โโโ package.json
โโโ petstore.json
โโโ README.md
Optionsโ
The @basketry/typescript
generator accepts the following options to customize the generated code:
eslintDisable
โ
- Type:
string[]
- An array of ESLint rules to disable in the generated code.
Use this option if a generator produces code that violates a rule you have configured in your ESLint configuration.
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"generators": ["@basketry/typescript"],
"output": "src",
"options": {
"typescript": {
"eslintDisable": [
"@typescript-eslint/no-explicit-any",
"@typescript-eslint/no-unused-vars"
]
}
}
}
This option as configured will emit the following code at the top of the generated file:
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
includeVersion
โ
- Type:
boolean
- Determines whether or not to nest the generated files in a directory named after the API major version.
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"generators": ["@basketry/typescript"],
"output": "src",
"options": {
"typescript": {
"includeVersion": false
}
}
}
This option as configured will emit the following file structure:
my-project/
โโโ node_modules/
โโโ src/
โ โโโ types.ts <-- generated
โ โโโ index.ts
โโโ .gitignore
โโโ basketry.config.json
โโโ package.json
โโโ petstore.json
โโโ README.md
prettierConfig
โ
- Type:
string
- Path to a Prettier configuration file.
This option provides a path to a Prettier configuration file. This generator formats all generated code with prettier. If a prettierConfig
option is provided, the generator will use that configuration file. If no prettierConfig
option is provided, the generator will locate a Prettier configuration file per the Prettier configuration file resolution rules.
{
"source": "petstore.json",
"parser": "@basketry/openapi-3",
"generators": ["@basketry/typescript"],
"output": "src",
"options": {
"typescript": {
"prettierConfig": "alternate.prettier.config.js"
}
}
}