* 根据参数模式生成示例值
(schema: any)
| 229 | * 根据参数模式生成示例值 |
| 230 | */ |
| 231 | private static generateExampleValue(schema: any): any { |
| 232 | if (schema.enum && schema.enum.length > 0) { |
| 233 | return schema.enum[0]; |
| 234 | } |
| 235 | |
| 236 | if (schema.default !== undefined) { |
| 237 | return schema.default; |
| 238 | } |
| 239 | |
| 240 | switch (schema.type) { |
| 241 | case 'string': |
| 242 | return schema.description ? `示例${schema.description}` : '示例文本'; |
| 243 | case 'number': |
| 244 | case 'integer': |
| 245 | return 42; |
| 246 | case 'boolean': |
| 247 | return true; |
| 248 | case 'array': |
| 249 | return []; |
| 250 | case 'object': |
| 251 | return {}; |
| 252 | default: |
| 253 | return null; |
| 254 | } |
| 255 | } |
| 256 | } |