A command-line tool that generates TypeScript types from OpenAPI specifications.
npm
# Install globally
npm install -g @roserocket-sdk/client-types-generator
# Or install in a project
npm install @roserocket-sdk/client-types-generator
yarn
yarn add @roserocket-sdk/client-types-generator
pnpm
# Install globally
pnpm add -g @roserocket-sdk/client-types-generator
# Or install in a project
pnpm add @roserocket-sdk/client-types-generator
client-types-generator -i <input> -o [output] -v <versionNumber>
yarn dlx @roserocket-sdk/client-types-generator -i <input> -o [output] -v <versionNumber>
The input can be either:
- A URL to an OpenAPI specification (must start with
http://
orhttps://
) - A path to a local OpenAPI specification file
-
Absolute paths (starting with
/
) are used as-is -
Relative paths are resolved relative to the current working directory
-
Example:
# Absolute path client-types-generator -i /Users/username/specs/openapi.json -v 2 # Relative path client-types-generator -i ./openapi.json -v 2 client-types-generator -i ../other-folder/openapi.json -v 2
-
If no output path is provided, the generated types will be printed to stdout
-
If an output path is provided:
-
Absolute paths (starting with
/
) are used as-is -
Relative paths are resolved relative to the current working directory
-
Example:
# Print to stdout client-types-generator -i openapi.json -v 2 # Save to file client-types-generator -i openapi.json -o ./src/types.ts -v 2 client-types-generator -i openapi.json -o /absolute/path/types.ts -v 2
-
- Your API or Endpoint version number.
- The number should be a valid integer.
- Floating-point numbers will be rounded up or down, e.g. 20.4 => 20; 2.6 => 2
- Only supports OpenAPI 3.0 specifications
- Only processes JSON content types
- Only the first successful response is processed
-
void
is returned if no response is found within>= 200 < 400
-
# Run directly from source
yarn run generate -i <input> -o [output] -v <versionNumber>
"/objects/{objectId}": {
"put": {
"summary": "Update a record.",
"tags": [
"Object Records"
],
"parameters": [
{
"name": "objectId",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
},
{
"name": "boardId",
"in": "query",
"description": "The board ID that this request is relative to.",
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ObjectRecordUpdateRequest"
}
}
}
},
"responses": {
"200": {
"description": "Returns the updated record with top-level primitive and nested updated fields populated.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/JSONRecord"
}
}
}
}
}
},
... |
[
`PUT /api/v4/objects/${string}`,
[
ObjectRecordUpdateRequest,
JSONRecord,
{
/**
* The board ID that this request is relative to.
*/
boardId?: string;
},
],
] |
...