1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

test: sync open api spec (#9687)

test: sync spec file
This commit is contained in:
Jason Rasmussen 2024-05-23 07:40:57 -04:00 committed by GitHub
parent a5e8b451b2
commit e7aa50425c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 45 additions and 16 deletions

View file

@ -260,9 +260,18 @@ jobs:
name: OpenAPI Clients name: OpenAPI Clients
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- 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 generation - name: Run API generation
run: make open-api run: make open-api
- name: Find file changes - name: Find file changes
uses: tj-actions/verify-changed-files@v20 uses: tj-actions/verify-changed-files@v20
id: verify-changed-files id: verify-changed-files
@ -270,6 +279,8 @@ jobs:
files: | files: |
mobile/openapi mobile/openapi
open-api/typescript-sdk open-api/typescript-sdk
open-api/immich-openapi-specs.json
- name: Verify files have not changed - name: Verify files have not changed
if: steps.verify-changed-files.outputs.files_changed == 'true' if: steps.verify-changed-files.outputs.files_changed == 'true'
run: | run: |
@ -332,7 +343,7 @@ jobs:
exit 1 exit 1
- name: Run SQL generation - name: Run SQL generation
run: npm run sql:generate run: npm run sync:sql
env: env:
DB_URL: postgres://postgres:postgres@localhost:5432/immich DB_URL: postgres://postgres:postgres@localhost:5432/immich

View file

@ -37,7 +37,7 @@ open-api-typescript:
cd ./open-api && bash ./bin/generate-open-api.sh typescript cd ./open-api && bash ./bin/generate-open-api.sh typescript
sql: sql:
npm --prefix server run sql:generate npm --prefix server run sync:sql
attach-server: attach-server:
docker exec -it docker_immich-server_1 sh docker exec -it docker_immich-server_1 sh

View file

@ -62,6 +62,8 @@ fi
if [ "$CURRENT_SERVER" != "$NEXT_SERVER" ]; then if [ "$CURRENT_SERVER" != "$NEXT_SERVER" ]; then
echo "Pumping Server: $CURRENT_SERVER => $NEXT_SERVER" echo "Pumping Server: $CURRENT_SERVER => $NEXT_SERVER"
npm --prefix server version "$SERVER_PUMP" npm --prefix server version "$SERVER_PUMP"
npm --prefix server ci
npm --prefix server run build
make open-api make open-api
npm --prefix open-api/typescript-sdk version "$SERVER_PUMP" npm --prefix open-api/typescript-sdk version "$SERVER_PUMP"
npm --prefix web version "$SERVER_PUMP" npm --prefix web version "$SERVER_PUMP"

View file

@ -24,7 +24,8 @@ function typescript {
npm --prefix typescript-sdk ci && npm --prefix typescript-sdk run build 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=../server
if [[ $1 == 'dart' ]]; then if [[ $1 == 'dart' ]]; then
dart dart

View file

@ -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)
);

View file

@ -30,7 +30,8 @@
"typeorm:migrations:revert": "typeorm migration:revert -d ./dist/database.config.js", "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: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", "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" "email:dev": "email dev -p 3050 --dir src/emails"
}, },
"dependencies": { "dependencies": {

View file

@ -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);
});

View file

@ -174,7 +174,7 @@ const patchOpenAPI = (document: OpenAPIObject) => {
return document; return document;
}; };
export const useSwagger = (app: INestApplication) => { export const useSwagger = (app: INestApplication, force = false) => {
const config = new DocumentBuilder() const config = new DocumentBuilder()
.setTitle('Immich') .setTitle('Immich')
.setDescription('Immich API') .setDescription('Immich API')
@ -211,7 +211,7 @@ export const useSwagger = (app: INestApplication) => {
SwaggerModule.setup('doc', app, specification, customOptions); SwaggerModule.setup('doc', app, specification, customOptions);
if (isDev()) { if (isDev() || force) {
// Generate API Documentation only in development mode // Generate API Documentation only in development mode
const outputPath = path.resolve(process.cwd(), '../open-api/immich-openapi-specs.json'); const outputPath = path.resolve(process.cwd(), '../open-api/immich-openapi-specs.json');
writeFileSync(outputPath, JSON.stringify(patchOpenAPI(specification), null, 2), { encoding: 'utf8' }); writeFileSync(outputPath, JSON.stringify(patchOpenAPI(specification), null, 2), { encoding: 'utf8' });