From 1383aafebb02c4f0316619295c9452ea4df7c37f Mon Sep 17 00:00:00 2001 From: simeng-li Date: Thu, 12 Sep 2024 13:44:03 +0800 Subject: [PATCH] fix(core): avoid duplicate operationId (#6574) avoid duplication operationId --- .../core/src/routes/experience/profile-routes.openapi.json | 4 ++-- .../verification-routes/verification-code.openapi.json | 2 +- packages/core/src/routes/swagger/utils/general.ts | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/src/routes/experience/profile-routes.openapi.json b/packages/core/src/routes/experience/profile-routes.openapi.json index dcc8adf76..b3014d6a5 100644 --- a/packages/core/src/routes/experience/profile-routes.openapi.json +++ b/packages/core/src/routes/experience/profile-routes.openapi.json @@ -2,8 +2,8 @@ "paths": { "/api/experience/profile": { "post": { - "operationId": "UpdateUserProfile", - "summary": "Update user profile data", + "operationId": "AddUserProfile", + "summary": "Add user profile", "description": "Adds user profile data to the current experience interaction.
- For `Register`: The profile data provided before the identification request will be used to create a new user account.
- For `SignIn` and `Register`: The profile data provided after the user is identified will be used to update the user's profile when the interaction is submitted.
- `ForgotPassword`: Not supported.", "requestBody": { "content": { diff --git a/packages/core/src/routes/experience/verification-routes/verification-code.openapi.json b/packages/core/src/routes/experience/verification-routes/verification-code.openapi.json index b14531d40..8f396fc00 100644 --- a/packages/core/src/routes/experience/verification-routes/verification-code.openapi.json +++ b/packages/core/src/routes/experience/verification-routes/verification-code.openapi.json @@ -47,7 +47,7 @@ }, "/api/experience/verification/verification-code/verify": { "post": { - "operationId": "VerifyVerificationCode", + "operationId": "VerifyVerificationCodeVerification", "summary": "Verify verification code", "description": "Verify the provided verification code against the user's identifier. If successful, the verification record will be marked as verified.", "requestBody": { diff --git a/packages/core/src/routes/swagger/utils/general.ts b/packages/core/src/routes/swagger/utils/general.ts index c56c9dec3..4a6955d2d 100644 --- a/packages/core/src/routes/swagger/utils/general.ts +++ b/packages/core/src/routes/swagger/utils/general.ts @@ -192,6 +192,8 @@ export const validateSupplement = ( * @throws {TypeError} if the document is invalid. */ export const validateSwaggerDocument = (document: OpenAPIV3.Document) => { + const operationIdSet = new Set(); + for (const [path, operations] of Object.entries(document.paths)) { if (path.startsWith('/api/interaction')) { devConsole.warn(`Path \`${path}\` is not documented. Do something!`); @@ -236,6 +238,11 @@ export const validateSwaggerDocument = (document: OpenAPIV3.Document) => { operation.operationId, `Path \`${path}\` and operation \`${method}\` must have an operationId.` ); + assert( + !operationIdSet.has(operation.operationId), + `Operation ID \`${operation.operationId}\` is duplicated.` + ); + operationIdSet.add(operation.operationId); } for (const tag of document.tags ?? []) {