raiton 6.8.8-beta.24 → 6.10.0-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +46 -1
- package/benchmarks/README.md +16 -0
- package/benchmarks/latest.json +172 -0
- package/benchmarks/latest.md +66 -0
- package/build/bin/index.mjs +33575 -21723
- package/build/types/bin/bootstrapper.d.ts +2 -0
- package/build/types/bin/cli-output.d.ts +46 -0
- package/build/types/bin/cli-tools.d.ts +13 -0
- package/build/types/bin/cli.d.ts +3 -0
- package/build/types/bin/commands.registry.d.ts +4 -0
- package/build/types/bin/constants.d.ts +3 -0
- package/build/types/bin/file-utils.d.ts +21 -0
- package/build/types/bin/index.d.ts +2 -0
- package/build/types/bin/name-utils.d.ts +4 -0
- package/build/types/bin/project-utils.d.ts +12 -0
- package/build/types/commands/artifact.command.d.ts +7 -0
- package/build/types/commands/build.command.d.ts +8 -0
- package/build/types/commands/client.command.d.ts +7 -0
- package/build/types/commands/contract.command.d.ts +8 -0
- package/build/types/commands/develop.command.d.ts +9 -0
- package/build/types/commands/docs.command.d.ts +8 -0
- package/build/types/commands/doctor.command.d.ts +9 -0
- package/build/types/commands/generate.command.d.ts +7 -0
- package/build/types/commands/inspect.command.d.ts +7 -0
- package/build/types/commands/mcp.command.d.ts +11 -0
- package/build/types/commands/new.command.d.ts +7 -0
- package/build/types/commands/openapi.command.d.ts +7 -0
- package/build/types/commands/routes.command.d.ts +7 -0
- package/build/types/commands/start.command.d.ts +9 -0
- package/build/types/commands/why.command.d.ts +7 -0
- package/build/types/contracts/decorators.d.ts +41 -0
- package/build/types/contracts/errors.d.ts +42 -0
- package/build/types/contracts/index.d.ts +4 -0
- package/build/types/contracts/schema.d.ts +70 -0
- package/build/types/contracts/typebox.d.ts +81 -0
- package/build/types/core/application.d.ts +37 -0
- package/build/types/core/artifacts/artifact.d.ts +3 -0
- package/build/types/core/artifacts/index.d.ts +1 -0
- package/build/types/core/artifacts/runner.d.ts +1 -0
- package/build/types/core/builder.d.ts +42 -0
- package/build/types/core/bytes.util.d.ts +3 -0
- package/build/types/core/command.d.ts +13 -0
- package/build/types/core/commands.d.ts +10 -0
- package/build/types/core/config/config.d.ts +27 -0
- package/build/types/core/config/define.d.ts +8 -0
- package/build/types/core/config/index.d.ts +3 -0
- package/build/types/core/config/schema.d.ts +24 -0
- package/build/types/core/context.d.ts +11 -0
- package/build/types/core/controller/builder.d.ts +26 -0
- package/build/types/core/controller/compiler.d.ts +2 -0
- package/build/types/core/controller/index.d.ts +4 -0
- package/build/types/core/controller/metadata.d.ts +3 -0
- package/build/types/core/controller/tracker.d.ts +9 -0
- package/build/types/core/directories.d.ts +10 -0
- package/build/types/core/guards.d.ts +11 -0
- package/build/types/core/helpers/index.d.ts +1 -0
- package/build/types/core/helpers/raiton.d.ts +1 -0
- package/build/types/core/hooks.d.ts +14 -0
- package/build/types/core/index.d.ts +17 -0
- package/build/types/core/injection/index.d.ts +1 -0
- package/build/types/core/injection/injection.d.ts +37 -0
- package/build/types/core/mcp/builder.d.ts +2 -0
- package/build/types/core/mcp/index.d.ts +3 -0
- package/build/types/core/mcp/metadata.d.ts +9 -0
- package/build/types/core/mcp/tracker.d.ts +9 -0
- package/build/types/core/middleware/compose.d.ts +8 -0
- package/build/types/core/middleware/index.d.ts +2 -0
- package/build/types/core/middleware/pipeline.d.ts +12 -0
- package/build/types/core/plugins/index.d.ts +2 -0
- package/build/types/core/plugins/plugin.d.ts +2 -0
- package/build/types/core/plugins/scope.d.ts +15 -0
- package/build/types/core/process.util.d.ts +1 -0
- package/build/types/core/raiton.d.ts +15 -0
- package/build/types/core/router/handler.d.ts +2 -0
- package/build/types/core/router/handler.utils.d.ts +37 -0
- package/build/types/core/router/index.d.ts +4 -0
- package/build/types/core/router/matcher.d.ts +50 -0
- package/build/types/core/router/route.d.ts +52 -0
- package/build/types/core/router/router.d.ts +23 -0
- package/build/types/core/scheduler/builder.d.ts +2 -0
- package/build/types/core/scheduler/cron.d.ts +32 -0
- package/build/types/core/scheduler/duration.d.ts +7 -0
- package/build/types/core/scheduler/index.d.ts +6 -0
- package/build/types/core/scheduler/manager.d.ts +47 -0
- package/build/types/core/scheduler/metadata.d.ts +8 -0
- package/build/types/core/scheduler/queue/backend.d.ts +42 -0
- package/build/types/core/scheduler/queue/index.d.ts +3 -0
- package/build/types/core/scheduler/queue/rabbitmq.backend.d.ts +37 -0
- package/build/types/core/scheduler/queue/redis.backend.d.ts +38 -0
- package/build/types/core/server.d.ts +9 -0
- package/build/types/core/socket/builder.d.ts +1 -0
- package/build/types/core/socket/index.d.ts +2 -0
- package/build/types/core/socket/metadata.d.ts +14 -0
- package/build/types/core/thread.d.ts +21 -0
- package/build/types/framework/artifacts.d.ts +20 -0
- package/build/types/framework/cache/cache.d.ts +84 -0
- package/build/types/framework/cache/cache.decorator.d.ts +21 -0
- package/build/types/framework/cache/etag.d.ts +62 -0
- package/build/types/framework/cache/index.d.ts +4 -0
- package/build/types/framework/cache/types.d.ts +89 -0
- package/build/types/framework/constants/decorators.constant.d.ts +28 -0
- package/build/types/framework/constants/index.d.ts +2 -0
- package/build/types/framework/constants/microservices.constant.d.ts +3 -0
- package/build/types/framework/controllers.d.ts +2 -0
- package/build/types/framework/data-transfer-object.d.ts +5 -0
- package/build/types/framework/decorators/access-guard.decorator.d.ts +1 -0
- package/build/types/framework/decorators/api-response.decorator.d.ts +66 -0
- package/build/types/framework/decorators/api.decorator.d.ts +160 -0
- package/build/types/framework/decorators/controllable.decorator.d.ts +3 -0
- package/build/types/framework/decorators/csrf-guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/csrf-token.decorator.d.ts +1 -0
- package/build/types/framework/decorators/guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/health-check.decorator.d.ts +17 -0
- package/build/types/framework/decorators/index.d.ts +15 -0
- package/build/types/framework/decorators/injection.decorator.d.ts +5 -0
- package/build/types/framework/decorators/mcp.decorator.d.ts +68 -0
- package/build/types/framework/decorators/middleware.decorator.d.ts +3 -0
- package/build/types/framework/decorators/parametrable.decorator.d.ts +9 -0
- package/build/types/framework/decorators/routable.decorator.d.ts +12 -0
- package/build/types/framework/decorators/route-interaction.decorator.d.ts +81 -0
- package/build/types/framework/decorators/scheduler.decorator.d.ts +54 -0
- package/build/types/framework/decorators/socket.decorator.d.ts +5 -0
- package/build/types/framework/encryption.d.ts +25 -0
- package/build/types/framework/enums/csrf.enum.d.ts +4 -0
- package/build/types/framework/enums/encrypted.enum.d.ts +20 -0
- package/build/types/framework/enums/event.message.enum.d.ts +4 -0
- package/build/types/framework/enums/http-method.enum.d.ts +10 -0
- package/build/types/framework/enums/http-parameters.enum.d.ts +11 -0
- package/build/types/framework/enums/http-status.enum.d.ts +64 -0
- package/build/types/framework/enums/index.d.ts +9 -0
- package/build/types/framework/enums/runtime.enum.d.ts +5 -0
- package/build/types/framework/enums/scheduler.enum.d.ts +21 -0
- package/build/types/framework/enums/timestamp.enum.d.ts +6 -0
- package/build/types/framework/env.d.ts +3 -0
- package/build/types/framework/errors/catalog.d.ts +42 -0
- package/build/types/framework/exceptions/http-exception.d.ts +18 -0
- package/build/types/framework/exceptions/index.d.ts +2 -0
- package/build/types/framework/exceptions/throwable.d.ts +76 -0
- package/build/types/framework/health-check.d.ts +42 -0
- package/build/types/framework/index.d.ts +20 -0
- package/build/types/framework/mcp/audit.d.ts +12 -0
- package/build/types/framework/mcp/conformance.d.ts +31 -0
- package/build/types/framework/mcp/handler.d.ts +11 -0
- package/build/types/framework/mcp/index.d.ts +5 -0
- package/build/types/framework/mcp/protocol.d.ts +17 -0
- package/build/types/framework/mcp/rate-limit.d.ts +10 -0
- package/build/types/framework/mcp/stdio.d.ts +40 -0
- package/build/types/framework/mcp/streamable-http.d.ts +17 -0
- package/build/types/framework/observability/index.d.ts +6 -0
- package/build/types/framework/observability/metrics.d.ts +23 -0
- package/build/types/framework/observability/plugin.d.ts +20 -0
- package/build/types/framework/observability/readiness.d.ts +9 -0
- package/build/types/framework/observability/request.d.ts +7 -0
- package/build/types/framework/observability/shutdown.d.ts +21 -0
- package/build/types/framework/observability/trace.d.ts +96 -0
- package/build/types/framework/parameter-bag.d.ts +14 -0
- package/build/types/framework/plugins/body-parser.plugin.d.ts +3 -0
- package/build/types/framework/plugins/dev.plugin.d.ts +12 -0
- package/build/types/framework/plugins/index.d.ts +5 -0
- package/build/types/framework/plugins/mcp.plugin.d.ts +15 -0
- package/build/types/framework/plugins/openapi.plugin.d.ts +58 -0
- package/build/types/framework/plugins/security/body-limit.d.ts +1 -0
- package/build/types/framework/plugins/security/cors.d.ts +10 -0
- package/build/types/framework/plugins/security/csrf.d.ts +2 -0
- package/build/types/framework/plugins/security/headers.d.ts +1 -0
- package/build/types/framework/plugins/security/index.d.ts +13 -0
- package/build/types/framework/plugins/security/method-guard.d.ts +1 -0
- package/build/types/framework/plugins/security/rate-limit.d.ts +5 -0
- package/build/types/framework/repositories.d.ts +5 -0
- package/build/types/framework/responses/error.d.ts +13 -0
- package/build/types/framework/responses/helpers.d.ts +7 -0
- package/build/types/framework/responses/http-throwable.d.ts +14 -0
- package/build/types/framework/responses/http.d.ts +13 -0
- package/build/types/framework/responses/index.d.ts +4 -0
- package/build/types/framework/runtime/bun/server.d.ts +2 -0
- package/build/types/framework/runtime/deno/server.d.ts +2 -0
- package/build/types/framework/runtime/index.d.ts +17 -0
- package/build/types/framework/runtime/node/reply.d.ts +12 -0
- package/build/types/framework/runtime/node/request.d.ts +33 -0
- package/build/types/framework/runtime/node/server.d.ts +2 -0
- package/build/types/framework/runtime/web/server.d.ts +1 -0
- package/build/types/framework/services.d.ts +5 -0
- package/build/types/framework/utilities/alias-path.util.d.ts +1 -0
- package/build/types/framework/utilities/artifact.util.d.ts +7 -0
- package/build/types/framework/utilities/callable.util.d.ts +1 -0
- package/build/types/framework/utilities/cookie.util.d.ts +1 -0
- package/build/types/framework/utilities/csrf.util.d.ts +26 -0
- package/build/types/framework/utilities/https.util.d.ts +49 -0
- package/build/types/framework/utilities/index.d.ts +12 -0
- package/build/types/framework/utilities/ip.util.d.ts +15 -0
- package/build/types/framework/utilities/json.util.d.ts +10 -0
- package/build/types/framework/utilities/openapi.utils.d.ts +7 -0
- package/build/types/framework/utilities/openapi.utils.impl.d.ts +18 -0
- package/build/types/framework/utilities/path.util.d.ts +3 -0
- package/build/types/framework/utilities/route-suggestion.util.d.ts +10 -0
- package/build/types/framework/utilities/url.util.d.ts +1 -0
- package/build/types/framework/utilities/utilities.util.d.ts +3 -0
- package/build/types/framework/utilities/validation.util.d.ts +8 -0
- package/build/types/framework/view-model.d.ts +4 -0
- package/build/types/generators/artifact.templates.d.ts +7 -0
- package/build/types/generators/index.d.ts +2 -0
- package/build/types/generators/project.templates.d.ts +21 -0
- package/build/types/manifest/client.d.ts +12 -0
- package/build/types/manifest/contract.d.ts +25 -0
- package/build/types/manifest/index.d.ts +5 -0
- package/build/types/manifest/introspect.d.ts +18 -0
- package/build/types/manifest/manifest.d.ts +18 -0
- package/build/types/manifest/schema.d.ts +177 -0
- package/build/types/requirements.d.ts +1 -0
- package/build/types/types/access-guards.d.ts +4 -0
- package/build/types/types/application.d.ts +32 -0
- package/build/types/types/artifact.d.ts +8 -0
- package/build/types/types/builder.d.ts +37 -0
- package/build/types/types/config.d.ts +62 -0
- package/build/types/types/controller.d.ts +27 -0
- package/build/types/types/contruct.d.ts +1 -0
- package/build/types/types/core.d.ts +11 -0
- package/build/types/types/csrf.d.ts +33 -0
- package/build/types/types/directory.d.ts +6 -0
- package/build/types/types/encryption.d.ts +14 -0
- package/build/types/types/generic.d.ts +2 -0
- package/build/types/types/guard.d.ts +9 -0
- package/build/types/types/http-responses.d.ts +7 -0
- package/build/types/types/index.d.ts +27 -0
- package/build/types/types/injection.d.ts +11 -0
- package/build/types/types/lifecycle.d.ts +9 -0
- package/build/types/types/mcp.d.ts +148 -0
- package/build/types/types/middleware.d.ts +12 -0
- package/build/types/types/parseable.d.ts +3 -0
- package/build/types/types/plugin.d.ts +6 -0
- package/build/types/types/raiton.d.ts +13 -0
- package/build/types/types/responses.d.ts +20 -0
- package/build/types/types/router.d.ts +13 -0
- package/build/types/types/runtime.d.ts +48 -0
- package/build/types/types/scheduler.d.ts +140 -0
- package/build/types/types/scheme.d.ts +125 -0
- package/build/types/types/server.d.ts +10 -0
- package/build/types/types/socket.d.ts +11 -0
- package/build/types/types/thread.d.ts +25 -0
- package/build/types/types/utilities.d.ts +4 -0
- package/build/types/types/values.d.ts +2 -0
- package/docs/AGENTS.md +55 -0
- package/docs/CLAUDE.md +55 -0
- package/docs/README.md +5 -0
- package/docs/contributors/cli/README.md +17 -3
- package/docs/contributors/cli/commands.md +28 -17
- package/docs/contributors/framework/plugins/openapi.md +12 -3
- package/docs/generated/cli/commands.md +26 -0
- package/docs/generated/config-schema.json +150 -0
- package/docs/generated/manifest-schema.json +236 -0
- package/docs/generated/manifest.json +101 -0
- package/docs/llms-full.txt +1271 -0
- package/docs/llms.txt +46 -0
- package/docs/user-guide/README.md +18 -12
- package/docs/user-guide/cli.md +21 -0
- package/docs/user-guide/config.md +14 -0
- package/docs/user-guide/contracts.md +67 -0
- package/docs/user-guide/en/README.md +83 -0
- package/docs/user-guide/getting-started.md +13 -1
- package/docs/user-guide/mcp.md +45 -2
- package/docs/user-guide/observability.md +74 -0
- package/docs/user-guide/openapi/plugin.md +10 -0
- package/docs/user-guide/recipes/README.md +32 -0
- package/docs/user-guide/recipes/contracts.md +52 -0
- package/docs/user-guide/recipes/doctor.md +16 -0
- package/docs/user-guide/recipes/generate.md +28 -0
- package/docs/user-guide/recipes/manifest.md +17 -0
- package/docs/user-guide/recipes/mcp-stdio.md +35 -0
- package/docs/user-guide/recipes/new-project.md +34 -0
- package/docs/user-guide/recipes/observability.md +17 -0
- package/package.json +40 -7
- package/scripts/bench.ts +586 -0
- package/scripts/postinstall.mjs +15 -0
- package/source/bin/cli-output.ts +139 -0
- package/source/bin/commands.registry.ts +23 -3
- package/source/bin/file-utils.ts +95 -0
- package/source/bin/name-utils.ts +26 -0
- package/source/bin/project-utils.ts +78 -0
- package/source/commands/artifact.command.ts +30 -15
- package/source/commands/client.command.ts +64 -0
- package/source/commands/contract.command.ts +104 -0
- package/source/commands/docs.command.ts +263 -0
- package/source/commands/doctor.command.ts +226 -0
- package/source/commands/generate.command.ts +58 -0
- package/source/commands/inspect.command.ts +108 -0
- package/source/commands/mcp.command.ts +258 -0
- package/source/commands/new.command.ts +135 -0
- package/source/commands/openapi.command.ts +95 -0
- package/source/commands/routes.command.ts +39 -0
- package/source/commands/why.command.ts +61 -0
- package/source/contracts/decorators.ts +151 -0
- package/source/contracts/errors.ts +76 -0
- package/source/contracts/index.ts +4 -0
- package/source/contracts/schema.ts +377 -0
- package/source/contracts/typebox.ts +193 -0
- package/source/core/application.ts +215 -73
- package/source/core/builder.ts +6 -2
- package/source/core/config/config.ts +144 -26
- package/source/core/config/define.ts +35 -8
- package/source/core/config/index.ts +2 -1
- package/source/core/config/schema.ts +263 -0
- package/source/core/controller/builder.ts +38 -13
- package/source/core/controller/compiler.ts +14 -7
- package/source/core/controller/metadata.ts +1 -1
- package/source/core/hooks.ts +13 -1
- package/source/core/injection/injection.ts +47 -9
- package/source/core/mcp/builder.ts +13 -2
- package/source/core/mcp/metadata.ts +2 -1
- package/source/core/middleware/compose.ts +48 -0
- package/source/core/middleware/pipeline.ts +69 -46
- package/source/core/raiton.ts +8 -0
- package/source/core/router/handler.ts +91 -31
- package/source/core/router/handler.utils.ts +107 -51
- package/source/core/router/matcher.ts +195 -24
- package/source/core/router/route.ts +100 -31
- package/source/core/router/router.ts +27 -2
- package/source/core/scheduler/metadata.ts +1 -1
- package/source/core/socket/metadata.ts +1 -1
- package/source/core/thread.ts +37 -2
- package/source/framework/artifacts.ts +92 -19
- package/source/framework/cache/cache.ts +48 -3
- package/source/framework/constants/decorators.constant.ts +5 -0
- package/source/framework/data-transfer-object.ts +4 -3
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +3 -2
- package/source/framework/decorators/csrf-token.decorator.ts +1 -1
- package/source/framework/decorators/guard.decorator.ts +3 -2
- package/source/framework/decorators/health-check.decorator.ts +1 -1
- package/source/framework/decorators/mcp.decorator.ts +38 -7
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -1
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +2 -2
- package/source/framework/decorators/scheduler.decorator.ts +3 -3
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +46 -7
- package/source/framework/errors/catalog.ts +159 -0
- package/source/framework/exceptions/http-exception.ts +1 -1
- package/source/framework/health-check.ts +18 -0
- package/source/framework/index.ts +2 -0
- package/source/framework/mcp/audit.ts +57 -0
- package/source/framework/mcp/conformance.ts +195 -0
- package/source/framework/mcp/handler.ts +131 -9
- package/source/framework/mcp/index.ts +6 -1
- package/source/framework/mcp/protocol.ts +6 -0
- package/source/framework/mcp/rate-limit.ts +33 -0
- package/source/framework/mcp/stdio.ts +150 -0
- package/source/framework/mcp/streamable-http.ts +36 -5
- package/source/framework/observability/index.ts +6 -0
- package/source/framework/observability/metrics.ts +162 -0
- package/source/framework/observability/plugin.ts +151 -0
- package/source/framework/observability/readiness.ts +22 -0
- package/source/framework/observability/request.ts +31 -0
- package/source/framework/observability/shutdown.ts +68 -0
- package/source/framework/observability/trace.ts +241 -0
- package/source/framework/plugins/body-parser.plugin.ts +88 -85
- package/source/framework/plugins/dev.plugin.ts +227 -0
- package/source/framework/plugins/index.ts +2 -1
- package/source/framework/plugins/mcp.plugin.ts +14 -3
- package/source/framework/plugins/openapi.plugin.ts +56 -13
- package/source/framework/responses/helpers.ts +4 -4
- package/source/framework/responses/http-throwable.ts +1 -1
- package/source/framework/runtime/bun/server.ts +2 -1
- package/source/framework/runtime/deno/server.ts +2 -1
- package/source/framework/runtime/index.ts +45 -13
- package/source/framework/runtime/node/request.ts +59 -13
- package/source/framework/utilities/index.ts +3 -1
- package/source/framework/utilities/openapi.utils.impl.ts +705 -0
- package/source/framework/utilities/openapi.utils.ts +6 -636
- package/source/framework/utilities/route-suggestion.util.ts +59 -0
- package/source/framework/utilities/validation.util.ts +20 -0
- package/source/generators/artifact.templates.ts +230 -0
- package/source/generators/index.ts +2 -0
- package/source/generators/project.templates.ts +392 -0
- package/source/manifest/client.ts +299 -0
- package/source/manifest/contract.ts +138 -0
- package/source/manifest/index.ts +5 -0
- package/source/manifest/introspect.ts +52 -0
- package/source/manifest/manifest.ts +341 -0
- package/source/manifest/schema.ts +149 -0
- package/source/types/builder.ts +5 -0
- package/source/types/config.ts +64 -2
- package/source/types/mcp.ts +63 -1
- package/tsconfig.build.json +13 -0
- package/source/commands/grafts.command.ts +0 -27
- package/tests/artifact-resolution.test.ts +0 -60
|
@@ -1,641 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {METADATA_KEYS, Parametrable} from "../index.ts";
|
|
3
|
-
import {PluginScope} from "../../core/index.ts";
|
|
4
|
-
import {RaitonConfig} from "../../core/config/index.ts";
|
|
5
|
-
import {getSocketRegistry} from "../../core/socket/index.ts";
|
|
6
|
-
import {getMcpServerRegistry} from "../../core/mcp/index.ts";
|
|
7
|
-
import {RaitonThread} from "../../core/thread.ts";
|
|
1
|
+
import type {PluginScope} from "../../core/plugins/scope.ts";
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
|
-
*
|
|
4
|
+
* Génération OpenAPI paresseuse : l'implémentation (et ses dépendances :
|
|
5
|
+
* contrats, thread, configuration) n'est chargée qu'au premier appel. Le
|
|
6
|
+
* démarrage du framework ne paie donc pas ce module.
|
|
11
7
|
*/
|
|
12
8
|
export async function generateOpenApiSpec(scope: PluginScope, opts: any): Promise<any> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const appHttps = RaitonThread.current?.application?.https;
|
|
16
|
-
|
|
17
|
-
let protocole: string;
|
|
18
|
-
let hostname: string;
|
|
19
|
-
let port: number | undefined;
|
|
20
|
-
let pathname: string;
|
|
21
|
-
let prefix: string;
|
|
22
|
-
|
|
23
|
-
if (appConfig) {
|
|
24
|
-
protocole = appHttps?.enabled ? 'https' : (appConfig.protocole || 'http');
|
|
25
|
-
hostname = appConfig.hostname || 'localhost';
|
|
26
|
-
port = appConfig.port;
|
|
27
|
-
pathname = appConfig.pathname || '/';
|
|
28
|
-
prefix = appConfig.prefix || '';
|
|
29
|
-
} else {
|
|
30
|
-
// Fallback to RaitonConfig
|
|
31
|
-
await RaitonConfig.sync(process.cwd());
|
|
32
|
-
const config: Map<keyof any, any> = RaitonConfig.current as any;
|
|
33
|
-
protocole = (config.get('protocole') as string) ?? 'http';
|
|
34
|
-
hostname = (config.get('hostname') as string) ?? 'localhost';
|
|
35
|
-
port = config.get('port') as number;
|
|
36
|
-
pathname = (config.get('pathname') as string) ?? '/';
|
|
37
|
-
prefix = (config.get('prefix') as string) ?? '';
|
|
38
|
-
}
|
|
39
|
-
const basePath = pathname.endsWith('/') ? pathname : pathname + '/';
|
|
40
|
-
|
|
41
|
-
let baseUrl = `${protocole}://${hostname}`;
|
|
42
|
-
if (port !== undefined && port !== null) {
|
|
43
|
-
baseUrl += `:${port}`;
|
|
44
|
-
}
|
|
45
|
-
baseUrl += basePath;
|
|
46
|
-
if (prefix) {
|
|
47
|
-
baseUrl += prefix.startsWith('/') ? prefix.slice(1) : prefix;
|
|
48
|
-
if (!baseUrl.endsWith('/')) baseUrl += '/';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Initialize OpenAPI document
|
|
52
|
-
const spec: any = {
|
|
53
|
-
openapi: '3.0.0',
|
|
54
|
-
info: {
|
|
55
|
-
title: opts.title,
|
|
56
|
-
version: opts.version,
|
|
57
|
-
description: opts.description,
|
|
58
|
-
...(opts.termsOfService ? {termsOfService: opts.termsOfService} : {}),
|
|
59
|
-
...(opts.contact ? {contact: opts.contact} : {}),
|
|
60
|
-
...(opts.license ? {license: opts.license} : {})
|
|
61
|
-
},
|
|
62
|
-
servers: [
|
|
63
|
-
{
|
|
64
|
-
url: baseUrl
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
paths: {}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const routes = scope.router.getRoutes();
|
|
71
|
-
|
|
72
|
-
for (const route of routes) {
|
|
73
|
-
const handler = route.handler as any;
|
|
74
|
-
const meta = handler._raitonMeta as {
|
|
75
|
-
routeMeta: { method: string; path: string; propertyKey: string };
|
|
76
|
-
controllerMeta: any;
|
|
77
|
-
controllerClass: any
|
|
78
|
-
} | undefined;
|
|
79
|
-
if (!meta) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const {routeMeta, controllerMeta, controllerClass} = meta;
|
|
84
|
-
const method = routeMeta.method.toLowerCase() as keyof any;
|
|
85
|
-
|
|
86
|
-
let path = route.path;
|
|
87
|
-
if (route.version) {
|
|
88
|
-
path = `/${route.version}${path}`;
|
|
89
|
-
}
|
|
90
|
-
if (!path.startsWith('/')) {
|
|
91
|
-
path = '/' + path;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!spec.paths[path]) {
|
|
95
|
-
spec.paths[path] = {};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const operation: any = {
|
|
99
|
-
parameters: [],
|
|
100
|
-
responses: {}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const controllerPrototype = controllerClass?.prototype ?? controllerClass;
|
|
104
|
-
|
|
105
|
-
const operationMetadata = Reflect.getMetadata(METADATA_KEYS.API_OPERATION, controllerPrototype, routeMeta.propertyKey);
|
|
106
|
-
if (operationMetadata) {
|
|
107
|
-
Object.assign(operation, operationMetadata);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const methodTags = Reflect.getMetadata(METADATA_KEYS.API_TAGS, controllerPrototype, routeMeta.propertyKey);
|
|
111
|
-
if (methodTags) {
|
|
112
|
-
operation.tags = methodTags;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const methodSecurity = Reflect.getMetadata(METADATA_KEYS.API_SECURITY, controllerPrototype, routeMeta.propertyKey);
|
|
116
|
-
if (methodSecurity) {
|
|
117
|
-
operation.security = methodSecurity;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const classTags = Reflect.getMetadata(METADATA_KEYS.API_TAGS, controllerClass);
|
|
121
|
-
if (classTags) {
|
|
122
|
-
operation.tags = [...(operation.tags || []), ...classTags];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const classSecurity = Reflect.getMetadata(METADATA_KEYS.API_SECURITY, controllerClass);
|
|
126
|
-
if (classSecurity) {
|
|
127
|
-
operation.security = [...(operation.security || []), ...classSecurity];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const params: ParamMetaInterface[] = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, controllerPrototype)?.[routeMeta.propertyKey] || [];
|
|
131
|
-
|
|
132
|
-
let bodyParam: ParamMetaInterface | undefined;
|
|
133
|
-
const otherParams = params.filter(p => {
|
|
134
|
-
if (p.type === Parametrable.BODY) {
|
|
135
|
-
bodyParam = p;
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const apiParameters = Reflect.getMetadata(METADATA_KEYS.API_PARAMETERS, controllerPrototype, routeMeta.propertyKey)?.[routeMeta.propertyKey] || [];
|
|
142
|
-
for (const param of apiParameters) {
|
|
143
|
-
let inLocation: string;
|
|
144
|
-
switch (param.in) {
|
|
145
|
-
case 'path':
|
|
146
|
-
inLocation = 'path';
|
|
147
|
-
break;
|
|
148
|
-
case 'query':
|
|
149
|
-
inLocation = 'query';
|
|
150
|
-
break;
|
|
151
|
-
case 'header':
|
|
152
|
-
inLocation = 'header';
|
|
153
|
-
break;
|
|
154
|
-
case 'cookie':
|
|
155
|
-
inLocation = 'cookie';
|
|
156
|
-
break;
|
|
157
|
-
default:
|
|
158
|
-
continue; // Skip unknown locations
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const paramObj: any = {
|
|
162
|
-
name: param.name,
|
|
163
|
-
in: inLocation,
|
|
164
|
-
description: param.description,
|
|
165
|
-
required: param.required ?? true,
|
|
166
|
-
schema: {
|
|
167
|
-
type: 'string'
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
if (param.type) {
|
|
172
|
-
paramObj.schema = getSchemaFromType(param.type);
|
|
173
|
-
if (param.default !== undefined) {
|
|
174
|
-
paramObj.schema.default = param.default;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
operation.parameters.push(paramObj);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Process standard Parametrable decorators (@Param, @Query, etc.)
|
|
182
|
-
for (const p of otherParams) {
|
|
183
|
-
let inLocation: string | undefined;
|
|
184
|
-
switch (p.type) {
|
|
185
|
-
case Parametrable.PARAM:
|
|
186
|
-
inLocation = 'path';
|
|
187
|
-
break;
|
|
188
|
-
case Parametrable.QUERY:
|
|
189
|
-
inLocation = 'query';
|
|
190
|
-
break;
|
|
191
|
-
case Parametrable.HEADER:
|
|
192
|
-
inLocation = 'header';
|
|
193
|
-
break;
|
|
194
|
-
// Note: COOKIE is not supported as there is no Parametrable.COOKIE in the framework
|
|
195
|
-
default:
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
if (!inLocation) continue;
|
|
199
|
-
|
|
200
|
-
const paramObj: any = {
|
|
201
|
-
name: p.key ?? '',
|
|
202
|
-
in: inLocation,
|
|
203
|
-
required: true, // We don't have info about required; assume true
|
|
204
|
-
schema: {
|
|
205
|
-
type: 'string' // Default to string; we could try to infer from p.metatype
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
// Try to improve schema based on metatype if available
|
|
209
|
-
if (p.metatype) {
|
|
210
|
-
// If metatype is a constructor like String, Number, Boolean, we can map to JSON types
|
|
211
|
-
const typeName = p.metatype.name;
|
|
212
|
-
switch (typeName) {
|
|
213
|
-
case 'String':
|
|
214
|
-
paramObj.schema.type = 'string';
|
|
215
|
-
break;
|
|
216
|
-
case 'Number':
|
|
217
|
-
paramObj.schema.type = 'number';
|
|
218
|
-
break;
|
|
219
|
-
case 'Boolean':
|
|
220
|
-
paramObj.schema.type = 'boolean';
|
|
221
|
-
break;
|
|
222
|
-
case 'Object':
|
|
223
|
-
paramObj.schema.type = 'object';
|
|
224
|
-
break;
|
|
225
|
-
case 'Array':
|
|
226
|
-
paramObj.schema.type = 'array';
|
|
227
|
-
// We don't know item type; leave as generic
|
|
228
|
-
break;
|
|
229
|
-
default:
|
|
230
|
-
// For custom classes (DTOs), we could generate a schema but skip for simplicity
|
|
231
|
-
// Keep as string for now
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
operation.parameters.push(paramObj);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Check for explicit API request body decorator
|
|
239
|
-
const apiRequestBody = Reflect.getMetadata(METADATA_KEYS.API_REQUEST_BODY, controllerPrototype, routeMeta.propertyKey);
|
|
240
|
-
if (apiRequestBody) {
|
|
241
|
-
// Use explicit API request body definition
|
|
242
|
-
const bodyRequired = apiRequestBody.required ?? true;
|
|
243
|
-
let bodySchema = null;
|
|
244
|
-
if (apiRequestBody.type) {
|
|
245
|
-
bodySchema = getSchemaFromType(apiRequestBody.type);
|
|
246
|
-
}
|
|
247
|
-
if (bodySchema !== null) {
|
|
248
|
-
operation.requestBody = {
|
|
249
|
-
required: bodyRequired,
|
|
250
|
-
content: {
|
|
251
|
-
'application/json': {
|
|
252
|
-
schema: bodySchema
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
} else if (bodyParam) {
|
|
258
|
-
// Fallback to automatic body parameter detection
|
|
259
|
-
// Determine if the body param has a metatype that is a class (DTO)
|
|
260
|
-
let bodySchema: any = {type: 'object'}; // default
|
|
261
|
-
if (bodyParam.metatype) {
|
|
262
|
-
bodySchema = getSchemaFromType(bodyParam.metatype);
|
|
263
|
-
}
|
|
264
|
-
operation.requestBody = {
|
|
265
|
-
required: true,
|
|
266
|
-
content: {
|
|
267
|
-
'application/json': {
|
|
268
|
-
schema: bodySchema
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Check for API response decorators first
|
|
275
|
-
const apiResponses = Reflect.getMetadata(METADATA_KEYS.API_RESPONSES, controllerPrototype)?.[routeMeta.propertyKey] || [];
|
|
276
|
-
|
|
277
|
-
if (apiResponses.length > 0) {
|
|
278
|
-
// Use decorator-defined responses
|
|
279
|
-
for (const response of apiResponses) {
|
|
280
|
-
const statusCode = String(response.status);
|
|
281
|
-
let responseContent = undefined;
|
|
282
|
-
|
|
283
|
-
if (response.type) {
|
|
284
|
-
const responseSchema = getSchemaFromType(response.type);
|
|
285
|
-
if (response.isArray) {
|
|
286
|
-
responseContent = {
|
|
287
|
-
type: 'array',
|
|
288
|
-
items: responseSchema
|
|
289
|
-
};
|
|
290
|
-
} else {
|
|
291
|
-
responseContent = responseSchema;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
operation.responses[statusCode] = {
|
|
296
|
-
description: response.description || '',
|
|
297
|
-
...(responseContent ? {content: {'application/json': {schema: responseContent}}} : {})
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
} else {
|
|
301
|
-
// Fallback to return type detection
|
|
302
|
-
const returnType = Reflect.getMetadata('design:returntype', controllerPrototype, routeMeta.propertyKey);
|
|
303
|
-
if (returnType) {
|
|
304
|
-
// Handle Promise<T> -> T
|
|
305
|
-
let resolvedType = returnType;
|
|
306
|
-
if (typeof returnType === 'function' && returnType.name === 'Promise' && !('length' in (returnType.prototype || {}))) {
|
|
307
|
-
// We can't easily get the generic argument; we'll try to infer from the type string
|
|
308
|
-
// For simplicity, if it's a Promise, we'll still treat the resolved type as unknown.
|
|
309
|
-
// In practice, we could attempt to get the type argument, but it's complex.
|
|
310
|
-
// We'll leave it as object for now.
|
|
311
|
-
resolvedType = Object;
|
|
312
|
-
}
|
|
313
|
-
const responseSchema = getSchemaFromType(resolvedType);
|
|
314
|
-
operation.responses['200'] = {
|
|
315
|
-
description: 'Successful response',
|
|
316
|
-
...(responseSchema ? {content: {'application/json': {schema: responseSchema}}} : {})
|
|
317
|
-
};
|
|
318
|
-
} else {
|
|
319
|
-
// Default response if we cannot determine return type
|
|
320
|
-
operation.responses['200'] = {
|
|
321
|
-
description: 'Successful response'
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Assign operation to path item under the method key
|
|
327
|
-
(spec.paths[path] as any)[method] = operation;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Document registered WebSocket sockets as POST operations (one per event)
|
|
331
|
-
const sockets = getSocketRegistry();
|
|
332
|
-
|
|
333
|
-
for (const [, socketEntry] of sockets) {
|
|
334
|
-
const {namespace, construct, metadata} = socketEntry;
|
|
335
|
-
const classTags = Reflect.getMetadata(METADATA_KEYS.API_TAGS, construct) || [];
|
|
336
|
-
const socketPrototype = construct?.prototype ?? construct;
|
|
337
|
-
|
|
338
|
-
for (const event of metadata.events) {
|
|
339
|
-
if (event.type !== 'event' && event.type !== 'message') continue;
|
|
340
|
-
if (!event.name) continue;
|
|
341
|
-
|
|
342
|
-
const channelPath = `${namespace}`.replace(/\/+/g, '/') || '/';
|
|
343
|
-
const eventPath = `${channelPath}/${event.name}`.replace(/\/+/g, '/');
|
|
344
|
-
|
|
345
|
-
if (!spec.paths[eventPath]) {
|
|
346
|
-
spec.paths[eventPath] = {};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const operation: any = {
|
|
350
|
-
parameters: [],
|
|
351
|
-
responses: {}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
const operationMetadata = Reflect.getMetadata(METADATA_KEYS.API_OPERATION, socketPrototype, event.propertyKey);
|
|
355
|
-
if (operationMetadata) {
|
|
356
|
-
Object.assign(operation, operationMetadata);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const methodTags = Reflect.getMetadata(METADATA_KEYS.API_TAGS, socketPrototype, event.propertyKey);
|
|
360
|
-
operation.tags = [...(methodTags || []), ...classTags];
|
|
361
|
-
|
|
362
|
-
const apiResponses = Reflect.getMetadata(METADATA_KEYS.API_RESPONSES, socketPrototype)?.[event.propertyKey] || [];
|
|
363
|
-
|
|
364
|
-
if (apiResponses.length > 0) {
|
|
365
|
-
for (const response of apiResponses) {
|
|
366
|
-
const statusCode = String(response.status);
|
|
367
|
-
let responseContent = undefined;
|
|
368
|
-
|
|
369
|
-
if (response.type) {
|
|
370
|
-
const responseSchema = getSchemaFromType(response.type);
|
|
371
|
-
responseContent = response.isArray
|
|
372
|
-
? {type: 'array', items: responseSchema}
|
|
373
|
-
: responseSchema;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
operation.responses[statusCode] = {
|
|
377
|
-
description: response.description || '',
|
|
378
|
-
...(responseContent ? {content: {'application/json': {schema: responseContent}}} : {})
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
operation.responses['200'] = {
|
|
383
|
-
description: 'Successful response'
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const apiRequestBody = Reflect.getMetadata(METADATA_KEYS.API_REQUEST_BODY, socketPrototype, event.propertyKey);
|
|
388
|
-
const dataSchema = apiRequestBody?.type
|
|
389
|
-
? getSchemaFromType(apiRequestBody.type)
|
|
390
|
-
: {type: 'object'};
|
|
391
|
-
|
|
392
|
-
operation.requestBody = {
|
|
393
|
-
required: apiRequestBody?.required ?? true,
|
|
394
|
-
content: {
|
|
395
|
-
'application/json': {
|
|
396
|
-
schema: {
|
|
397
|
-
type: 'object',
|
|
398
|
-
properties: {
|
|
399
|
-
event: {type: 'string', enum: [event.name], example: event.name},
|
|
400
|
-
data: dataSchema
|
|
401
|
-
},
|
|
402
|
-
required: ['event', 'data']
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
operation['x-websocket'] = {
|
|
409
|
-
channel: channelPath,
|
|
410
|
-
event: event.name
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
(spec.paths[eventPath] as any).post = operation;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Document registered MCP servers as streamable HTTP (POST JSON-RPC) operations
|
|
418
|
-
const mcpServers = getMcpServerRegistry();
|
|
419
|
-
|
|
420
|
-
for (const [, mcpEntry] of mcpServers) {
|
|
421
|
-
const mcpPath = mcpEntry.path;
|
|
422
|
-
if (!spec.paths[mcpPath]) {
|
|
423
|
-
spec.paths[mcpPath] = {};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const elements = [
|
|
427
|
-
...mcpEntry.metadata.tools.map(t => ({kind: 'tool', ...t})),
|
|
428
|
-
...mcpEntry.metadata.prompts.map(p => ({kind: 'prompt', ...p})),
|
|
429
|
-
...mcpEntry.metadata.resources.map(r => ({kind: 'resource', ...r})),
|
|
430
|
-
...mcpEntry.metadata.resourceTemplates.map(r => ({kind: 'resource-template', ...r})),
|
|
431
|
-
];
|
|
432
|
-
|
|
433
|
-
(spec.paths[mcpPath] as any).post = {
|
|
434
|
-
summary: `MCP server: ${mcpEntry.name} (${mcpEntry.version})`,
|
|
435
|
-
description: mcpEntry.metadata.description
|
|
436
|
-
|| `Model Context Protocol server. Exposes ${
|
|
437
|
-
elements.map(e => `${e.kind}s`).filter((v, i, a) => a.indexOf(v) === i).join(', ') || 'no elements'
|
|
438
|
-
}.`,
|
|
439
|
-
parameters: [],
|
|
440
|
-
requestBody: {
|
|
441
|
-
required: true,
|
|
442
|
-
content: {
|
|
443
|
-
'application/json': {
|
|
444
|
-
schema: {
|
|
445
|
-
type: 'object',
|
|
446
|
-
properties: {
|
|
447
|
-
jsonrpc: {type: 'string', const: '2.0'},
|
|
448
|
-
id: {type: ['number', 'string', 'null']},
|
|
449
|
-
method: {type: 'string', enum: [...new Set(elements.map(e => e.kind === 'tool' ? 'tools/call' : e.kind === 'prompt' ? 'prompts/get' : 'resources/read'))]},
|
|
450
|
-
params: {type: 'object'}
|
|
451
|
-
},
|
|
452
|
-
required: ['jsonrpc', 'method']
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
},
|
|
457
|
-
responses: {
|
|
458
|
-
'200': {
|
|
459
|
-
description: 'Successful JSON-RPC response',
|
|
460
|
-
content: {'application/json': {schema: {type: 'object'}}}
|
|
461
|
-
},
|
|
462
|
-
'202': {
|
|
463
|
-
description: 'Request accepted (notification)'
|
|
464
|
-
},
|
|
465
|
-
'406': {
|
|
466
|
-
description: 'Unsupported protocol version'
|
|
467
|
-
}
|
|
468
|
-
},
|
|
469
|
-
'x-mcp': {
|
|
470
|
-
name: mcpEntry.name,
|
|
471
|
-
version: mcpEntry.version,
|
|
472
|
-
transport: 'streamable-http',
|
|
473
|
-
tools: mcpEntry.metadata.tools.map(t => ({
|
|
474
|
-
name: t.name,
|
|
475
|
-
description: t.description,
|
|
476
|
-
inputSchema: {
|
|
477
|
-
type: 'object',
|
|
478
|
-
properties: Object.fromEntries(
|
|
479
|
-
t.arguments.map(a => [a.name, {type: a.schema?.type || 'string', description: a.description}])
|
|
480
|
-
),
|
|
481
|
-
...(t.arguments.some(a => a.required) ? {required: t.arguments.filter(a => a.required).map(a => a.name)} : {})
|
|
482
|
-
}
|
|
483
|
-
})),
|
|
484
|
-
prompts: mcpEntry.metadata.prompts.map(p => ({
|
|
485
|
-
name: p.name,
|
|
486
|
-
description: p.description,
|
|
487
|
-
arguments: p.arguments.map(a => ({name: a.name, description: a.description, required: a.required}))
|
|
488
|
-
})),
|
|
489
|
-
resources: [
|
|
490
|
-
...mcpEntry.metadata.resources.map(r => ({uri: r.uri, name: r.name, mimeType: r.mimeType})),
|
|
491
|
-
...mcpEntry.metadata.resourceTemplates.map(r => ({uriTemplate: r.uri, name: r.name, mimeType: r.mimeType})),
|
|
492
|
-
]
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return spec;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Attempt to derive a JSON Schema fragment from a TypeScript type.
|
|
502
|
-
* This is a simplified implementation; for production use, consider using
|
|
503
|
-
* a library like @sinclair/typebox or class-transformer to generate schemas.
|
|
504
|
-
*/
|
|
505
|
-
export function getSchemaFromType(type: any, visited: Set<any> = new Set()): any {
|
|
506
|
-
if (typeof type !== 'function') {
|
|
507
|
-
// Not a constructor; fallback to basic type detection
|
|
508
|
-
return getPrimitiveTypeSchema(typeof type);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (visited.has(type)) {
|
|
512
|
-
return {type: 'object', description: 'Circular reference'};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const typeName = type.name;
|
|
516
|
-
switch (typeName) {
|
|
517
|
-
case 'String':
|
|
518
|
-
return {type: 'string'};
|
|
519
|
-
case 'Number':
|
|
520
|
-
return {type: 'number'};
|
|
521
|
-
case 'Boolean':
|
|
522
|
-
return {type: 'boolean'};
|
|
523
|
-
case 'Object':
|
|
524
|
-
return {type: 'object'};
|
|
525
|
-
case 'Array':
|
|
526
|
-
return {
|
|
527
|
-
type: 'array',
|
|
528
|
-
items: {type: 'string'} // We don't know the item type
|
|
529
|
-
};
|
|
530
|
-
case 'Date':
|
|
531
|
-
return {
|
|
532
|
-
type: 'string',
|
|
533
|
-
format: 'date-time'
|
|
534
|
-
};
|
|
535
|
-
default:
|
|
536
|
-
// For custom classes (DTOs, entities, etc.), check for @ApiProperty
|
|
537
|
-
// We use Reflect.getMetadata to support inheritance of properties
|
|
538
|
-
const properties = Reflect.getMetadata(METADATA_KEYS.API_PROPERTY, type);
|
|
539
|
-
|
|
540
|
-
if (properties) {
|
|
541
|
-
visited.add(type);
|
|
542
|
-
const schema: any = {
|
|
543
|
-
type: 'object',
|
|
544
|
-
properties: {},
|
|
545
|
-
required: []
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
for (const [key, options] of Object.entries(properties) as [string, any][]) {
|
|
549
|
-
let propSchema: any;
|
|
550
|
-
const propType = options.type;
|
|
551
|
-
|
|
552
|
-
if (options.isArray) {
|
|
553
|
-
propSchema = {
|
|
554
|
-
type: 'array',
|
|
555
|
-
items: propType ? getSchemaFromType(propType, new Set(visited)) : {type: 'string'}
|
|
556
|
-
};
|
|
557
|
-
} else if (propType) {
|
|
558
|
-
propSchema = getSchemaFromType(propType, new Set(visited));
|
|
559
|
-
} else {
|
|
560
|
-
propSchema = {type: 'string'};
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (options.description) propSchema.description = options.description;
|
|
564
|
-
if (options.example) propSchema.example = options.example;
|
|
565
|
-
if (options.enum) propSchema.enum = options.enum;
|
|
566
|
-
|
|
567
|
-
schema.properties[key] = propSchema;
|
|
568
|
-
if (options.required) {
|
|
569
|
-
schema.required.push(key);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if (schema.required.length === 0) {
|
|
574
|
-
delete schema.required;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
return schema;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return {type: 'object'};
|
|
581
|
-
}
|
|
9
|
+
const {generateOpenApiSpec: generate} = await import("./openapi.utils.impl.ts")
|
|
10
|
+
return generate(scope, opts)
|
|
582
11
|
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Get schema for primitive types (string, number, boolean, bigint, symbol, undefined, object, function)
|
|
586
|
-
*/
|
|
587
|
-
export function getPrimitiveTypeSchema(primitive: string): any {
|
|
588
|
-
switch (primitive) {
|
|
589
|
-
case 'string':
|
|
590
|
-
return {type: 'string'};
|
|
591
|
-
case 'number':
|
|
592
|
-
return {type: 'number'};
|
|
593
|
-
case 'boolean':
|
|
594
|
-
return {type: 'boolean'};
|
|
595
|
-
case 'bigint':
|
|
596
|
-
return {type: 'string'}; // Represent bigint as string in JSON
|
|
597
|
-
case 'undefined':
|
|
598
|
-
return {type: 'null'};
|
|
599
|
-
case 'object':
|
|
600
|
-
return {type: 'object'};
|
|
601
|
-
case 'function':
|
|
602
|
-
return {type: 'string'}; // functions are not serializable; represent as string placeholder
|
|
603
|
-
default:
|
|
604
|
-
return {type: 'string'};
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Generate HTML for Swagger UI using CDN
|
|
610
|
-
*/
|
|
611
|
-
// export function generateHtml(title: string, endpoint: string): string {
|
|
612
|
-
// // Ensure endpoint starts with / if not already
|
|
613
|
-
// if (!endpoint.startsWith('/')) {
|
|
614
|
-
// endpoint = '/' + endpoint;
|
|
615
|
-
// }
|
|
616
|
-
// return `<!DOCTYPE html>
|
|
617
|
-
// <html lang="en">
|
|
618
|
-
// <head>
|
|
619
|
-
// <meta charset="UTF-8">
|
|
620
|
-
// <title>${title} - SwaggerUI</title>
|
|
621
|
-
// <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" />
|
|
622
|
-
// </head>
|
|
623
|
-
// <body>
|
|
624
|
-
// <div id="swagger-ui"></div>
|
|
625
|
-
// <script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
|
|
626
|
-
// <script>
|
|
627
|
-
// window.onload = () => {
|
|
628
|
-
// window.ui = SwaggerUIBundle({
|
|
629
|
-
// url: '${endpoint}',
|
|
630
|
-
// domId: '#swagger-ui',
|
|
631
|
-
// presets: [
|
|
632
|
-
// SwaggerUIBundle.presets.forApis,
|
|
633
|
-
// SwaggerUIBundle.SwaggerUIStandalonePreset
|
|
634
|
-
// ],
|
|
635
|
-
// layout: "BaseLayout"
|
|
636
|
-
// });
|
|
637
|
-
// }
|
|
638
|
-
// </script>
|
|
639
|
-
// </body>
|
|
640
|
-
// </html>`;
|
|
641
|
-
// }
|