From 36b57af0cf69485b4635d8b561b84cc8742030f2 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Wed, 23 Jul 2025 16:04:27 -0700 Subject: [PATCH 01/10] Development SDK generation script patch, for playing nice with SciCatLive. --- scripts/generate-nestjs-sdk.bash | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 3c6b81f2e..2fbf0cee6 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -2,12 +2,38 @@ # # +USING_SCICAT_LIVE=0 +while [[ "$#" -gt 0 ]]; do + case "$1" in + --scicatlive) + USING_SCICAT_LIVE=1 + shift + ;; + *) + echo "Unknown argument: $1" + exit 1 + ;; + esac +done + USER=`who am i | cut -d\ -f1` echo -e "\nUser running the script: ${USER}" echo -e "\nCleanup old files..." rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular rm -rf @scicatproject/scicat-sdk-ts-angular +rm local-api-for-generator.json + +echo -e "\nFetching the API from local instance of back end..." + +if [ $USING_SCICAT_LIVE -eq 1 ]; +then + # For when developing with SciCat Live: + curl http://backend.localhost/explorer-json > local-api-for-generator.json +else + # For when developing with a backend running directly on localhost: + curl http://host.docker.internal:3000/explorer-json > local-api-for-generator.json +fi echo -e "\nGenerating the new sdk..." @@ -25,6 +51,16 @@ docker run \ -o local/@scicatproject/scicat-sdk-ts-angular \ --additional-properties=ngVersion=19.0.0,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,withInterfaces=true --skip-validate-spec +# Check if the docker command resulted in any output. +# If we don't do this, we'll try to cd into a missing folder, +# and then we'd be invoking 'npm run build' as root in the main project folder, +# which would create a bunch of stuff in ./dist belonging to root, +# causing problems for things like SciCat Live. +if [ ! -d "@scicatproject/scicat-sdk-ts-angular" ]; then + echo "Error: OpenApi output not found." + exit 1 +fi + REMOVE_NPM_LINK=0 if ! command -v npm 2>&1 1>/dev/null then From 648608906c4c15f865da58a8a6a0926a5bc74c14 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Mon, 4 Aug 2025 11:19:28 -0700 Subject: [PATCH 02/10] Forgot to include a few lines from my development branch... --- scripts/generate-nestjs-sdk.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 2fbf0cee6..cd45d2c3b 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -43,10 +43,9 @@ echo -e "\nGenerating the new sdk..." ## docker run \ --rm \ - --add-host host.docker.internal:host-gateway \ -v "`pwd`:/local" \ openapitools/openapi-generator-cli:v7.13.0 generate \ - -i http://host.docker.internal:3000/explorer-json \ + -i /local/local-api-for-generator.json \ -g typescript-angular \ -o local/@scicatproject/scicat-sdk-ts-angular \ --additional-properties=ngVersion=19.0.0,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,withInterfaces=true --skip-validate-spec From 39a099b1a558709bc10c7943519c8cb7dd639964 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Fri, 8 Aug 2025 12:48:09 -0700 Subject: [PATCH 03/10] Accepting an alternate Swagger URL via command line argument. --- scripts/generate-nestjs-sdk.bash | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index cd45d2c3b..05d03ba56 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -1,12 +1,13 @@ #!/bin/bash # -# -USING_SCICAT_LIVE=0 +# This default is for when developing with a backend running directly on localhost +SWAGGER_API_URL="http://localhost:3000/explorer-json" while [[ "$#" -gt 0 ]]; do case "$1" in - --scicatlive) - USING_SCICAT_LIVE=1 + --swagger-url) + shift + SWAGGER_API_URL=$1 shift ;; *) @@ -24,16 +25,8 @@ rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular rm -rf @scicatproject/scicat-sdk-ts-angular rm local-api-for-generator.json -echo -e "\nFetching the API from local instance of back end..." - -if [ $USING_SCICAT_LIVE -eq 1 ]; -then - # For when developing with SciCat Live: - curl http://backend.localhost/explorer-json > local-api-for-generator.json -else - # For when developing with a backend running directly on localhost: - curl http://host.docker.internal:3000/explorer-json > local-api-for-generator.json -fi +echo -e "\nFetching the Swagger API from the back end..." +curl ${SWAGGER_API_URL} > local-api-for-generator.json echo -e "\nGenerating the new sdk..." @@ -50,6 +43,8 @@ docker run \ -o local/@scicatproject/scicat-sdk-ts-angular \ --additional-properties=ngVersion=19.0.0,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,withInterfaces=true --skip-validate-spec +rm local-api-for-generator.json + # Check if the docker command resulted in any output. # If we don't do this, we'll try to cd into a missing folder, # and then we'd be invoking 'npm run build' as root in the main project folder, @@ -99,4 +94,3 @@ then rm -fv "/usr/local/bin/npm" rm -fv "/usr/local/bin/node" fi - From 87eae686ca5a635721c2597bc120c0f8776910d4 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Thu, 14 Aug 2025 17:11:09 -0700 Subject: [PATCH 04/10] Version bump for OpenAPI generator. --- scripts/generate-nestjs-sdk.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 05d03ba56..242d5fdcd 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -37,7 +37,7 @@ echo -e "\nGenerating the new sdk..." docker run \ --rm \ -v "`pwd`:/local" \ - openapitools/openapi-generator-cli:v7.13.0 generate \ + openapitools/openapi-generator-cli:v7.14.0 generate \ -i /local/local-api-for-generator.json \ -g typescript-angular \ -o local/@scicatproject/scicat-sdk-ts-angular \ From 8d5afffc5104d6e8937658a1be5a06ddf17ee2a4 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Thu, 14 Aug 2025 17:11:42 -0700 Subject: [PATCH 05/10] Useful message when build output is not found. Halts before deleting, so user can run attempt manual build. --- scripts/generate-nestjs-sdk.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 242d5fdcd..c21ec557e 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -77,6 +77,11 @@ cd @scicatproject/scicat-sdk-ts-angular npm install npm run build +if [ ! -d "@scicatproject/scicat-sdk-ts-angular/dist" ]; then + echo "Error: Build ouput not found." + exit 1 +fi + echo -e "\nCopying the build files in node_modules..." cd ../.. cp -rv @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular From 63797c6dc915b1cd9eed465e8e61e59a3bff84dd Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Thu, 14 Aug 2025 17:12:56 -0700 Subject: [PATCH 06/10] A debugging note. --- scripts/generate-nestjs-sdk.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index c21ec557e..0a22b5cdc 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -74,6 +74,7 @@ fi echo -e "\nInstalling dependencies and building the sdk..." cd @scicatproject/scicat-sdk-ts-angular +# If this fails mysteriously you may need to run 'npm cache verify'. npm install npm run build From 222b79a1399ae16623016ddb8195e493a98569a3 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Wed, 3 Sep 2025 13:22:35 -0700 Subject: [PATCH 07/10] Further refinements to the SDK generation script. --- scripts/generate-nestjs-sdk.bash | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 0a22b5cdc..7575248f6 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -1,6 +1,13 @@ #!/bin/bash # +# Note: This script is meant to be run from the project root, e.g. +# ./scripts/generate-nestjs-sdk.bash +if [ ! -d "node_modules" ]; then + echo "Error: No node_modules folder found. This script is means to be run from the project root." + exit 1 +fi + # This default is for when developing with a backend running directly on localhost SWAGGER_API_URL="http://localhost:3000/explorer-json" while [[ "$#" -gt 0 ]]; do @@ -77,14 +84,15 @@ cd @scicatproject/scicat-sdk-ts-angular # If this fails mysteriously you may need to run 'npm cache verify'. npm install npm run build +cd ../.. if [ ! -d "@scicatproject/scicat-sdk-ts-angular/dist" ]; then echo "Error: Build ouput not found." exit 1 fi -echo -e "\nCopying the build files in node_modules..." -cd ../.. +echo -e "\nCopying the build files into node_modules..." +mkdir -p node_modules/@scicatproject/scicat-sdk-ts-angular cp -rv @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular echo -e "\nAdjusting ownership to user ${USER}" @@ -92,7 +100,7 @@ chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts-angular echo -e "\nFinal cleanup..." echo -e "Removing sdk folder" -rm -rfv @scicatproject +rm -rf @scicatproject if [ $REMOVE_NPM_LINK -eq 1 ]; then @@ -100,3 +108,5 @@ then rm -fv "/usr/local/bin/npm" rm -fv "/usr/local/bin/node" fi + +echo -e "\nDone." \ No newline at end of file From a2cdf46ab6c2a8833f34eca73d831cfb8920367d Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Wed, 3 Sep 2025 13:26:06 -0700 Subject: [PATCH 08/10] Minor fix to SDK copy paths. --- scripts/generate-nestjs-sdk.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 7575248f6..26174ebd0 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -93,7 +93,7 @@ fi echo -e "\nCopying the build files into node_modules..." mkdir -p node_modules/@scicatproject/scicat-sdk-ts-angular -cp -rv @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular +cp -rv @scicatproject/scicat-sdk-ts-angular/dist/ node_modules/@scicatproject/scicat-sdk-ts-angular/ echo -e "\nAdjusting ownership to user ${USER}" chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts-angular From 8cc98750d4542f40865a3092050780212963edbd Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Thu, 4 Sep 2025 12:22:37 -0700 Subject: [PATCH 09/10] Allowing SWAGGER_API_URL environment variable. --- scripts/generate-nestjs-sdk.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index 26174ebd0..b008c5014 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -4,12 +4,12 @@ # Note: This script is meant to be run from the project root, e.g. # ./scripts/generate-nestjs-sdk.bash if [ ! -d "node_modules" ]; then - echo "Error: No node_modules folder found. This script is means to be run from the project root." + echo "Error: No node_modules folder found. This script is meant to be run from the project root." exit 1 fi # This default is for when developing with a backend running directly on localhost -SWAGGER_API_URL="http://localhost:3000/explorer-json" +SWAGGER_API_URL=${SWAGGER_API_URL:-"http://localhost:3000/explorer-json"} while [[ "$#" -gt 0 ]]; do case "$1" in --swagger-url) From 984e50b67fc79debfbf7981e96cd81fbaecee916 Mon Sep 17 00:00:00 2001 From: Garrett Birkel Date: Mon, 8 Sep 2025 12:48:17 -0700 Subject: [PATCH 10/10] Using the same config file that the back end CI code uses to configure the API generator. --- scripts/generate-nestjs-sdk.bash | 14 +++++++++----- scripts/typescript-angular-config.json | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 scripts/typescript-angular-config.json diff --git a/scripts/generate-nestjs-sdk.bash b/scripts/generate-nestjs-sdk.bash index b008c5014..d9349f70b 100755 --- a/scripts/generate-nestjs-sdk.bash +++ b/scripts/generate-nestjs-sdk.bash @@ -27,9 +27,9 @@ done USER=`who am i | cut -d\ -f1` echo -e "\nUser running the script: ${USER}" -echo -e "\nCleanup old files..." -rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular +echo -e "\nCleaning up from any previous run..." rm -rf @scicatproject/scicat-sdk-ts-angular +mkdir -p @scicatproject/scicat-sdk-ts-angular rm local-api-for-generator.json echo -e "\nFetching the Swagger API from the back end..." @@ -44,12 +44,14 @@ echo -e "\nGenerating the new sdk..." docker run \ --rm \ -v "`pwd`:/local" \ - openapitools/openapi-generator-cli:v7.14.0 generate \ + openapitools/openapi-generator-cli:v7.13.0 generate \ -i /local/local-api-for-generator.json \ + -c /local/scripts/typescript-angular-config.json \ -g typescript-angular \ -o local/@scicatproject/scicat-sdk-ts-angular \ - --additional-properties=ngVersion=19.0.0,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,withInterfaces=true --skip-validate-spec + --additional-properties=supportsES6=true --skip-validate-spec +# Clean this up immediately after use, in case subsequent steps fail. rm local-api-for-generator.json # Check if the docker command resulted in any output. @@ -57,7 +59,7 @@ rm local-api-for-generator.json # and then we'd be invoking 'npm run build' as root in the main project folder, # which would create a bunch of stuff in ./dist belonging to root, # causing problems for things like SciCat Live. -if [ ! -d "@scicatproject/scicat-sdk-ts-angular" ]; then +if [ ! -d "@scicatproject/scicat-sdk-ts-angular/api" ]; then echo "Error: OpenApi output not found." exit 1 fi @@ -91,6 +93,8 @@ if [ ! -d "@scicatproject/scicat-sdk-ts-angular/dist" ]; then exit 1 fi +echo -e "\nRemoving existing version from node_modules..." +rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular echo -e "\nCopying the build files into node_modules..." mkdir -p node_modules/@scicatproject/scicat-sdk-ts-angular cp -rv @scicatproject/scicat-sdk-ts-angular/dist/ node_modules/@scicatproject/scicat-sdk-ts-angular/ diff --git a/scripts/typescript-angular-config.json b/scripts/typescript-angular-config.json new file mode 100644 index 000000000..7291e03e2 --- /dev/null +++ b/scripts/typescript-angular-config.json @@ -0,0 +1,9 @@ +{ + "generatorName": "typescript-angular", + "npmName": "@scicatproject/scicat-sdk-ts-angular", + "ngVersion": "19.0.0", + "withInterfaces": true, + "paramNaming": "original", + "modelPropertyNaming": "original", + "enumPropertyNaming": "original" +}