Refactor
This commit is contained in:
parent
e6e7cecdb6
commit
664acb2d0e
1 changed files with 10 additions and 11 deletions
|
@ -41,24 +41,22 @@ export function genOpenapiSpec(lang = 'ja-JP') {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function genProps(props: { [key: string]: Context & { desc: any, default: any }; }) {
|
function genProps(props: { [key: string]: Context; }) {
|
||||||
const properties = {} as any;
|
const properties = {} as any;
|
||||||
|
|
||||||
const kvs = Object.entries(props);
|
for (const [k, v] of Object.entries(props)) {
|
||||||
|
properties[k] = genProp(v);
|
||||||
for (const kv of kvs) {
|
|
||||||
properties[kv[0]] = genProp(kv[1], kv[1].desc, kv[1].default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genProp(param: Context, desc?: string, _default?: any): any {
|
function genProp(param: Context): any {
|
||||||
const required = param.name === 'Object' ? (param as any).props ? Object.entries((param as any).props).filter(([k, v]: any) => !v.isOptional).map(([k, v]) => k) : [] : [];
|
const required = param.name === 'Object' ? (param as any).props ? Object.entries((param as any).props).filter(([k, v]: any) => !v.isOptional).map(([k, v]) => k) : [] : [];
|
||||||
return {
|
return {
|
||||||
description: desc,
|
description: (param.data || {}).desc,
|
||||||
default: _default,
|
default: (param.data || {}).default,
|
||||||
...(_default ? { default: _default } : {}),
|
...((param.data || {}).default ? { default: (param.data || {}).default } : {}),
|
||||||
type: param.name === 'ID' ? 'string' : param.name.toLowerCase(),
|
type: param.name === 'ID' ? 'string' : param.name.toLowerCase(),
|
||||||
...(param.name === 'ID' ? { example: 'xxxxxxxxxxxxxxxxxxxxxxxx', format: 'id' } : {}),
|
...(param.name === 'ID' ? { example: 'xxxxxxxxxxxxxxxxxxxxxxxx', format: 'id' } : {}),
|
||||||
nullable: param.isNullable,
|
nullable: param.isNullable,
|
||||||
|
@ -97,8 +95,9 @@ export function genOpenapiSpec(lang = 'ja-JP') {
|
||||||
|
|
||||||
if (endpoint.meta.params) {
|
if (endpoint.meta.params) {
|
||||||
for (const [k, v] of Object.entries(endpoint.meta.params)) {
|
for (const [k, v] of Object.entries(endpoint.meta.params)) {
|
||||||
if (v.desc) (v.validator as any).desc = v.desc[lang];
|
if (v.validator.data == null) v.validator.data = {};
|
||||||
if (v.default) (v.validator as any).default = v.default;
|
if (v.desc) v.validator.data.desc = v.desc[lang];
|
||||||
|
if (v.default) v.validator.data.default = v.default;
|
||||||
porops[k] = v.validator;
|
porops[k] = v.validator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue