Skip to content

Commit

Permalink
fallback to origin
Browse files Browse the repository at this point in the history
  • Loading branch information
netweng committed Jun 5, 2024
1 parent ec9ca85 commit c8b1558
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cloudtower-api-doc/swagger/SKS-App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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]);
Expand Down
8 changes: 5 additions & 3 deletions cloudtower-api-doc/swagger/utils/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = [
Expand Down Expand Up @@ -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]);
},
});
});
Expand Down

0 comments on commit c8b1558

Please sign in to comment.