Skip to content

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 โ€‹

  1. Update OpenAPI specification version
  2. Validate specification with Spectral
  3. Generate all clients with new version
  4. Test generated clients against live API
  5. Update documentation with new features
  6. Tag and release clients

๐Ÿ“Š Generator Comparison โ€‹

LanguageGeneratorLibraryType SafetyAsync SupportCommunity
Rubyrubyfaradayโญโญโญโœ…โญโญโญโญโญ
TypeScripttypescript-fetchfetchโญโญโญโญโญโœ…โญโญโญโญโญ
Pythonpythonrequestsโญโญโญโœ…โญโญโญโญโญ
Gogonet/httpโญโญโญโญโญโœ…โญโญโญโญ
Javajavaokhttp-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 โ€‹

๐Ÿ”„ Navigation โ€‹


Need help? Check the troubleshooting section above or reach out to the OpenAPI Generator community for support.

Released under the Apache-2.0 License.