Client Generation Reference โ
Complete reference guide for troubleshooting, testing, and maintaining your generated API clients.
๐งช Testing Generated Clients โ
Basic Functionality Test โ
bash
# Test script for any generated client
#!/bin/bash
echo "๐งช Testing generated client..."
# Test 1: Client can be imported/required
echo "โ
Testing client import..."
# Test 2: Client can connect to API
echo "โ
Testing API connection..."
# Test 3: Client can fetch data
echo "โ
Testing data fetching..."
# Test 4: Client handles errors gracefully
echo "โ
Testing error handling..."
echo "โ
All tests passed!"
Integration Testing โ
yaml
# GitHub Actions workflow for client testing
name: Test Generated Clients
on: [push, pull_request]
jobs:
test-clients:
runs-on: ubuntu-latest
strategy:
matrix:
language: [ruby, python, typescript, go]
steps:
- uses: actions/checkout@v3
- name: Generate ${{ matrix.language }} client
run: |
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i /local/openapi/openapi.yaml \
-g ${{ matrix.language }} \
-o /local/test-client
- name: Test ${{ matrix.language }} client
run: |
cd test-client
# Language-specific test commands
./test-client.sh
๐ Version Management โ
Version Synchronization โ
All generated clients follow the same versioning as the OpenAPI specification:
bash
# Update all clients to new version
VERSION="1.1.0"
# Update specification version
sed -i "s/version: .*/version: $VERSION/" openapi/openapi.yaml
# Regenerate all clients with new version
./scripts/generate-all-clients.sh $VERSION
Client Release Process โ
- Update OpenAPI specification version
- Validate specification with Spectral
- Generate all clients with new version
- Test generated clients against live API
- Update documentation with new features
- Tag and release clients
๐ Generator Comparison โ
Language | Generator | Library | Type Safety | Async Support | Community |
---|---|---|---|---|---|
Ruby | ruby | faraday | โญโญโญ | โ | โญโญโญโญโญ |
TypeScript | typescript-fetch | fetch | โญโญโญโญโญ | โ | โญโญโญโญโญ |
Python | python | requests | โญโญโญ | โ | โญโญโญโญโญ |
Go | go | net/http | โญโญโญโญโญ | โ | โญโญโญโญ |
Java | java | okhttp-gson | โญโญโญโญโญ | โ | โญโญโญโญโญ |
๐ง Troubleshooting โ
Common Issues โ
Issue: Generator not found
bash
# Solution: Update generator list
openapi-generator-cli list | grep python
Issue: Invalid specification
bash
# Solution: Validate specification first
spectral lint openapi/openapi.yaml
Issue: Generated client compilation errors
bash
# Solution: Check generator version compatibility
openapi-generator-cli version
Issue: Docker permission denied
bash
# Solution: Fix Docker permissions
sudo chmod 666 /var/run/docker.sock
# Or run with proper user permissions
docker run --rm -v "${PWD}:/local" --user $(id -u):$(id -g) openapitools/openapi-generator-cli
Issue: Client imports fail
bash
# Solution: Check package structure and dependencies
ls -la generated-client/
# Install required dependencies for your language
Debug Mode โ
bash
# Enable debug output
openapi-generator-cli generate \
-i openapi/openapi.yaml \
-g python \
--enable-post-process-file \
--global-property=debugModels,debugOperations \
-o ./debug-client
Verbose Output โ
bash
# Get detailed generation information
openapi-generator-cli generate \
-i openapi/openapi.yaml \
-g ruby \
--verbose \
-o ./debug-client
๐ Best Practices โ
Generator Selection โ
- โ Use stable generators - Prefer generators marked as stable
- โ Test before production - Always test generated clients
- โ Version consistency - Keep all clients on same spec version
- โ Documentation - Generate documentation with clients
- โ Error handling - Implement proper error handling
Customization โ
- ๐ฏ Custom templates - Modify templates for specific needs
- ๐ฏ Configuration files - Use JSON config for consistency
- ๐ฏ Post-processing - Add custom logic after generation
- ๐ฏ Package metadata - Include proper package information
Development Workflow โ
- ๐ Automate generation - Use scripts for consistent results
- ๐ Version control - Don't commit generated files
- ๐ CI/CD integration - Generate clients in your pipeline
- ๐ Testing pipeline - Validate generated clients automatically
Production Considerations โ
- ๐ Performance - Choose appropriate HTTP libraries
- ๐ Security - Validate all inputs and handle secrets properly
- ๐ Monitoring - Add logging and metrics to generated clients
- ๐ Documentation - Maintain clear usage examples
๐ Resources โ
Documentation โ
Community โ
Related Tools โ
- Spectral - OpenAPI linting
- Swagger Editor - Online specification editor
- Insomnia - API testing with OpenAPI import
- Postman - API development with OpenAPI support
๐ Navigation โ
- Overview - Getting started with client generation
- Language Commands - Ready-to-use generation commands
- Advanced Configuration - Custom templates and automation
- Usage Examples - See generated clients in action
Need help? Check the troubleshooting section above or reach out to the OpenAPI Generator community for support.