Skip to content

chargebee/sdk-generator

Repository files navigation

SDK Generator

A powerful tool that automatically generates Software Development Kits (SDKs) for multiple programming languages from OpenAPI 3.0 specifications.

πŸš€ Features

  • Multi-language Support: Generate SDKs for 8 programming languages
  • OpenAPI 3.0 Compatible: Built on industry-standard OpenAPI specifications
  • Template-based Generation: Customizable templates for each language
  • Type Safety: Generates strongly-typed code with proper interfaces
  • CLI Interface: Simple command-line tool for easy integration

πŸ“‹ Supported Languages

πŸ› οΈ Prerequisites

  • Java 17 or higher
  • Gradle 7.0 or higher

Download Latest OpenAPI Specification

To get the latest OpenAPI specification for Chargebee, you can download it from the Chargebee OpenAPI repository

For Chargebee Client Library Generation

To generate SDKs for Chargebee's official client libraries, you'll need to clone the respective repositories first, as the generator updates existing code structure rather than creating everything from scratch:

# Clone all Chargebee client library repositories
git clone https://github.com/chargebee/chargebee-php.git
git clone https://github.com/chargebee/chargebee-node.git
git clone https://github.com/chargebee/chargebee-python.git
git clone https://github.com/chargebee/chargebee-ruby.git
git clone https://github.com/chargebee/chargebee-java.git
git clone https://github.com/chargebee/chargebee-dotnet.git
git clone https://github.com/chargebee/chargebee-go.git

Note: The SDK generator updates existing repository structures rather than creating complete projects from scratch. Make sure to clone the target repositories before running the generation commands.

πŸ“¦ Installation

From Source

git clone https://github.com/chargebee/sdk-generator.git
cd sdk-generator
./gradlew build

Using Gradle

./gradlew run --args="-i spec.json -l JAVA -o ./output"

πŸš€ Quick Start

Basic Usage

# Generate a Java SDK
./gradlew run --args="-i chargebee_sdk_spec.json -l JAVA -o ../chargebee-java/src/main/java/com/chargebee"

# Generate Nodejs typings
./gradlew run --args="-i chargebee_sdk_spec.json -l TYPESCRIPT_TYPINGS_V3 -o ../chargebee-node/types/"

# Generate Python SDK
./gradlew run --args="-i chargebee_sdk_spec.json -l PYTHON_V3 -o ../chargebee-python/chargebee"

With docker-compose

# Checkout or update all required SDK repositories to ../chargebee-sdks
# Also downloads the latest OpenAPI spec
docker compose run --rm sdk-generator setup

# Generate the SDK
docker compose run --rm sdk-generator generate <lang1> <lang2>

Command Line Options

Option Description Required
-i, --input Path to OpenAPI specification file βœ…
-l, --language Target language for SDK generation βœ…
-o, --output Output directory path βœ…

Available Languages

Current/Latest Versions

JAVA                    - Java SDK
TYPESCRIPT_TYPINGS_V3  - TypeScript type definitions (v3)
NODE_V3                - Node.js SDK (v3)
PYTHON_V3              - Python SDK (v3)
PHP_V4                 - PHP SDK (v4)
RUBY                   - Ruby SDK
DOTNET                 - .NET SDK
GO                     - Go SDK

Legacy Versions

NODE                   - Node.js SDK (legacy)
PYTHON                 - Python SDK (legacy)
PHP                    - PHP SDK (legacy)

πŸ“ Project Structure

src/
β”œβ”€β”€ main/
β”‚   β”œβ”€β”€ java/com/chargebee/
β”‚   β”‚   β”œβ”€β”€ openapi/           # OpenAPI parsing and processing
β”‚   β”‚   β”œβ”€β”€ sdk/               # Language-specific generators
β”‚   β”‚   └── Main.java          # CLI entry point
β”‚   └── resources/
β”‚       └── templates/         # Language-specific templates
β”‚           β”œβ”€β”€ java/
β”‚           β”œβ”€β”€ php/
β”‚           β”œβ”€β”€ python/
β”‚           └── ...
└── test/                      # Unit tests

πŸ”§ Configuration

Custom Templates

The generator uses Handlebars templates located in src/main/resources/templates/. You can customize the generated code by modifying these templates:

  • java/ - Java SDK templates
  • ts/ - TypeScript templates
  • python/ - Python SDK templates
  • php/ - PHP SDK templates
  • And more...

OpenAPI Extensions

The generator supports custom OpenAPI extensions for enhanced functionality:

# Example OpenAPI spec with custom extensions
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          x-is-dependent-attribute: true
        email:
          type: string
          x-is-multi-attribute: false

X-CB Extension Parameters

This SDK generator uses custom OpenAPI extension parameters (prefixed with x-cb-) to enhance code generation capabilities. These extensions provide additional metadata for:

  • Operation behavior control (list operations, bulk operations, idempotency)
  • Parameter filtering and ordering
  • Resource relationships and sub-resources
  • Special data type handling (money fields, custom fields)
  • URL construction and routing

For a complete list and detailed descriptions of all supported extensions, see X-CB Extensions Documentation.

Key Extensions

  • x-cb-operation-method-name: Defines SDK method names
  • x-cb-operation-is-list: Marks list operations for special handling
  • x-cb-is-filter-parameter: Enables filter parameter generation
  • x-cb-resource-id: Links operations to resource models
  • x-cb-is-money-column: Special handling for monetary values

πŸ§ͺ Testing

Run the test suite:

# Run all tests
./gradlew test

# Run tests with coverage
./gradlew test jacocoTestReport

View coverage report at build/jacocoHtml/index.html

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for new functionality
  5. Run tests: ./gradlew test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Code Style

  • Follow Java naming conventions
  • Use meaningful variable and method names
  • Add JavaDoc comments for public APIs
  • Ensure all tests pass before submitting

πŸ“ Examples

Generating Multiple SDKs

Using Current/Latest Versions (Recommended)

# Generate SDKs using latest versions
./gradlew run --args="-i chargebee_sdk_spec.json -l JAVA -o ../chargebee-java/src/main/java/com/chargebee"
./gradlew run --args="-i chargebee_sdk_spec.json -l PHP_V4 -o ../chargebee-php/src"
./gradlew run --args="-i chargebee_sdk_spec.json -l PYTHON_V3 -o ../chargebee-python/chargebee"
./gradlew run --args="-i chargebee_sdk_spec.json -l TYPESCRIPT_TYPINGS_V3 -o ../chargebee-node/types/"
./gradlew run --args="-i chargebee_sdk_spec.json -l NODE_V3 -o ../chargebee-node/src/resources"

Using Legacy Versions

# Generate SDKs using legacy versions (not recommended for new projects)
./gradlew run --args="-i chargebee_sdk_spec.json -l PYTHON -o ./python-legacy-sdk"
./gradlew run --args="-i chargebee_sdk_spec.json -l NODE -o ./node-legacy-sdk"
./gradlew run --args="-i chargebee_sdk_spec.json -l PHP -o ./php-legacy-sdk"

Batch Generation for Chargebee Client Libraries

Generate SDKs for all supported languages targeting Chargebee's official client library repositories:

Prerequisites: Clone all Chargebee client repositories before running these commands.

Current/Latest Versions

# Generate current versions of SDKs
./gradlew run --args="-i chargebee_sdk_spec.json -l PHP_V4 -o ../chargebee-php/src" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l NODE_V3 -o ../chargebee-node/src/resources" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l PYTHON_V3 -o ../chargebee-python/chargebee" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l RUBY -o ../chargebee-ruby/lib/chargebee" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l TYPESCRIPT_TYPINGS_V3 -o ../chargebee-node/types/" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l JAVA -o ../chargebee-java/src/main/java/com/chargebee" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l DOTNET -o ../chargebee-dotnet/ChargeBee" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l GO -o ../chargebee-go" &&

echo "Current SDK versions generated successfully."

Legacy Versions (For Backward Compatibility)

# Generate legacy versions of SDKs
./gradlew run --args="-i chargebee_sdk_spec.json -l PHP -o ../chargebee-php/lib" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l NODE -o ../chargebee-node/lib/resources" &&

./gradlew run --args="-i chargebee_sdk_spec.json -l PYTHON -o ../chargebee-python/chargebee" &&

echo "Legacy SDK versions generated successfully."

Note for Node.js (NODE_V3)

After generating the Node.js SDK (NODE_V3), run the following command in the SDK output directory to format the code:

npx prettier --write .

Note for Python (PYTHON_V3)

After generating the Python SDK (PYTHON_V3), run the following command in the SDK output directory to format the code:

black .

Note for GO

After generating the GO SDK, run the following command in the SDK output directory to format the code:

gofmt -w .

Repository Structure

The above commands assume the following repository structure with cloned Chargebee repositories:

parent-directory/
β”œβ”€β”€ sdk-generator/                 # This repository
β”œβ”€β”€ cb-openapi-generator/         # OpenAPI specifications
β”œβ”€β”€ chargebee-php/                # https://github.com/chargebee/chargebee-php
β”œβ”€β”€ chargebee-node/               # https://github.com/chargebee/chargebee-node
β”œβ”€β”€ chargebee-python/             # https://github.com/chargebee/chargebee-python
β”œβ”€β”€ chargebee-ruby/               # https://github.com/chargebee/chargebee-ruby
β”œβ”€β”€ chargebee-java/               # https://github.com/chargebee/chargebee-java
β”œβ”€β”€ chargebee-dotnet/             # https://github.com/chargebee/chargebee-dotnet
└── chargebee-go/                 # https://github.com/chargebee/chargebee-go

Important: The generator updates existing code within these repositories. Ensure you have the latest version of each repository before generating SDKs.

Feedback

If you find any bugs or have any questions / feedback, open an issue in this repository or reach out to us on [email protected]

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ”— Related Projects


Made with ❀️ by chargebee

About

Chargeebee's SDK generator framework

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5