No release in over 3 years
A lightweight tool to generate client SDKs in multiple languages from OpenAPI/Swagger specs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 13.0
~> 3.12

Runtime

~> 2.0
 Project Readme

OpenAPI SDK Generator

Gem Version

A Ruby gem that reads OpenAPI specifications and automatically generates type-safe client SDKs in multiple languages (Ruby and JavaScript).

Installation

gem install openapi_sdk_generator_gem

Usage

Command Line Interface

Generate SDKs from an OpenAPI specification file or URL:

# Show help
openapi-sdk-generator --help

# Generate JavaScript SDK from local file
openapi-sdk-generator -i path/to/openapi.yaml -o ./output -l javascript

# Generate Ruby SDK from local file
openapi-sdk-generator -i path/to/openapi.yaml -o ./output -l ruby

# Generate from URL
openapi-sdk-generator -i https://example.com/openapi.yaml -o ./output -l ruby

Options:

  • -i, --input: Path or URL to OpenAPI specification (YAML/JSON)
  • -o, --output: Output directory for generated SDK
  • -l, --language: Target language (ruby or javascript)

Programmatic Usage

require 'openapi_sdk_generator'

# Parse OpenAPI specification
parser = OpenapiSdkGenerator::Parser.new('path/to/openapi.yaml')

# Generate Ruby SDK
ruby_generator = OpenapiSdkGenerator::Generators::RubyGenerator.new(parser)
ruby_generator.write_to_directory('./output/ruby')

# Generate JavaScript SDK
js_generator = OpenapiSdkGenerator::Generators::JavascriptGenerator.new(parser)
js_generator.write_to_directory('./output/javascript')

Using a URL

require 'openapi_sdk_generator'

# Parse from URL
url = 'https://raw.githubusercontent.com/example/openapi.yaml'
parser = OpenapiSdkGenerator::Parser.new(url)

# Generate SDK
generator = OpenapiSdkGenerator::Generators::RubyGenerator.new(parser)
generator.write_to_directory('./output')

Example

Using the Petstore OpenAPI specification:

openapi-sdk-generator \
  -i https://raw.githubusercontent.com/taimourz/openapi_sdk_generator_gem/main/test/fixtures/petstore.yaml \
  -o ./my-sdk \
  -l ruby

This generates:

my-sdk/
├── README.md          # Usage documentation
├── client.rb          # API client with all methods
└── models/            # Data models
    ├── pet.rb
    ├── error.rb
    └── newpet.rb

Generated SDK Structure

Ruby Output

  • client.rb - Main API client with HTTP methods for each endpoint
  • models/*.rb - Individual model classes with serialization/deserialization
  • README.md - Auto-generated documentation with usage examples

JavaScript Output

  • client.js - API client with async/await methods
  • package.json - NPM package configuration
  • README.md - Auto-generated documentation

Requirements

  • Ruby 2.7 or higher
  • OpenAPI Specification 3.0+

Links