mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Add generated openapi docs to website (#1067)
* Add generated openapi docs to website * Uppercase API link in navbar * fix(docs): open api empty summary (#1069) * feat(docs): Use /docs/api path for swagger docs * Sync api version to be the same as the server * Update version Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
1adf8ff6b6
commit
a97b761eda
9 changed files with 2787 additions and 73 deletions
|
|
@ -9,6 +9,7 @@ import { AppModule } from './app.module';
|
|||
import { serverVersion } from './constants/server_version.constant';
|
||||
import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
|
||||
import { json } from 'body-parser';
|
||||
import { patchOpenAPI } from './utils/patch-open-api.util';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
|
|
@ -26,7 +27,7 @@ async function bootstrap() {
|
|||
const config = new DocumentBuilder()
|
||||
.setTitle('Immich')
|
||||
.setDescription('Immich API')
|
||||
.setVersion('1.17.0')
|
||||
.setVersion(`${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`)
|
||||
.addBearerAuth({
|
||||
type: 'http',
|
||||
scheme: 'Bearer',
|
||||
|
|
@ -55,7 +56,7 @@ async function bootstrap() {
|
|||
if (process.env.NODE_ENV == 'development') {
|
||||
// Generate API Documentation only in development mode
|
||||
const outputPath = path.resolve(process.cwd(), 'immich-openapi-specs.json');
|
||||
writeFileSync(outputPath, JSON.stringify(apiDocument, null, 2), { encoding: 'utf8' });
|
||||
writeFileSync(outputPath, JSON.stringify(patchOpenAPI(apiDocument), null, 2), { encoding: 'utf8' });
|
||||
Logger.log(
|
||||
`Running Immich Server in DEVELOPMENT environment - version ${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`,
|
||||
'ImmichServer',
|
||||
|
|
|
|||
28
server/apps/immich/src/utils/patch-open-api.util.ts
Normal file
28
server/apps/immich/src/utils/patch-open-api.util.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { OpenAPIObject } from '@nestjs/swagger';
|
||||
|
||||
export function patchOpenAPI(document: OpenAPIObject) {
|
||||
for (const path of Object.values(document.paths)) {
|
||||
const operations = {
|
||||
get: path.get,
|
||||
put: path.put,
|
||||
post: path.post,
|
||||
delete: path.delete,
|
||||
options: path.options,
|
||||
head: path.head,
|
||||
patch: path.patch,
|
||||
trace: path.trace,
|
||||
};
|
||||
|
||||
for (const operation of Object.values(operations)) {
|
||||
if (!operation) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (operation.summary === '') {
|
||||
delete operation.summary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue