High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
test: sync open api spec (#9687)
Jason Rasmussene7aa50425c43
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 7603c6fb7c..ab22f255ee 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -260,9 +260,18 @@ jobs:name: OpenAPI Clientsruns-on: ubuntu-lateststeps:- - uses: actions/checkout@v4+ - name: Checkout code+ uses: actions/checkout@v4++ - name: Install server dependencies+ run: npm --prefix=server ci++ - name: Build the app+ run: npm --prefix=server run build+- name: Run API generationrun: make open-api+- name: Find file changesuses: tj-actions/verify-changed-files@v20id: verify-changed-files@@ -270,6 +279,8 @@ jobs:files: |mobile/openapiopen-api/typescript-sdk+ open-api/immich-openapi-specs.json+- name: Verify files have not changedif: steps.verify-changed-files.outputs.files_changed == 'true'run: |@@ -332,7 +343,7 @@ jobs:exit 1- name: Run SQL generation- run: npm run sql:generate+ run: npm run sync:sqlenv:DB_URL: postgres://postgres:postgres@localhost:5432/immichdiff --git a/Makefile b/Makefileindex ede70237fe..b7fe03591c 100644--- a/Makefile+++ b/Makefile@@ -37,7 +37,7 @@ open-api-typescript:cd ./open-api && bash ./bin/generate-open-api.sh typescriptsql:- npm --prefix server run sql:generate+ npm --prefix server run sync:sqlattach-server:docker exec -it docker_immich-server_1 shdiff --git a/misc/release/pump-version.sh b/misc/release/pump-version.shindex 14f0b3a817..0d0ae4b9e2 100755--- a/misc/release/pump-version.sh+++ b/misc/release/pump-version.sh@@ -62,6 +62,8 @@ fiif [ "$CURRENT_SERVER" != "$NEXT_SERVER" ]; thenecho "Pumping Server: $CURRENT_SERVER => $NEXT_SERVER"npm --prefix server version "$SERVER_PUMP"+ npm --prefix server ci+ npm --prefix server run buildmake open-apinpm --prefix open-api/typescript-sdk version "$SERVER_PUMP"npm --prefix web version "$SERVER_PUMP"diff --git a/open-api/bin/generate-open-api.sh b/open-api/bin/generate-open-api.shindex 4eb121102d..a00d57d0ae 100755--- a/open-api/bin/generate-open-api.sh+++ b/open-api/bin/generate-open-api.sh@@ -24,7 +24,8 @@ function typescript {npm --prefix typescript-sdk ci && npm --prefix typescript-sdk run build}-node ./bin/sync-spec-version.js+# requires server to be built+npm run sync:open-api --prefix=../serverif [[ $1 == 'dart' ]]; thendartdiff --git a/open-api/bin/sync-spec-version.js b/open-api/bin/sync-spec-version.jsdeleted file mode 100644index 98c52413e6..0000000000--- a/open-api/bin/sync-spec-version.js+++ /dev/null@@ -1,9 +0,0 @@-const spec = require('../immich-openapi-specs.json');-const pkg = require('../../server/package.json');-const path = require('path');-const fs = require('fs');-spec.info.version = pkg.version;-fs.writeFileSync(- path.join(__dirname, '../immich-openapi-specs.json'),- JSON.stringify(spec, null, 2)-);diff --git a/server/package.json b/server/package.jsonindex 6265c6d928..e657ca0757 100644--- a/server/package.json+++ b/server/package.json@@ -30,7 +30,8 @@"typeorm:migrations:revert": "typeorm migration:revert -d ./dist/database.config.js","typeorm:schema:drop": "typeorm query -d ./dist/database.config.js 'DROP schema public cascade; CREATE schema public;'","typeorm:schema:reset": "npm run typeorm:schema:drop && npm run typeorm:migrations:run",- "sql:generate": "node ./dist/utils/sql.js",+ "sync:open-api": "node ./dist/bin/sync-open-api.js",+ "sync:sql": "node ./dist/bin/sync-sql.js","email:dev": "email dev -p 3050 --dir src/emails"},"dependencies": {diff --git a/server/src/bin/sync-open-api.ts b/server/src/bin/sync-open-api.tsnew file mode 100644index 0000000000..70e2bb8c35--- /dev/null+++ b/server/src/bin/sync-open-api.ts@@ -0,0 +1,23 @@+#!/usr/bin/env node+process.env.DB_URL = 'postgres://postgres:postgres@localhost:5432/immich';+import { NestFactory } from '@nestjs/core';+import { NestExpressApplication } from '@nestjs/platform-express';+import { ApiModule } from 'src/app.module';+import { useSwagger } from 'src/utils/misc';++const sync = async () => {+ const app = await NestFactory.create<NestExpressApplication>(ApiModule, { preview: true });+ useSwagger(app, true);+ await app.close();+};++sync()+ .then(() => {+ console.log('Done');+ process.exit(0);+ })+ .catch((error) => {+ console.error(error);+ console.log('Something went wrong');+ process.exit(1);+ });diff --git a/server/src/utils/sql.ts b/server/src/bin/sync-sql.tssimilarity index 100%rename from server/src/utils/sql.tsrename to server/src/bin/sync-sql.tsdiff --git a/server/src/utils/misc.ts b/server/src/utils/misc.tsindex 910bc0962a..f5c0105c03 100644--- a/server/src/utils/misc.ts+++ b/server/src/utils/misc.ts@@ -174,7 +174,7 @@ const patchOpenAPI = (document: OpenAPIObject) => {return document;};-export const useSwagger = (app: INestApplication) => {+export const useSwagger = (app: INestApplication, force = false) => {const config = new DocumentBuilder().setTitle('Immich').setDescription('Immich API')@@ -211,7 +211,7 @@ export const useSwagger = (app: INestApplication) => {SwaggerModule.setup('doc', app, specification, customOptions);- if (isDev()) {+ if (isDev() || force) {// Generate API Documentation only in development modeconst outputPath = path.resolve(process.cwd(), '../open-api/immich-openapi-specs.json');writeFileSync(outputPath, JSON.stringify(patchOpenAPI(specification), null, 2), { encoding: 'utf8' });