@roserocket-sdk/client-types-generator

1.0.6 • Public • Published

Rose Rocket Client Types Generator

A command-line tool that generates TypeScript types from OpenAPI specifications.

Installation

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

Usage

client-types-generator -i <input> -o [output] -v <versionNumber>

Yarn

yarn dlx @roserocket-sdk/client-types-generator -i <input> -o [output] -v <versionNumber>

Input (-i)

The input can be either:

  • A URL to an OpenAPI specification (must start with http:// or https://)
  • A path to a local OpenAPI specification file

File Path Handling

  • 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

Output (-o)

  • 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

Version Number (-v)

  • 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

Current Limitations

  • 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

Development

# Run directly from source
yarn run generate -i <input> -o [output] -v <versionNumber>

Example

Openapi Schema snippet

"/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"
                }
              }
           }
        }
    }
},

Generated Type

... |
  [
      `PUT /api/v4/objects/${string}`,
      [
          ObjectRecordUpdateRequest,
          JSONRecord,
          {
            /**
             * The board ID that this request is relative to.
             */
            boardId?: string;
          },
      ],
  ] |
...

Readme

Keywords

none

Package Sidebar

Install

npm i @roserocket-sdk/client-types-generator

Weekly Downloads

882

Version

1.0.6

License

All rights reserved by Rose Rocket, Inc.

Unpacked Size

30 kB

Total Files

13

Last publish

Collaborators

  • roserocket