From f5dda2d45483312b38de5aa2a8e7a9d2b53aa90f Mon Sep 17 00:00:00 2001 From: Kratos2k7 Date: Wed, 8 Apr 2026 10:25:33 +0500 Subject: [PATCH] fix: --template-dir added back to PHP/Python/Ruby scripts (config templateDir resolves relative to config file, not CWD) --- .github/workflows/regenerate-sdk.yml | 33 +++++++++++++++++++++------- scripts/sdk/generate-node.sh | 10 +++++---- scripts/sdk/generate-php.sh | 1 + scripts/sdk/generate-python.sh | 3 ++- scripts/sdk/generate-ruby.sh | 1 + scripts/sdk/generate-typescript.sh | 6 +++-- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/.github/workflows/regenerate-sdk.yml b/.github/workflows/regenerate-sdk.yml index 0d2abee..93dea0e 100644 --- a/.github/workflows/regenerate-sdk.yml +++ b/.github/workflows/regenerate-sdk.yml @@ -126,16 +126,28 @@ jobs: "${{ github.workspace }}/_generated" \ "${{ steps.version.outputs.sdk_version }}" + - name: Debug generated output + run: | + echo "Generated output structure:" + ls -la _generated/ 2>/dev/null || echo "ERROR: _generated/ does not exist!" + if [ "${{ inputs.language }}" = "node" ] || [ "${{ inputs.language }}" = "typescript" ]; then + ls -la _generated/src/generated/ 2>/dev/null || echo "ERROR: _generated/src/generated/ missing!" + elif [ "${{ inputs.language }}" = "php" ]; then + ls -la _generated/src/ 2>/dev/null || echo "ERROR: _generated/src/ missing!" + elif [ "${{ inputs.language }}" = "python" ]; then + ls -la _generated/shotstack_sdk/ 2>/dev/null || echo "ERROR: _generated/shotstack_sdk/ missing!" + elif [ "${{ inputs.language }}" = "ruby" ]; then + ls -la _generated/lib/shotstack/ 2>/dev/null || echo "ERROR: _generated/lib/shotstack/ missing!" + fi + - name: Copy generated files to SDK repo run: | - # Remove previously generated files (but not .git, README, .github, etc.) + set -e if [ "${{ inputs.language }}" = "node" ] || [ "${{ inputs.language }}" = "typescript" ]; then rm -rf src/generated/ dist/ mkdir -p src/generated/ cp -r _generated/src/generated/* src/generated/ - # Copy src/index.ts if generated [ -f _generated/src/index.ts ] && cp _generated/src/index.ts src/index.ts - # Update package.json version only (preserve custom fields) if [ -f _generated/package.json ]; then node -e " const pkg = JSON.parse(require('fs').readFileSync('package.json', 'utf-8')); @@ -144,19 +156,24 @@ jobs: require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); " fi - # Copy tsconfig if generated and none exists [ -f _generated/tsconfig.json ] && [ ! -f tsconfig.json ] && cp _generated/tsconfig.json tsconfig.json elif [ "${{ inputs.language }}" = "php" ]; then rm -rf src/Api/ src/Model/ src/ApiException.php src/Configuration.php src/HeaderSelector.php src/ObjectSerializer.php - cp -r _generated/src/* src/ 2>/dev/null || true - cp -r _generated/lib/* src/ 2>/dev/null || true + cp -r _generated/src/* src/ elif [ "${{ inputs.language }}" = "python" ]; then rm -rf shotstack_sdk/api/ shotstack_sdk/model/ shotstack_sdk/models/ - cp -r _generated/shotstack_sdk/* shotstack_sdk/ 2>/dev/null || true + cp -r _generated/shotstack_sdk/* shotstack_sdk/ + # Generator v5.4.0 outputs to models/ but SDK expects model/ + if [ -d shotstack_sdk/models ] && [ ! -d shotstack_sdk/model ]; then + mv shotstack_sdk/models shotstack_sdk/model + mkdir -p shotstack_sdk/models + echo "from shotstack_sdk.model import *" > shotstack_sdk/models/__init__.py + fi elif [ "${{ inputs.language }}" = "ruby" ]; then rm -rf lib/shotstack/api/ lib/shotstack/models/ - cp -r _generated/lib/shotstack/* lib/shotstack/ 2>/dev/null || true + cp -r _generated/lib/shotstack/* lib/shotstack/ fi + echo "Copy complete for ${{ inputs.language }}" - name: Run post-generate script if: hashFiles('scripts/post-generate.sh') != '' diff --git a/scripts/sdk/generate-node.sh b/scripts/sdk/generate-node.sh index 34dafd7..106d5a3 100644 --- a/scripts/sdk/generate-node.sh +++ b/scripts/sdk/generate-node.sh @@ -18,14 +18,16 @@ echo "Generating Node/TypeScript SDK v${VERSION}..." mkdir -p "${OUTPUT_DIR}/src/generated" -# hey-api resolves $ref from the spec's directory, so we must run from OAS root -# and point at the YAML source (not the bundled JSON) to resolve all refs. -# The bundled JSON has unresolved example $refs that hey-api tries to follow. +# hey-api resolves $ref from the spec's directory, so we pass the absolute path +# to the YAML source. The bundled JSON has unresolved example $refs that hey-api +# tries to follow, so we use the original YAML instead. +# Run npx from the OAS root so it finds the locally-installed hey-api package. cd "${OAS_ROOT}" npx @hey-api/openapi-ts \ - --input "./api.oas3.yaml" \ + --input "${OAS_ROOT}/api.oas3.yaml" \ --output "${OUTPUT_DIR}/src/generated" \ --plugins @hey-api/typescript @hey-api/sdk +cd - # Write package.json for the generated SDK cat > "${OUTPUT_DIR}/package.json" << EOF diff --git a/scripts/sdk/generate-php.sh b/scripts/sdk/generate-php.sh index 01b06bd..aa3df82 100644 --- a/scripts/sdk/generate-php.sh +++ b/scripts/sdk/generate-php.sh @@ -22,6 +22,7 @@ npx @openapitools/openapi-generator-cli generate \ -g php \ -c "${CONFIGS_DIR}/php.yaml" \ -o "${OUTPUT_DIR}" \ + --template-dir "${OAS_ROOT}/templates/php" \ --additional-properties=invokerPackage=Shotstack\\Client,licenseName="MIT",composerPackageName="shotstack/shotstack-sdk-php",srcBasePath="src",artifactVersion="${VERSION}",artifactUrl="https://shotstack.io",developerOrganization="Shotstack",developerOrganizationUrl="https://shotstack.io" echo "PHP SDK generated at ${OUTPUT_DIR}" diff --git a/scripts/sdk/generate-python.sh b/scripts/sdk/generate-python.sh index d006cb2..995d8d3 100644 --- a/scripts/sdk/generate-python.sh +++ b/scripts/sdk/generate-python.sh @@ -24,13 +24,14 @@ echo "Using openapi-generator v${PYTHON_GENERATOR_VERSION} (Python requires lega npx @openapitools/openapi-generator-cli version-manager set "${PYTHON_GENERATOR_VERSION}" -# cd to OAS root so config-relative paths (templateDir: templates/python) resolve +# cd to OAS root for consistent working directory cd "${OAS_ROOT}" npx @openapitools/openapi-generator-cli generate \ -i "${SPEC_FILE}" \ -g python \ -c "${CONFIGS_DIR}/python.yaml" \ -o "${OUTPUT_DIR}" \ + --template-dir "${OAS_ROOT}/templates/python" \ --additional-properties=packageName="shotstack_sdk",projectName="shotstack-sdk",pythonAttrNoneIfUnset=true,packageVersion="${VERSION}",packageUrl="https://shotstack.io/product/sdk/python/",infoName="Shotstack",infoEmail="pypi@shotstack.io",licenseInfo="MIT" echo "Python SDK generated at ${OUTPUT_DIR}" diff --git a/scripts/sdk/generate-ruby.sh b/scripts/sdk/generate-ruby.sh index ec71a73..76ad721 100644 --- a/scripts/sdk/generate-ruby.sh +++ b/scripts/sdk/generate-ruby.sh @@ -22,6 +22,7 @@ npx @openapitools/openapi-generator-cli generate \ -g ruby \ -c "${CONFIGS_DIR}/ruby.yaml" \ -o "${OUTPUT_DIR}" \ + --template-dir "${OAS_ROOT}/templates/ruby" \ --additional-properties=moduleName="Shotstack",gemAuthor="Shotstack",gemAuthorEmail="ruby@shotstack.io",gemHomepage="https://shotstack.io/product/sdk/ruby/",gemLicense="MIT",gemVersion="${VERSION}" echo "Ruby SDK generated at ${OUTPUT_DIR}" diff --git a/scripts/sdk/generate-typescript.sh b/scripts/sdk/generate-typescript.sh index 789c4f1..68a7857 100644 --- a/scripts/sdk/generate-typescript.sh +++ b/scripts/sdk/generate-typescript.sh @@ -18,12 +18,14 @@ echo "Generating TypeScript SDK v${VERSION}..." mkdir -p "${OUTPUT_DIR}/src/generated" -# hey-api resolves $ref from the spec's directory, so we must run from OAS root +# hey-api resolves $ref from the spec's directory, so we pass the absolute path +# to the YAML source. Run npx from OAS root so it finds the locally-installed package. cd "${OAS_ROOT}" npx @hey-api/openapi-ts \ - --input "./api.oas3.yaml" \ + --input "${OAS_ROOT}/api.oas3.yaml" \ --output "${OUTPUT_DIR}/src/generated" \ --plugins @hey-api/typescript @hey-api/sdk +cd - # Write package.json cat > "${OUTPUT_DIR}/package.json" << EOF