Skip to content

Validate OpenAPI Generator SDK generation #1

Validate OpenAPI Generator SDK generation

Validate OpenAPI Generator SDK generation #1

name: OpenAPI Generator SDK Validation
run-name: Validate OpenAPI Generator SDK generation
on:
pull_request:
paths:
# OpenAPI Generator files
- 'client-sdks/openapi/Makefile'
- 'client-sdks/openapi/merge_stainless_config.py'
- 'client-sdks/openapi/build_hierarchy.py'
- 'client-sdks/openapi/patch_hierarchy.py'
- 'client-sdks/openapi/patches.yml'
- 'client-sdks/openapi/openapi-config.json'
- 'client-sdks/openapi/openapitools.json'
- 'client-sdks/openapi/README.md'
# Stainless source files (our inputs)
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
# This workflow itself
- '.github/workflows/openapi-generator-validation.yml'
merge_group:
branches:
- main
- 'release-[0-9]+.[0-9]+.x'
push:
branches:
- main
- 'release-[0-9]+.[0-9]+.x'
paths:
- 'client-sdks/openapi/**'
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
- '.github/workflows/openapi-generator-validation.yml'
workflow_dispatch:
inputs:
test_macos:
description: 'Force macOS testing (expensive)'
type: boolean
default: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
determine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check which files changed
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
critical:
- 'client-sdks/openapi/Makefile'
- 'client-sdks/openapi/merge_stainless_config.py'
- 'client-sdks/openapi/build_hierarchy.py'
- 'client-sdks/openapi/patch_hierarchy.py'
- 'client-sdks/openapi/patches.yml'
- 'client-sdks/openapi/openapitools.json'
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
- name: Determine test matrix
id: set-matrix
run: |
# Always test on Linux
MATRIX='{"os":["ubuntu-latest"]}'
# Include macOS if:
# 1. Manual workflow_dispatch with test_macos=true
# 2. Push to main/release branches
# 3. Critical files changed in PR
INCLUDE_MACOS="false"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
INCLUDE_MACOS="${{ inputs.test_macos }}"
elif [ "${{ github.event_name }}" = "push" ]; then
# Always test macOS on main/release branches
INCLUDE_MACOS="true"
elif [ "${{ steps.filter.outputs.critical }}" = "true" ]; then
# Critical files changed in PR
INCLUDE_MACOS="true"
fi
if [ "$INCLUDE_MACOS" = "true" ]; then
MATRIX='{"os":["ubuntu-latest","macos-latest"]}'
fi
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
echo "Testing on platforms: $MATRIX"
validate-sdk-generation:
needs: determine-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.determine-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Python environment
uses: ./.github/actions/setup-runner
with:
python-version: '3.12'
- name: Set up Java
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: '11'
- name: Set up Node.js (Linux only)
if: runner.os == 'Linux'
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '22'
- name: Install openapi-generator-cli (Linux)
if: runner.os == 'Linux'
run: npm install -g @openapitools/openapi-generator-cli
- name: Install openapi-generator-cli (macOS)
if: runner.os == 'macOS'
run: brew install openapi-generator
- name: Verify installations
working-directory: client-sdks/openapi
run: |
set -e
GENERATOR_CMD=$([ "${{ runner.os }}" = "macOS" ] && echo "openapi-generator" || echo "openapi-generator-cli")
echo "=== Java version ==="
java -version
echo "=== OpenAPI Generator version ==="
$GENERATOR_CMD version
echo "=== SDK version from pyproject.toml ==="
VERSION_OUTPUT=$(make version)
echo "$VERSION_OUTPUT"
# Extract version string
VERSION="${VERSION_OUTPUT#SDK version: }"
# Check version is at least 5 characters (e.g., "0.5.0")
if [ ${#VERSION} -lt 5 ]; then
echo "Error: Version string too short: '$VERSION'"
exit 1
fi
echo "Version validation passed: $VERSION"
- name: Run dependency check
working-directory: client-sdks/openapi
run: make check-generator
- name: Generate OpenAPI spec
working-directory: client-sdks/openapi
run: make openapi
- name: Validate generated OpenAPI spec
working-directory: client-sdks/openapi
run: |
set -e
# Check that openapi.yml was generated
if [ ! -f openapi.yml ]; then
echo "Error: openapi.yml was not generated"
exit 1
fi
echo "OpenAPI spec generated successfully"
ls -lh openapi.yml
- name: Generate Python SDK
working-directory: client-sdks/openapi
run: make sdk
- name: Validate generated SDK
working-directory: client-sdks/openapi
run: |
set -e
# Check SDK directory was generated
if [ ! -d sdks/python ]; then
echo "Error: SDK directory was not generated"
exit 1
fi
# Check we generated a substantial number of Python files (> 10)
PY_FILE_COUNT=$(find sdks/python -name "*.py" | wc -l)
echo "Generated Python files: $PY_FILE_COUNT"
if [ "$PY_FILE_COUNT" -le 10 ]; then
echo "Error: Too few Python files generated (expected > 10, got $PY_FILE_COUNT)"
exit 1
fi
echo "SDK validation passed: $PY_FILE_COUNT Python files generated"
# Show directory structure for debugging
echo "=== Generated SDK structure ==="
find sdks/python -type f -name "*.py" | head -20