A Ruby gem that reads OpenAPI specifications and automatically generates type-safe client SDKs in multiple languages (Ruby and JavaScript).
gem install openapi_sdk_generator_gemGenerate 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 rubyOptions:
-i, --input: Path or URL to OpenAPI specification (YAML/JSON)-o, --output: Output directory for generated SDK-l, --language: Target language (rubyorjavascript)
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')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')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 rubyThis generates:
my-sdk/
├── README.md # Usage documentation
├── client.rb # API client with all methods
└── models/ # Data models
├── pet.rb
├── error.rb
└── newpet.rb
client.rb- Main API client with HTTP methods for each endpointmodels/*.rb- Individual model classes with serialization/deserializationREADME.md- Auto-generated documentation with usage examples
client.js- API client with async/await methodspackage.json- NPM package configurationREADME.md- Auto-generated documentation
- Ruby 2.7 or higher
- OpenAPI Specification 3.0+
- GitHub Repository: github.com/taimourz/openapi_sdk_generator_gem
- RubyGems: rubygems.org/gems/openapi_sdk_generator_gem
- Blog Tutorial: taimourz.github.io/portfolio/notes/openapi-sdk