@breadstone/archipel-mcp 0.0.10 → 0.0.13
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/data/guides/ai-text-generation.md +361 -0
- package/data/guides/analytics-and-error-tracking.md +189 -0
- package/data/guides/authentication-and-authorization.md +657 -0
- package/data/guides/blob-storage.md +242 -0
- package/data/guides/caching.md +255 -0
- package/data/guides/cryptography-and-otp.md +240 -0
- package/data/guides/database-setup.md +546 -0
- package/data/guides/document-generation.md +174 -0
- package/data/guides/email-delivery.md +196 -0
- package/data/guides/esigning-integration.md +231 -0
- package/data/guides/getting-started.md +351 -0
- package/data/guides/implementing-ports.md +317 -0
- package/data/guides/index.md +62 -0
- package/data/guides/mcp-server.md +222 -0
- package/data/guides/openapi-and-feature-discovery.md +266 -0
- package/data/guides/payments-and-feature-gating.md +244 -0
- package/data/guides/resource-management.md +352 -0
- package/data/guides/telemetry-and-observability.md +190 -0
- package/data/guides/testing.md +319 -0
- package/data/guides/tsdoc-guidelines.md +45 -0
- package/data/packages/platform-database/api/Class.DatabaseModule.md +3 -5
- package/data/packages/platform-database/api/Class.DatabaseService.md +5 -4
- package/data/packages/platform-database/api/Class.PrismaService.md +8 -7
- package/data/packages/platform-database/api/Interface.IDatabaseModuleConfig.md +13 -1
- package/data/packages/platform-database/api/Interface.IPrismaServiceOptions.md +22 -0
- package/data/packages/platform-database/api/Variable.DATABASE_MODULE_CONFIG.md +14 -0
- package/data/packages/platform-database/api/Variable.DB_ACCELERATE_URL.md +14 -0
- package/data/packages/platform-database/api/Variable.DB_AUTO_CONNECTION.md +14 -0
- package/data/packages/platform-database/api/Variable.DB_OPTIMIZE.md +14 -0
- package/data/packages/platform-database/api/Variable.DB_OPTIMIZE_API_KEY.md +14 -0
- package/data/packages/platform-database/api/Variable.PLATFORM_DATABASE_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-database/api/index.md +13 -1
- package/data/packages/platform-database/index.md +41 -18
- package/data/packages/platform-openapi/api/Class.SwaggerFeatureDiscovery.md +10 -6
- package/data/packages/platform-telemetry/api/Class.NoopTelemetryFacade.md +10 -10
- package/data/packages/platform-telemetry/api/Interface.ITelemetryFacade.md +1 -1
- package/package.json +1 -1
- package/src/GuidesLoader.d.ts +13 -0
- package/src/GuidesLoader.js +81 -0
- package/src/main.js +36 -198
- package/src/models/IGuideDoc.d.ts +15 -0
- package/src/models/IGuideDoc.js +3 -0
- package/src/tools/registerGetConfigPatternTool.d.ts +5 -0
- package/src/tools/registerGetConfigPatternTool.js +15 -0
- package/src/tools/registerGetDtoPatternTool.d.ts +5 -0
- package/src/tools/registerGetDtoPatternTool.js +15 -0
- package/src/tools/registerGetErrorHandlingPatternTool.d.ts +5 -0
- package/src/tools/registerGetErrorHandlingPatternTool.js +15 -0
- package/src/tools/registerGetGuardPatternTool.d.ts +5 -0
- package/src/tools/registerGetGuardPatternTool.js +15 -0
- package/src/tools/registerGetGuideTool.d.ts +6 -0
- package/src/tools/registerGetGuideTool.js +32 -0
- package/src/tools/registerGetMappingPatternTool.d.ts +5 -0
- package/src/tools/registerGetMappingPatternTool.js +34 -0
- package/src/tools/registerGetModulePatternTool.d.ts +5 -0
- package/src/tools/registerGetModulePatternTool.js +29 -0
- package/src/tools/registerGetPackageDocTool.d.ts +6 -0
- package/src/tools/registerGetPackageDocTool.js +43 -0
- package/src/tools/registerGetQueryPatternTool.d.ts +5 -0
- package/src/tools/registerGetQueryPatternTool.js +29 -0
- package/src/tools/registerGetRepositoryPatternTool.d.ts +5 -0
- package/src/tools/registerGetRepositoryPatternTool.js +29 -0
- package/src/tools/registerGetTestingPatternTool.d.ts +5 -0
- package/src/tools/registerGetTestingPatternTool.js +15 -0
- package/src/tools/registerListGuidesTool.d.ts +6 -0
- package/src/tools/registerListGuidesTool.js +22 -0
- package/src/tools/registerListPackagesTool.d.ts +6 -0
- package/src/tools/registerListPackagesTool.js +20 -0
- package/src/tools/registerSearchDocsTool.d.ts +6 -0
- package/src/tools/registerSearchDocsTool.js +35 -0
- package/src/tools/registerSearchGuidesTool.d.ts +6 -0
- package/src/tools/registerSearchGuidesTool.js +28 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Guides
|
|
3
|
+
description: Developer guides for integrating and working with Archipel platform libraries.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Guides
|
|
7
|
+
|
|
8
|
+
Practical guides for working with Archipel packages in your NestJS application.
|
|
9
|
+
|
|
10
|
+
## Foundations
|
|
11
|
+
|
|
12
|
+
| Guide | What you'll learn |
|
|
13
|
+
| ------------------------------------------ | -------------------------------------------------------------------------------------- |
|
|
14
|
+
| [Getting Started](./getting-started) | Install packages, register your first module, implement ports, and run the app. |
|
|
15
|
+
| [Implementing Ports](./implementing-ports) | How the port/adapter pattern works, how to write adapters, and how to test them. |
|
|
16
|
+
| [Testing](./testing) | Unit testing services, testing port adapters, integration testing with real databases. |
|
|
17
|
+
| [TSDoc Guidelines](./tsdoc-guidelines) | Documentation standards for public APIs and generated reference pages. |
|
|
18
|
+
|
|
19
|
+
## Security & Identity
|
|
20
|
+
|
|
21
|
+
| Guide | What you'll learn |
|
|
22
|
+
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
23
|
+
| [Authentication & Authorization](./authentication-and-authorization) | JWT tokens, role-based access, custom scopes, MFA, sessions, and OAuth social login. |
|
|
24
|
+
| [Cryptography & OTP](./cryptography-and-otp) | Bcrypt password hashing, prefixed UUIDs, and TOTP multi-factor authentication. |
|
|
25
|
+
|
|
26
|
+
## Data & Storage
|
|
27
|
+
|
|
28
|
+
| Guide | What you'll learn |
|
|
29
|
+
| ----------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
30
|
+
| [Database Setup](./database-setup) | PostgreSQL via Prisma, Accelerate, repositories, queries, transactions, and health. |
|
|
31
|
+
| [Blob Storage](./blob-storage) | Multi-provider file storage, uploads, signed URLs, and metadata tracking. |
|
|
32
|
+
| [Document Generation](./document-generation) | Generate PDF and DOCX from templates with variable substitution and image processing. |
|
|
33
|
+
| [E-Signing Integration](./esigning-integration) | Electronic signature workflows, provider setup, and webhook handling. |
|
|
34
|
+
|
|
35
|
+
## Communication & Payments
|
|
36
|
+
|
|
37
|
+
| Guide | What you'll learn |
|
|
38
|
+
| ---------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
39
|
+
| [Email Delivery](./email-delivery) | Multi-provider email sending, template engines, and verification flows. |
|
|
40
|
+
| [Payments & Feature Gating](./payments-and-feature-gating) | Payment provider integration, webhook handling, and feature-based access control. |
|
|
41
|
+
|
|
42
|
+
## Operations & Observability
|
|
43
|
+
|
|
44
|
+
| Guide | What you'll learn |
|
|
45
|
+
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
|
|
46
|
+
| [Telemetry & Observability](./telemetry-and-observability) | OpenTelemetry metrics, distributed tracing, and structured logging. |
|
|
47
|
+
| [Analytics & Error Tracking](./analytics-and-error-tracking) | Capture errors and user context with Sentry, AppInsights, or Datadog. |
|
|
48
|
+
| [Caching](./caching) | In-memory LRU and Redis layered caches with TTL, stale-while-revalidate, and metrics. |
|
|
49
|
+
|
|
50
|
+
## AI & Extensibility
|
|
51
|
+
|
|
52
|
+
| Guide | What you'll learn |
|
|
53
|
+
| ------------------------------------------ | ------------------------------------------------------------------------------- |
|
|
54
|
+
| [AI Text Generation](./ai-text-generation) | Multi-provider text completions, capability registry, and intent orchestration. |
|
|
55
|
+
| [MCP Server](./mcp-server) | Build MCP servers with tools, resources, and prompts for AI agent integration. |
|
|
56
|
+
|
|
57
|
+
## Platform Internals
|
|
58
|
+
|
|
59
|
+
| Guide | What you'll learn |
|
|
60
|
+
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
61
|
+
| [OpenAPI & Feature Discovery](./openapi-and-feature-discovery) | Multi-document Swagger UI, the @Api decorator, and automatic per-module doc discovery. |
|
|
62
|
+
| [Resource Management](./resource-management) | Load templates, assets, and files from disk, blob storage, or memory via ResourceManager. |
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: MCP Server
|
|
3
|
+
description: Build a Model Context Protocol (MCP) server with tools, resources, and prompts for AI agent integration.
|
|
4
|
+
order: 13
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# MCP Server
|
|
8
|
+
|
|
9
|
+
This guide covers building an MCP server with `platform-mcp`: defining tools, resources, and prompts that AI agents can discover and invoke, selecting transports, and registering everything with auto-discovery.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @breadstone/archipel-platform-mcp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## What is MCP?
|
|
22
|
+
|
|
23
|
+
The [Model Context Protocol](https://modelcontextprotocol.io/) is an open standard for connecting AI agents to external tools and data sources. An MCP server exposes:
|
|
24
|
+
|
|
25
|
+
- **Tools** — Functions the AI can call (e.g., search a database, create a record)
|
|
26
|
+
- **Resources** — Data the AI can read (e.g., configuration, documentation)
|
|
27
|
+
- **Prompts** — Pre-built prompt templates the AI can use
|
|
28
|
+
|
|
29
|
+
`platform-mcp` provides decorators and a discovery service that auto-registers your tools, resources, and prompts.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Module Registration
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Module } from '@nestjs/common';
|
|
37
|
+
import { McpModule } from '@breadstone/archipel-platform-mcp';
|
|
38
|
+
|
|
39
|
+
@Module({
|
|
40
|
+
imports: [
|
|
41
|
+
McpModule.register({
|
|
42
|
+
name: 'my-api-mcp',
|
|
43
|
+
version: '1.0.0',
|
|
44
|
+
}),
|
|
45
|
+
],
|
|
46
|
+
})
|
|
47
|
+
export class AppModule {}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or asynchronously with configuration:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { McpModule } from '@breadstone/archipel-platform-mcp';
|
|
54
|
+
import { ConfigService } from '@breadstone/archipel-platform-core';
|
|
55
|
+
|
|
56
|
+
McpModule.registerAsync({
|
|
57
|
+
useFactory: (configService: ConfigService) => ({
|
|
58
|
+
name: configService.get('MCP_SERVER_NAME'),
|
|
59
|
+
version: configService.get('MCP_SERVER_VERSION'),
|
|
60
|
+
}),
|
|
61
|
+
inject: [ConfigService],
|
|
62
|
+
}),
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Defining Tools
|
|
68
|
+
|
|
69
|
+
Use `@McpTool()` to define callable functions:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Injectable } from '@nestjs/common';
|
|
73
|
+
import { McpTool } from '@breadstone/archipel-platform-mcp';
|
|
74
|
+
|
|
75
|
+
@Injectable()
|
|
76
|
+
export class UserTools {
|
|
77
|
+
@McpTool({
|
|
78
|
+
name: 'search_users',
|
|
79
|
+
description: 'Search for users by name or email',
|
|
80
|
+
parameters: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
query: { type: 'string', description: 'Search term' },
|
|
84
|
+
limit: { type: 'number', description: 'Max results', default: 10 },
|
|
85
|
+
},
|
|
86
|
+
required: ['query'],
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
public async searchUsers(params: { query: string; limit?: number }): Promise<unknown> {
|
|
90
|
+
// Implementation: search your database and return results
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@McpTool({
|
|
94
|
+
name: 'get_user',
|
|
95
|
+
description: 'Get a user by their ID',
|
|
96
|
+
parameters: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
userId: { type: 'string', description: 'The user ID' },
|
|
100
|
+
},
|
|
101
|
+
required: ['userId'],
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
public async getUser(params: { userId: string }): Promise<unknown> {
|
|
105
|
+
// Implementation: fetch a single user
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Defining Resources
|
|
113
|
+
|
|
114
|
+
Use `@McpResource()` to expose data that AI agents can read:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { Injectable } from '@nestjs/common';
|
|
118
|
+
import { McpResource } from '@breadstone/archipel-platform-mcp';
|
|
119
|
+
|
|
120
|
+
@Injectable()
|
|
121
|
+
export class DocsResources {
|
|
122
|
+
@McpResource({
|
|
123
|
+
name: 'api_documentation',
|
|
124
|
+
description: 'API documentation and usage guidelines',
|
|
125
|
+
uri: 'docs://api/overview',
|
|
126
|
+
})
|
|
127
|
+
public async getApiDocs(): Promise<string> {
|
|
128
|
+
return `
|
|
129
|
+
# API Overview
|
|
130
|
+
Base URL: https://api.yourapp.com/v1
|
|
131
|
+
Authentication: Bearer token required
|
|
132
|
+
Rate limit: 1000 requests/hour
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Defining Prompts
|
|
141
|
+
|
|
142
|
+
Use `@McpPrompt()` to register reusable prompt templates:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { Injectable } from '@nestjs/common';
|
|
146
|
+
import { McpPrompt } from '@breadstone/archipel-platform-mcp';
|
|
147
|
+
|
|
148
|
+
@Injectable()
|
|
149
|
+
export class AnalysisPrompts {
|
|
150
|
+
@McpPrompt({
|
|
151
|
+
name: 'analyze_user_activity',
|
|
152
|
+
description: "Analyze a user's recent activity and provide insights",
|
|
153
|
+
parameters: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
userId: { type: 'string', description: 'The user to analyze' },
|
|
157
|
+
timeRange: { type: 'string', description: 'Time range (e.g., 7d, 30d)', default: '7d' },
|
|
158
|
+
},
|
|
159
|
+
required: ['userId'],
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
public getTemplate(params: { userId: string; timeRange?: string }): string {
|
|
163
|
+
return `Analyze the recent activity for user ${params.userId} over the last ${params.timeRange ?? '7d'}.
|
|
164
|
+
Provide insights on usage patterns, feature adoption, and potential issues.`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Auto-Discovery
|
|
172
|
+
|
|
173
|
+
`McpDiscoveryService` automatically finds and registers all classes that use `@McpTool`, `@McpResource`, or `@McpPrompt` decorators. Just ensure the classes are registered as NestJS providers:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
@Module({
|
|
177
|
+
imports: [McpModule.register({ name: 'my-api-mcp', version: '1.0.0' })],
|
|
178
|
+
providers: [UserTools, DocsResources, AnalysisPrompts],
|
|
179
|
+
})
|
|
180
|
+
export class McpFeatureModule {}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Transport Options
|
|
186
|
+
|
|
187
|
+
MCP supports multiple transport protocols:
|
|
188
|
+
|
|
189
|
+
| Transport | When to use |
|
|
190
|
+
| --------- | --------------------------------------------- |
|
|
191
|
+
| **SSE** | Browser-based AI agents, streaming responses |
|
|
192
|
+
| **HTTP** | Standard REST-based AI agent communication |
|
|
193
|
+
| **Stdio** | CLI tools, local development, piped processes |
|
|
194
|
+
|
|
195
|
+
The `McpServerService` handles transport negotiation automatically.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Connecting the Guides
|
|
200
|
+
|
|
201
|
+
The MCP server can expose Archipel's guides as resources. This makes your documentation discoverable by AI agents:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
@Injectable()
|
|
205
|
+
export class GuideResources {
|
|
206
|
+
@McpResource({
|
|
207
|
+
name: 'guide_authentication',
|
|
208
|
+
description: 'Guide for setting up authentication and authorization',
|
|
209
|
+
uri: 'docs://guides/authentication-and-authorization',
|
|
210
|
+
})
|
|
211
|
+
public async getAuthGuide(): Promise<string> {
|
|
212
|
+
// Read and return the guide content
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Next Steps
|
|
220
|
+
|
|
221
|
+
- Browse the [platform-mcp API reference](/packages/platform-mcp/api/) for complete decorator options
|
|
222
|
+
- See the [Getting Started](/guides/getting-started) guide for basic module setup
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: OpenAPI & Feature Discovery
|
|
3
|
+
description: Set up multi-document Swagger UI, annotate controllers with the @Api decorator, and use @SwaggerFeature for automatic per-module documentation discovery.
|
|
4
|
+
order: 16
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# OpenAPI & Feature Discovery
|
|
8
|
+
|
|
9
|
+
This guide covers the full lifecycle of API documentation with `platform-openapi`: installing the package, configuring environment variables, annotating controllers, registering feature modules, and bootstrapping the multi-document Swagger UI.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @breadstone/archipel-platform-openapi
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
### Environment Variables
|
|
24
|
+
|
|
25
|
+
All four variables are **required**:
|
|
26
|
+
|
|
27
|
+
```env
|
|
28
|
+
APP_VERSION=1.0.0
|
|
29
|
+
SWAGGER_CONTACT_NAME=Your Team
|
|
30
|
+
SWAGGER_CONTACT_URL=https://yourcompany.com
|
|
31
|
+
SWAGGER_CONTACT_EMAIL=api@yourcompany.com
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Variable | Purpose |
|
|
35
|
+
| ----------------------- | -------------------------------------------------- |
|
|
36
|
+
| `APP_VERSION` | Version shown in every generated OpenAPI document. |
|
|
37
|
+
| `SWAGGER_CONTACT_NAME` | Contact name in the info block. |
|
|
38
|
+
| `SWAGGER_CONTACT_URL` | Contact URL in the info block. |
|
|
39
|
+
| `SWAGGER_CONTACT_EMAIL` | Contact email in the info block. |
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Overview: How It Works
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
@SwaggerFeature() SwaggerFeatureDiscovery SwaggerFeatureRegistry SwaggerMultiDocumentService
|
|
47
|
+
────────────────── ────────────────────── ────────────────────── ───────────────────────────
|
|
48
|
+
Decorator stores Reads global store and Holds finalized list of Builds per-feature OpenAPI
|
|
49
|
+
metadata in global registers features into features. Sorted, locked, documents, sets up Swagger
|
|
50
|
+
store at import time. the registry. immutable after finalize(). UI routes, and index page.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
1. Each feature module is decorated with `@SwaggerFeature()` — metadata is stored globally when the module is imported.
|
|
54
|
+
2. During bootstrap, `SwaggerFeatureDiscovery` reads all registered features and pushes them into `SwaggerFeatureRegistry`.
|
|
55
|
+
3. `SwaggerMultiDocumentService` finalizes the registry, builds one OpenAPI document per feature (filtered by tag), and mounts Swagger UI + JSON endpoints.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Step 1: Annotate Feature Modules
|
|
60
|
+
|
|
61
|
+
Decorate each feature module with `@SwaggerFeature()`. This tells the discovery system which tag corresponds to which documentation section.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { Module } from '@nestjs/common';
|
|
65
|
+
import { SwaggerFeature } from '@breadstone/archipel-platform-openapi';
|
|
66
|
+
import { TipController } from './TipController';
|
|
67
|
+
import { TipService } from './TipService';
|
|
68
|
+
|
|
69
|
+
@SwaggerFeature({
|
|
70
|
+
name: 'tip',
|
|
71
|
+
title: 'My App API — Tips',
|
|
72
|
+
description: 'API endpoints for tip management.',
|
|
73
|
+
tag: 'Tip',
|
|
74
|
+
tags: ['Tip'],
|
|
75
|
+
})
|
|
76
|
+
@Module({
|
|
77
|
+
controllers: [TipController],
|
|
78
|
+
providers: [TipService],
|
|
79
|
+
exports: [TipService],
|
|
80
|
+
})
|
|
81
|
+
export class TipModule {}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Property | Required | Description |
|
|
85
|
+
| ------------- | -------- | ---------------------------------------------------------------------------- |
|
|
86
|
+
| `name` | Yes | Short identifier used for the URL path (e.g. `docs/tip`). |
|
|
87
|
+
| `title` | Yes | Human-readable title shown in the Swagger UI header. |
|
|
88
|
+
| `description` | Yes | Description shown in the Swagger UI header and on the index page. |
|
|
89
|
+
| `tag` | Yes | Primary OpenAPI tag — operations with this tag are included in the document. |
|
|
90
|
+
| `tags` | Yes | Array of all tags to include. Usually `[tag]`. |
|
|
91
|
+
| `path` | No | Custom URL path. Defaults to `docs/{name}`. |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Step 2: Annotate Controllers with `@Api()`
|
|
96
|
+
|
|
97
|
+
`@Api()` is a convenience decorator that combines multiple `@nestjs/swagger` decorators into one. Use it on methods or classes to keep controller annotations concise.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { Controller, Get, Post, Body, Param, HttpCode, HttpStatus } from '@nestjs/common';
|
|
101
|
+
import { Api } from '@breadstone/archipel-platform-openapi';
|
|
102
|
+
import { CreateTipRequest } from './dto/CreateTipRequest';
|
|
103
|
+
import { TipResponse } from './dto/TipResponse';
|
|
104
|
+
|
|
105
|
+
@Controller('api/v1/tips')
|
|
106
|
+
export class TipController {
|
|
107
|
+
@Get()
|
|
108
|
+
@Api({
|
|
109
|
+
tags: 'Tip',
|
|
110
|
+
operation: { summary: 'List all tips' },
|
|
111
|
+
responses: [{ status: 200, description: 'Tips retrieved.', type: [TipResponse] }],
|
|
112
|
+
})
|
|
113
|
+
public listTips(): Promise<TipResponse[]> {
|
|
114
|
+
// ...
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Get(':tipId')
|
|
118
|
+
@Api({
|
|
119
|
+
tags: 'Tip',
|
|
120
|
+
auth: 'bearer',
|
|
121
|
+
operation: { summary: 'Get a tip by ID' },
|
|
122
|
+
params: { name: 'tipId', type: String },
|
|
123
|
+
responses: [
|
|
124
|
+
{ status: 200, description: 'Tip found.', type: TipResponse },
|
|
125
|
+
{ status: 404, description: 'Tip not found.' },
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
public getTip(@Param('tipId') tipId: string): Promise<TipResponse> {
|
|
129
|
+
// ...
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Post()
|
|
133
|
+
@HttpCode(HttpStatus.CREATED)
|
|
134
|
+
@Api({
|
|
135
|
+
tags: 'Tip',
|
|
136
|
+
auth: 'bearer',
|
|
137
|
+
operation: { summary: 'Create a new tip' },
|
|
138
|
+
body: { type: CreateTipRequest },
|
|
139
|
+
responses: [
|
|
140
|
+
{ status: 201, description: 'Tip created.', type: TipResponse },
|
|
141
|
+
{ status: 400, description: 'Validation failed.' },
|
|
142
|
+
],
|
|
143
|
+
})
|
|
144
|
+
public createTip(@Body() body: CreateTipRequest): Promise<TipResponse> {
|
|
145
|
+
// ...
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### `@Api()` Options Reference
|
|
151
|
+
|
|
152
|
+
| Option | Type | Description |
|
|
153
|
+
| ------------ | --------------------------------------------- | ---------------------------------------------------- |
|
|
154
|
+
| `auth` | `'bearer' \| 'basic' \| 'oauth2' \| 'cookie'` | Adds the corresponding auth decorator. |
|
|
155
|
+
| `tags` | `string \| string[]` | OpenAPI tag(s) for the operation. |
|
|
156
|
+
| `operation` | `ApiOperationOptions` | Summary, description, deprecation flag, etc. |
|
|
157
|
+
| `responses` | `ApiResponseOptions \| ApiResponseOptions[]` | One or more response definitions. |
|
|
158
|
+
| `headers` | `ApiHeaderOptions[]` | Expected request headers. |
|
|
159
|
+
| `params` | `ApiParamOptions \| ApiParamOptions[]` | Path parameter definitions. |
|
|
160
|
+
| `query` | `ApiQueryOptions \| ApiQueryOptions[]` | Query parameter definitions. |
|
|
161
|
+
| `body` | `ApiBodyOptions` | Request body definition. |
|
|
162
|
+
| `scopes` | `string[]` | OAuth2 scopes (only relevant when `auth: 'oauth2'`). |
|
|
163
|
+
| `extensions` | `Record<string, string \| number \| boolean>` | Custom OpenAPI extension properties (`x-*`). |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Step 3: Bootstrap the Swagger UI
|
|
168
|
+
|
|
169
|
+
In your application bootstrap (`main.ts`), wire up discovery and the multi-document service:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { NestFactory } from '@nestjs/core';
|
|
173
|
+
import {
|
|
174
|
+
SwaggerFeatureDiscovery,
|
|
175
|
+
SwaggerFeatureRegistry,
|
|
176
|
+
SwaggerMultiDocumentService,
|
|
177
|
+
} from '@breadstone/archipel-platform-openapi';
|
|
178
|
+
import { ConfigService, ContentTemplateEngine, HostService, ResourceManager } from '@breadstone/archipel-platform-core';
|
|
179
|
+
import { AppModule } from './AppModule';
|
|
180
|
+
|
|
181
|
+
async function bootstrap() {
|
|
182
|
+
const app = await NestFactory.create(AppModule);
|
|
183
|
+
|
|
184
|
+
// Resolve services
|
|
185
|
+
const configService = app.get(ConfigService);
|
|
186
|
+
const hostService = app.get(HostService);
|
|
187
|
+
const resourceManager = app.get(ResourceManager);
|
|
188
|
+
const contentTemplateEngine = app.get(ContentTemplateEngine);
|
|
189
|
+
|
|
190
|
+
// 1. Discover features
|
|
191
|
+
const featureRegistry = new SwaggerFeatureRegistry();
|
|
192
|
+
const discovery = new SwaggerFeatureDiscovery();
|
|
193
|
+
discovery.registerDiscoveredFeatures(featureRegistry);
|
|
194
|
+
discovery.registerDefaultFeatures(featureRegistry);
|
|
195
|
+
|
|
196
|
+
// 2. Setup multi-document Swagger UI
|
|
197
|
+
const swaggerService = new SwaggerMultiDocumentService(
|
|
198
|
+
app,
|
|
199
|
+
configService,
|
|
200
|
+
hostService,
|
|
201
|
+
featureRegistry,
|
|
202
|
+
resourceManager,
|
|
203
|
+
contentTemplateEngine,
|
|
204
|
+
);
|
|
205
|
+
await swaggerService.setupMultipleSwaggerDocuments();
|
|
206
|
+
|
|
207
|
+
await app.listen(3000);
|
|
208
|
+
}
|
|
209
|
+
bootstrap();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
After bootstrap the following routes are available:
|
|
213
|
+
|
|
214
|
+
| Route | What it serves |
|
|
215
|
+
| ------------------ | --------------------------------------------------- |
|
|
216
|
+
| `/docs` | Main index page with a searchable feature grid. |
|
|
217
|
+
| `/docs/{name}` | Swagger UI for a single feature (e.g. `/docs/tip`). |
|
|
218
|
+
| `/api/{name}.json` | Raw OpenAPI JSON for a single feature. |
|
|
219
|
+
| `/docs/all` | Combined Swagger UI with every endpoint. |
|
|
220
|
+
| `/api/all.json` | Combined OpenAPI JSON. |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## How Tag Filtering Works
|
|
225
|
+
|
|
226
|
+
Each feature declares a `tag` (e.g. `'Tip'`). When the document is built:
|
|
227
|
+
|
|
228
|
+
1. A full OpenAPI document is created from the entire application.
|
|
229
|
+
2. All paths that do **not** have an operation tagged with the feature's tag are removed.
|
|
230
|
+
3. Schema references used only by removed operations are pruned.
|
|
231
|
+
4. The special tag `'*'` (used by the default `all` feature) skips filtering entirely.
|
|
232
|
+
|
|
233
|
+
This means the `tag` value in `@SwaggerFeature()` must match the `tags` value you pass to `@Api()` on your controllers.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Exporting OpenAPI Specs Programmatically
|
|
238
|
+
|
|
239
|
+
If you need the generated OpenAPI documents outside of a running HTTP server (e.g. for CI contract checks or SDK generation), use `generateOpenApiDocuments()`:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const documents = swaggerService.generateOpenApiDocuments();
|
|
243
|
+
|
|
244
|
+
for (const { feature, document } of documents) {
|
|
245
|
+
const json = JSON.stringify(document, null, 2);
|
|
246
|
+
writeFileSync(`specs/${feature.name}.json`, json);
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Theme Customization
|
|
253
|
+
|
|
254
|
+
`SwaggerTheme` loads `swagger.css` and `swagger.js` from the package assets via `ResourceManager`. These files customize the Swagger UI appearance (colors, dark theme, responsive layout). The theme is applied automatically — no additional configuration is needed.
|
|
255
|
+
|
|
256
|
+
To override the theme, provide your own `swagger.css` / `swagger.js` files through a `FileResourceStrategy` with a higher-priority base path so that `ResourceManager` picks them up before the built-in assets.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Checklist
|
|
261
|
+
|
|
262
|
+
- [ ] All four environment variables set (`APP_VERSION`, `SWAGGER_CONTACT_*`)
|
|
263
|
+
- [ ] Every feature module decorated with `@SwaggerFeature()`
|
|
264
|
+
- [ ] Tags in `@SwaggerFeature({ tag })` match tags in `@Api({ tags })`
|
|
265
|
+
- [ ] `SwaggerFeatureDiscovery` called before `setupMultipleSwaggerDocuments()`
|
|
266
|
+
- [ ] `registerDefaultFeatures()` called for the combined `/docs/all` document
|