Skip to content

Commit

Permalink
test: sync open api spec (immich-app#9687)
Browse files Browse the repository at this point in the history
test: sync spec file
  • Loading branch information
jrasm91 authored May 23, 2024
1 parent a5e8b45 commit e7aa504
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 16 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,27 @@ jobs:
name: OpenAPI Clients
runs-on: ubuntu-latest
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
run: make open-api

- name: Find file changes
uses: tj-actions/verify-changed-files@v20
id: verify-changed-files
with:
files: |
mobile/openapi
open-api/typescript-sdk
open-api/immich-openapi-specs.json
- name: Verify files have not changed
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
Expand Down Expand Up @@ -332,7 +343,7 @@ jobs:
exit 1
- name: Run SQL generation
run: npm run sql:generate
run: npm run sync:sql
env:
DB_URL: postgres://postgres:postgres@localhost:5432/immich

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open-api-typescript:
cd ./open-api && bash ./bin/generate-open-api.sh typescript

sql:
npm --prefix server run sql:generate
npm --prefix server run sync:sql

attach-server:
docker exec -it docker_immich-server_1 sh
2 changes: 2 additions & 0 deletions misc/release/pump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ fi
if [ "$CURRENT_SERVER" != "$NEXT_SERVER" ]; then
echo "Pumping Server: $CURRENT_SERVER => $NEXT_SERVER"
npm --prefix server version "$SERVER_PUMP"
npm --prefix server ci
npm --prefix server run build
make open-api
npm --prefix open-api/typescript-sdk version "$SERVER_PUMP"
npm --prefix web version "$SERVER_PUMP"
Expand Down
3 changes: 2 additions & 1 deletion open-api/bin/generate-open-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=../server

if [[ $1 == 'dart' ]]; then
dart
Expand Down
9 changes: 0 additions & 9 deletions open-api/bin/sync-spec-version.js

This file was deleted.

3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
23 changes: 23 additions & 0 deletions server/src/bin/sync-open-api.ts
Original file line number Diff line number Diff line change
@@ -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);
});
File renamed without changes.
4 changes: 2 additions & 2 deletions server/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 mode
const outputPath = path.resolve(process.cwd(), '../open-api/immich-openapi-specs.json');
writeFileSync(outputPath, JSON.stringify(patchOpenAPI(specification), null, 2), { encoding: 'utf8' });
Expand Down

0 comments on commit e7aa504

Please sign in to comment.