()
| 547 | }; |
| 548 | |
| 549 | const generateDocumentation = async () => { |
| 550 | const docs = DocumentationService.getInstance(); |
| 551 | const api = APIService.getInstance(); |
| 552 | |
| 553 | let baseSchema = { |
| 554 | info: { |
| 555 | title: "Axe API", |
| 556 | description: "Edit your swagger/index.ts file", |
| 557 | }, |
| 558 | servers: [ |
| 559 | { |
| 560 | url: "http://localhost:3000", |
| 561 | }, |
| 562 | ], |
| 563 | }; |
| 564 | |
| 565 | const swaggerBasePath = path.join(api.appFolder, "swagger"); |
| 566 | if ( |
| 567 | fs.existsSync(`${swaggerBasePath}.ts`) || |
| 568 | fs.existsSync(`${swaggerBasePath}.js`) |
| 569 | ) { |
| 570 | const { default: userDefinedSchema } = await import(swaggerBasePath); |
| 571 | baseSchema = userDefinedSchema; |
| 572 | } |
| 573 | |
| 574 | const schemas: any = {}; |
| 575 | const requestBodies: any = {}; |
| 576 | const firstVersion = api.versions.at(0); |
| 577 | |
| 578 | if (!firstVersion) { |
| 579 | throw new Error("The version is not found!"); |
| 580 | } |
| 581 | |
| 582 | for (const model of firstVersion.modelList.get()) { |
| 583 | const properties: any = {}; |
| 584 | for (const column of model.columns) { |
| 585 | properties[column.name] = { |
| 586 | type: toPropertyType(column.data_type), |
| 587 | format: column.data_type, |
| 588 | }; |
| 589 | } |
| 590 | schemas[model.name] = { |
| 591 | type: "object", |
| 592 | properties, |
| 593 | }; |
| 594 | |
| 595 | if (model.instance.handlers.includes(HandlerTypes.INSERT)) { |
| 596 | requestBodies[`${model.name}${pascalCase(HttpMethods.POST)}Body`] = { |
| 597 | type: "object", |
| 598 | properties: toFillableFieldProperties(model), |
| 599 | }; |
| 600 | } |
| 601 | |
| 602 | if (model.instance.handlers.includes(HandlerTypes.UPDATE)) { |
| 603 | requestBodies[`${model.name}${pascalCase(HttpMethods.PUT)}Body`] = { |
| 604 | type: "object", |
| 605 | properties: toFillableFieldProperties(model), |
| 606 | }; |
no test coverage detected