diff --git a/cloudtower-api-doc/swagger/SKS-App.tsx b/cloudtower-api-doc/swagger/SKS-App.tsx index 9e12249..52f2294 100644 --- a/cloudtower-api-doc/swagger/SKS-App.tsx +++ b/cloudtower-api-doc/swagger/SKS-App.tsx @@ -8,7 +8,7 @@ import { ISpec, sksSpecMap as specMap, overwriteSchemaTitle, - // wrapSpecWithI18n, + wrapSpecWithI18n, } from "./utils"; import Redocly from "./redoc/Redoc"; import { LOCAL_STORAGE_SERVERS_KEY } from "./redoc/Console/ServerDropdown"; @@ -78,7 +78,7 @@ const App: React.FC = () => { const swaggerSpec: ISpec = _.cloneDeep(data.default); setRawSpec(swaggerSpec); i18next.changeLanguage(i18n.currentLocale); - setSpec(swaggerSpec); + setSpec(wrapSpecWithI18n(swaggerSpec, i18n.currentLocale, version)); }) }, [version, i18n.currentLocale]); diff --git a/cloudtower-api-doc/swagger/utils/wrap.ts b/cloudtower-api-doc/swagger/utils/wrap.ts index 206f89d..5d31ea9 100644 --- a/cloudtower-api-doc/swagger/utils/wrap.ts +++ b/cloudtower-api-doc/swagger/utils/wrap.ts @@ -40,8 +40,9 @@ export const wrapSpecWithI18n = ( const method = Object.keys(paths[p])[0] const operationObj = paths[p][method] as OpenAPIV3.OperationObject; const { description, summary } = apiDoc; - operationObj .description = description; - operationObj .summary = summary; + const { description: originDes, summary: originSum } = operationObj; + operationObj.description = originDes || description; + operationObj.summary = originSum || summary; const example = swaggerSpecExample [p] || {}; if(example) { operationObj["x-codeSamples"] = [ @@ -88,7 +89,8 @@ export const wrapSpecWithI18n = ( schema: components.schemas[s], prefix: ["components", "schemas", s], describeFn: ({ prefix, path }) => { - _.set(cloneSpec, [...prefix, "description"], schema[path]); + const originDes = _.get(cloneSpec, [...prefix, 'description']); + _.set(cloneSpec, [...prefix, "description"], originDes || schema[path]); }, }); });