@navios/openapi-bun 0.7.0
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 +33 -0
- package/LICENSE +8 -0
- package/README.md +286 -0
- package/dist/src/controllers/index.d.mts +4 -0
- package/dist/src/controllers/index.d.mts.map +1 -0
- package/dist/src/controllers/openapi-json.controller.d.mts +10 -0
- package/dist/src/controllers/openapi-json.controller.d.mts.map +1 -0
- package/dist/src/controllers/openapi-ui.controller.d.mts +10 -0
- package/dist/src/controllers/openapi-ui.controller.d.mts.map +1 -0
- package/dist/src/controllers/openapi-yaml.controller.d.mts +10 -0
- package/dist/src/controllers/openapi-yaml.controller.d.mts.map +1 -0
- package/dist/src/index.d.mts +8 -0
- package/dist/src/index.d.mts.map +1 -0
- package/dist/src/openapi-bun.plugin.d.mts +68 -0
- package/dist/src/openapi-bun.plugin.d.mts.map +1 -0
- package/dist/src/schemas/index.d.mts +2 -0
- package/dist/src/schemas/index.d.mts.map +1 -0
- package/dist/src/schemas/openapi-bun-options.schema.d.mts +114 -0
- package/dist/src/schemas/openapi-bun-options.schema.d.mts.map +1 -0
- package/dist/src/services/index.d.mts +2 -0
- package/dist/src/services/index.d.mts.map +1 -0
- package/dist/src/services/openapi-document.service.d.mts +38 -0
- package/dist/src/services/openapi-document.service.d.mts.map +1 -0
- package/dist/src/tokens/index.d.mts +2 -0
- package/dist/src/tokens/index.d.mts.map +1 -0
- package/dist/src/tokens/openapi-options.token.d.mts +25 -0
- package/dist/src/tokens/openapi-options.token.d.mts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsdown.config.d.mts +3 -0
- package/dist/tsdown.config.d.mts.map +1 -0
- package/dist/vitest.config.d.mts +3 -0
- package/dist/vitest.config.d.mts.map +1 -0
- package/lib/index.cjs +4326 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +262 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +262 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +4311 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +48 -0
- package/project.json +66 -0
- package/src/controllers/index.mts +3 -0
- package/src/controllers/openapi-json.controller.mts +51 -0
- package/src/controllers/openapi-ui.controller.mts +72 -0
- package/src/controllers/openapi-yaml.controller.mts +46 -0
- package/src/index.mts +30 -0
- package/src/openapi-bun.plugin.mts +167 -0
- package/src/schemas/index.mts +10 -0
- package/src/schemas/openapi-bun-options.schema.mts +135 -0
- package/src/services/index.mts +4 -0
- package/src/services/openapi-document.service.mts +83 -0
- package/src/tokens/index.mts +1 -0
- package/src/tokens/openapi-options.token.mts +31 -0
- package/tsconfig.json +15 -0
- package/tsconfig.lib.json +8 -0
- package/tsconfig.spec.json +8 -0
- package/tsdown.config.mts +41 -0
- package/vitest.config.mts +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.7.0] - 2025-12-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Bun OpenAPI Provider**: Initial release of the Bun provider for OpenAPI documentation
|
|
13
|
+
- **Scalar UI Integration**: Interactive Scalar UI for exploring API documentation
|
|
14
|
+
- **OpenAPI Plugin**: `defineOpenApiPlugin()` function for easy integration with Navios applications
|
|
15
|
+
- **Automatic Spec Generation**: Automatic OpenAPI specification generation from Navios controllers
|
|
16
|
+
- **JSON Endpoint**: `/openapi.json` endpoint serving OpenAPI specification in JSON format
|
|
17
|
+
- **YAML Endpoint**: `/openapi.yaml` endpoint serving OpenAPI specification in YAML format (configurable)
|
|
18
|
+
- **Documentation UI**: `/docs` endpoint serving interactive Scalar UI documentation
|
|
19
|
+
- **Customizable Configuration**: Extensive configuration options:
|
|
20
|
+
- OpenAPI info (title, version, description, contact, license, termsOfService)
|
|
21
|
+
- Server definitions
|
|
22
|
+
- Security schemes and global security requirements
|
|
23
|
+
- Custom tags with descriptions
|
|
24
|
+
- Customizable paths for JSON, YAML, and docs endpoints
|
|
25
|
+
- Scalar UI theme configuration (default, alternate, moon, purple, solarized)
|
|
26
|
+
- Option to disable YAML endpoint
|
|
27
|
+
- **Bun Integration**: Seamless integration with Bun's HTTP server
|
|
28
|
+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
29
|
+
- **All Core Decorators**: Full support for all decorators from `@navios/openapi`:
|
|
30
|
+
- `@ApiTag`, `@ApiOperation`, `@ApiSummary`, `@ApiDeprecated`, `@ApiSecurity`, `@ApiExclude`, `@ApiStream`
|
|
31
|
+
- **Endpoint Type Support**: Support for all endpoint types (standard, multipart, stream)
|
|
32
|
+
- **Zod Schema Support**: Automatic conversion of Zod schemas to OpenAPI schemas
|
|
33
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2025 Oleksandr Hanzha
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# @navios/openapi-bun
|
|
2
|
+
|
|
3
|
+
Bun provider for OpenAPI documentation with Scalar UI integration.
|
|
4
|
+
|
|
5
|
+
This package provides OpenAPI documentation generation for Navios applications running on Bun, including automatic endpoint discovery, schema conversion, and Scalar UI integration for interactive API documentation.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
`@navios/openapi-bun` extends `@navios/openapi` with Bun-specific integration, providing:
|
|
10
|
+
|
|
11
|
+
- Scalar UI for interactive API documentation
|
|
12
|
+
- Automatic OpenAPI spec generation
|
|
13
|
+
- JSON and YAML endpoints for the OpenAPI specification
|
|
14
|
+
- Seamless integration with Bun's HTTP server
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Automatic endpoint discovery from Navios controllers
|
|
19
|
+
- Zod schema to OpenAPI schema conversion
|
|
20
|
+
- Interactive Scalar UI documentation
|
|
21
|
+
- OpenAPI JSON and YAML endpoints
|
|
22
|
+
- Customizable themes and configuration
|
|
23
|
+
- Support for all endpoint types (standard, multipart, stream)
|
|
24
|
+
- Type-safe configuration
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bun add @navios/openapi @navios/openapi-bun
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or with npm:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @navios/openapi @navios/openapi-bun
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Basic Setup
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { defineBunEnvironment } from '@navios/adapter-bun'
|
|
44
|
+
import { Module, NaviosFactory } from '@navios/core'
|
|
45
|
+
import { defineOpenApiPlugin } from '@navios/openapi-bun'
|
|
46
|
+
import { ApiTag, ApiOperation } from '@navios/openapi'
|
|
47
|
+
|
|
48
|
+
import { AppModule } from './app.module.js'
|
|
49
|
+
|
|
50
|
+
async function bootstrap() {
|
|
51
|
+
const app = await NaviosFactory.create(AppModule, {
|
|
52
|
+
adapter: defineBunEnvironment(),
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
app.usePlugin(
|
|
56
|
+
defineOpenApiPlugin({
|
|
57
|
+
info: {
|
|
58
|
+
title: 'My API',
|
|
59
|
+
version: '1.0.0',
|
|
60
|
+
description: 'API documentation',
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
await app.init()
|
|
66
|
+
await app.listen({ port: 3000 })
|
|
67
|
+
|
|
68
|
+
console.log('API docs available at http://localhost:3000/docs')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
bootstrap()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Complete Example
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { defineBunEnvironment } from '@navios/adapter-bun'
|
|
78
|
+
import { builder } from '@navios/builder'
|
|
79
|
+
import {
|
|
80
|
+
Controller,
|
|
81
|
+
Endpoint,
|
|
82
|
+
EndpointParams,
|
|
83
|
+
Module,
|
|
84
|
+
NaviosFactory,
|
|
85
|
+
} from '@navios/core'
|
|
86
|
+
import { defineOpenApiPlugin } from '@navios/openapi-bun'
|
|
87
|
+
import { ApiOperation, ApiTag } from '@navios/openapi'
|
|
88
|
+
import { z } from 'zod'
|
|
89
|
+
|
|
90
|
+
const API = builder()
|
|
91
|
+
|
|
92
|
+
const userSchema = z.object({
|
|
93
|
+
id: z.string(),
|
|
94
|
+
name: z.string(),
|
|
95
|
+
email: z.string().email(),
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
export const getUser = API.declareEndpoint({
|
|
99
|
+
method: 'GET',
|
|
100
|
+
url: '/users/$userId',
|
|
101
|
+
responseSchema: userSchema,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
@Controller()
|
|
105
|
+
@ApiTag('Users', 'User management operations')
|
|
106
|
+
class UserController {
|
|
107
|
+
@Endpoint(getUser)
|
|
108
|
+
@ApiOperation({
|
|
109
|
+
summary: 'Get user by ID',
|
|
110
|
+
description: 'Retrieves a user by their unique identifier.',
|
|
111
|
+
})
|
|
112
|
+
async getUser(params: EndpointParams<typeof getUser>) {
|
|
113
|
+
return {
|
|
114
|
+
id: params.urlParams.userId,
|
|
115
|
+
name: 'John',
|
|
116
|
+
email: 'john@example.com',
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Module({ controllers: [UserController] })
|
|
122
|
+
class AppModule {}
|
|
123
|
+
|
|
124
|
+
async function bootstrap() {
|
|
125
|
+
const app = await NaviosFactory.create(AppModule, {
|
|
126
|
+
adapter: defineBunEnvironment(),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
app.usePlugin(
|
|
130
|
+
defineOpenApiPlugin({
|
|
131
|
+
info: {
|
|
132
|
+
title: 'User API',
|
|
133
|
+
version: '1.0.0',
|
|
134
|
+
},
|
|
135
|
+
securitySchemes: {
|
|
136
|
+
bearerAuth: {
|
|
137
|
+
type: 'http',
|
|
138
|
+
scheme: 'bearer',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
await app.init()
|
|
145
|
+
await app.listen({ port: 3000 })
|
|
146
|
+
console.log('API docs: http://localhost:3000/docs')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
bootstrap()
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Advanced Configuration
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
app.usePlugin(
|
|
156
|
+
defineOpenApiPlugin({
|
|
157
|
+
info: {
|
|
158
|
+
title: 'My API',
|
|
159
|
+
version: '1.0.0',
|
|
160
|
+
description: 'Complete API documentation',
|
|
161
|
+
termsOfService: 'https://example.com/terms',
|
|
162
|
+
contact: {
|
|
163
|
+
name: 'API Support',
|
|
164
|
+
url: 'https://example.com/support',
|
|
165
|
+
email: 'support@example.com',
|
|
166
|
+
},
|
|
167
|
+
license: {
|
|
168
|
+
name: 'MIT',
|
|
169
|
+
url: 'https://opensource.org/licenses/MIT',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
servers: [
|
|
173
|
+
{ url: 'http://localhost:3000', description: 'Development' },
|
|
174
|
+
{ url: 'https://api.example.com', description: 'Production' },
|
|
175
|
+
],
|
|
176
|
+
securitySchemes: {
|
|
177
|
+
bearerAuth: {
|
|
178
|
+
type: 'http',
|
|
179
|
+
scheme: 'bearer',
|
|
180
|
+
bearerFormat: 'JWT',
|
|
181
|
+
},
|
|
182
|
+
apiKey: {
|
|
183
|
+
type: 'apiKey',
|
|
184
|
+
in: 'header',
|
|
185
|
+
name: 'X-API-Key',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
security: [{ bearerAuth: [] }], // Global security requirement
|
|
189
|
+
tags: [
|
|
190
|
+
{ name: 'Users', description: 'User management' },
|
|
191
|
+
{ name: 'Orders', description: 'Order processing' },
|
|
192
|
+
],
|
|
193
|
+
jsonPath: '/openapi.json',
|
|
194
|
+
yamlPath: '/openapi.yaml',
|
|
195
|
+
docsPath: '/docs',
|
|
196
|
+
scalar: {
|
|
197
|
+
theme: 'purple',
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Configuration Options
|
|
204
|
+
|
|
205
|
+
### Path Configuration
|
|
206
|
+
|
|
207
|
+
| Option | Default | Description |
|
|
208
|
+
| ---------- | --------------- | -------------------------- |
|
|
209
|
+
| `jsonPath` | `/openapi.json` | Path to serve OpenAPI JSON |
|
|
210
|
+
| `yamlPath` | `/openapi.yaml` | Path to serve OpenAPI YAML |
|
|
211
|
+
| `docsPath` | `/docs` | Path to serve Scalar UI |
|
|
212
|
+
| `disableYaml` | `false` | Disable YAML endpoint |
|
|
213
|
+
|
|
214
|
+
### Scalar Themes
|
|
215
|
+
|
|
216
|
+
The `scalar.theme` option accepts: `'default'`, `'alternate'`, `'moon'`, `'purple'`, `'solarized'`.
|
|
217
|
+
|
|
218
|
+
## Decorators
|
|
219
|
+
|
|
220
|
+
All decorators from `@navios/openapi` are available:
|
|
221
|
+
|
|
222
|
+
- `@ApiTag` - Group endpoints under tags
|
|
223
|
+
- `@ApiOperation` - Full operation metadata
|
|
224
|
+
- `@ApiSummary` - Quick summary
|
|
225
|
+
- `@ApiDeprecated` - Mark as deprecated
|
|
226
|
+
- `@ApiSecurity` - Security requirements
|
|
227
|
+
- `@ApiExclude` - Exclude from docs
|
|
228
|
+
- `@ApiStream` - Stream endpoint metadata
|
|
229
|
+
|
|
230
|
+
See [@navios/openapi](../openapi/README.md) for detailed decorator documentation.
|
|
231
|
+
|
|
232
|
+
## Endpoints
|
|
233
|
+
|
|
234
|
+
After setup, the following endpoints are automatically available:
|
|
235
|
+
|
|
236
|
+
- `GET /docs` - Interactive Scalar UI documentation
|
|
237
|
+
- `GET /openapi.json` - OpenAPI specification in JSON format
|
|
238
|
+
- `GET /openapi.yaml` - OpenAPI specification in YAML format (if enabled)
|
|
239
|
+
|
|
240
|
+
## Requirements
|
|
241
|
+
|
|
242
|
+
- **Runtime**: Bun 1.0+
|
|
243
|
+
- **Dependencies**:
|
|
244
|
+
- `@navios/adapter-bun` - Bun adapter for Navios
|
|
245
|
+
- `@navios/core` - Core Navios framework
|
|
246
|
+
- `@navios/openapi` - Core OpenAPI package
|
|
247
|
+
- `zod` ^3.25.0 || ^4.0.0 - Schema validation
|
|
248
|
+
- **Peer Dependencies**:
|
|
249
|
+
- `@navios/builder` - Endpoint builder
|
|
250
|
+
|
|
251
|
+
## Features
|
|
252
|
+
|
|
253
|
+
- **Automatic Discovery**: Discovers all endpoints from your controllers
|
|
254
|
+
- **Schema Conversion**: Converts Zod schemas to OpenAPI schemas automatically
|
|
255
|
+
- **Interactive UI**: Beautiful Scalar UI for exploring your API
|
|
256
|
+
- **Type Safety**: Full TypeScript support with comprehensive types
|
|
257
|
+
- **Customizable**: Extensive configuration options
|
|
258
|
+
- **Production Ready**: Battle-tested in production environments
|
|
259
|
+
|
|
260
|
+
## Examples
|
|
261
|
+
|
|
262
|
+
For complete working examples, see:
|
|
263
|
+
|
|
264
|
+
- [OpenAPI Examples](../../examples/openapi/src/bun.mts) - Full Bun example
|
|
265
|
+
- [OpenAPI Guide](../../apps/docs/docs/server/guides/openapi.md) - Comprehensive documentation
|
|
266
|
+
|
|
267
|
+
## Documentation
|
|
268
|
+
|
|
269
|
+
For complete documentation on using OpenAPI with Navios, see:
|
|
270
|
+
|
|
271
|
+
- [OpenAPI Guide](../../apps/docs/docs/server/guides/openapi.md)
|
|
272
|
+
- [@navios/openapi Core Package](../openapi/README.md)
|
|
273
|
+
- [Controllers & Endpoints](../core/docs/controllers.md)
|
|
274
|
+
|
|
275
|
+
## Comparison with Fastify Provider
|
|
276
|
+
|
|
277
|
+
| Feature | Bun Provider | Fastify Provider |
|
|
278
|
+
| ----------- | --------------- | ---------------- |
|
|
279
|
+
| Runtime | Bun | Node.js |
|
|
280
|
+
| Performance | Very High | High |
|
|
281
|
+
| UI | Scalar | Scalar |
|
|
282
|
+
| Setup | Simple | Simple |
|
|
283
|
+
| Themes | 5 themes | 5 themes |
|
|
284
|
+
|
|
285
|
+
Both providers offer the same features and API - choose based on your runtime environment.
|
|
286
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a customized JSON controller with the correct path.
|
|
4
|
+
* Called by the plugin to create a controller with the configured jsonPath.
|
|
5
|
+
*
|
|
6
|
+
* @param jsonPath - The path to serve the OpenAPI JSON (e.g., '/openapi.json')
|
|
7
|
+
* @returns A controller class that serves the OpenAPI document as JSON
|
|
8
|
+
*/
|
|
9
|
+
export declare function createOpenApiJsonController(jsonPath: string): ClassType;
|
|
10
|
+
//# sourceMappingURL=openapi-json.controller.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-json.controller.d.mts","sourceRoot":"","sources":["../../../src/controllers/openapi-json.controller.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAgB3C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CA0BvE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a customized Scalar UI controller with the correct path.
|
|
4
|
+
*
|
|
5
|
+
* @param docsPath - The path to serve the Scalar UI (e.g., '/docs')
|
|
6
|
+
* @param jsonPath - The path to the OpenAPI JSON spec (used by Scalar to load the spec)
|
|
7
|
+
* @returns A controller class that serves the Scalar API Reference UI
|
|
8
|
+
*/
|
|
9
|
+
export declare function createOpenApiUiController(docsPath: string, jsonPath: string): ClassType;
|
|
10
|
+
//# sourceMappingURL=openapi-ui.controller.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-ui.controller.d.mts","sourceRoot":"","sources":["../../../src/controllers/openapi-ui.controller.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAY3C;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,SAAS,CAgDX"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClassType } from '@navios/di';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a customized YAML controller with the correct path.
|
|
4
|
+
* Uses Stream endpoint to set content-type header properly.
|
|
5
|
+
*
|
|
6
|
+
* @param yamlPath - The path to serve the OpenAPI YAML (e.g., '/openapi.yaml')
|
|
7
|
+
* @returns A controller class that serves the OpenAPI document as YAML
|
|
8
|
+
*/
|
|
9
|
+
export declare function createOpenApiYamlController(yamlPath: string): ClassType;
|
|
10
|
+
//# sourceMappingURL=openapi-yaml.controller.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-yaml.controller.d.mts","sourceRoot":"","sources":["../../../src/controllers/openapi-yaml.controller.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAQ3C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CA6BvE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { OpenApiBunPlugin, defineOpenApiPlugin, type BunOpenApiPluginOptions, type ScalarOptions, type ScalarTheme, } from './openapi-bun.plugin.mjs';
|
|
2
|
+
export { bunOpenApiPluginOptionsSchema, scalarOptionsSchema, scalarThemeSchema, type BunOpenApiPluginOptionsBase, } from './schemas/index.mjs';
|
|
3
|
+
export { OpenApiOptionsToken } from './tokens/index.mjs';
|
|
4
|
+
export { OpenApiDocumentService, OpenApiDocumentServiceToken, } from './services/index.mjs';
|
|
5
|
+
export { createOpenApiJsonController } from './controllers/openapi-json.controller.mjs';
|
|
6
|
+
export { createOpenApiYamlController } from './controllers/openapi-yaml.controller.mjs';
|
|
7
|
+
export { createOpenApiUiController } from './controllers/openapi-ui.controller.mjs';
|
|
8
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EACL,6BAA6B,EAC7B,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,2BAA2B,GACjC,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAGxD,OAAO,EACL,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AACvF,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { NaviosPlugin, PluginContext, PluginDefinition } from '@navios/core';
|
|
2
|
+
import type { ScalarOptions, ScalarTheme } from './schemas/index.mjs';
|
|
3
|
+
import type { BunOpenApiPluginOptions } from './tokens/openapi-options.token.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* OpenAPI plugin for Bun adapter.
|
|
6
|
+
*
|
|
7
|
+
* This plugin:
|
|
8
|
+
* - Scans all registered modules for endpoints
|
|
9
|
+
* - Generates an OpenAPI 3.1 document
|
|
10
|
+
* - Injects controllers for JSON, YAML, and Scalar UI endpoints
|
|
11
|
+
*
|
|
12
|
+
* Unlike the Fastify plugin which registers routes directly,
|
|
13
|
+
* this plugin uses the standard Navios controller pattern via
|
|
14
|
+
* ModuleLoaderService.extendModules().
|
|
15
|
+
*/
|
|
16
|
+
export declare class OpenApiBunPlugin implements NaviosPlugin<BunOpenApiPluginOptions> {
|
|
17
|
+
readonly name = "openapi-bun";
|
|
18
|
+
register(context: PluginContext, options: BunOpenApiPluginOptions): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Registers the plugin options in the DI container.
|
|
21
|
+
*/
|
|
22
|
+
private registerOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Registers and initializes the document service.
|
|
25
|
+
*/
|
|
26
|
+
private initializeDocumentService;
|
|
27
|
+
/**
|
|
28
|
+
* Creates controller classes based on options.
|
|
29
|
+
*/
|
|
30
|
+
private createControllers;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a plugin definition for the OpenAPI Bun plugin.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Plugin configuration options
|
|
36
|
+
* @returns Plugin definition to pass to `app.usePlugin()`
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { NaviosFactory } from '@navios/core'
|
|
41
|
+
* import { defineBunEnvironment } from '@navios/adapter-bun'
|
|
42
|
+
* import { defineOpenApiPlugin } from '@navios/openapi-bun'
|
|
43
|
+
*
|
|
44
|
+
* const app = await NaviosFactory.create(AppModule, {
|
|
45
|
+
* adapter: defineBunEnvironment(),
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* app.usePlugin(defineOpenApiPlugin({
|
|
49
|
+
* info: {
|
|
50
|
+
* title: 'My API',
|
|
51
|
+
* version: '1.0.0',
|
|
52
|
+
* description: 'API documentation',
|
|
53
|
+
* },
|
|
54
|
+
* servers: [
|
|
55
|
+
* { url: 'http://localhost:3000', description: 'Development' },
|
|
56
|
+
* ],
|
|
57
|
+
* scalar: {
|
|
58
|
+
* theme: 'purple',
|
|
59
|
+
* },
|
|
60
|
+
* }))
|
|
61
|
+
*
|
|
62
|
+
* await app.listen({ port: 3000 })
|
|
63
|
+
* // API docs available at http://localhost:3000/docs
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function defineOpenApiPlugin(options: BunOpenApiPluginOptions): PluginDefinition<BunOpenApiPluginOptions>;
|
|
67
|
+
export type { ScalarOptions, ScalarTheme, BunOpenApiPluginOptions };
|
|
68
|
+
//# sourceMappingURL=openapi-bun.plugin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-bun.plugin.d.mts","sourceRoot":"","sources":["../../src/openapi-bun.plugin.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EACjB,MAAM,cAAc,CAAA;AAKrB,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AASjF;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,YAAW,YAAY,CAAC,uBAAuB,CAAC;IAC5E,QAAQ,CAAC,IAAI,iBAAgB;IAEvB,QAAQ,CACZ,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAyBhB;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;YACW,yBAAyB;IAWvC;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAqB1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAAC,uBAAuB,CAAC,CAK3C;AAGD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,uBAAuB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/schemas/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for Scalar UI theme options
|
|
4
|
+
*/
|
|
5
|
+
export declare const scalarThemeSchema: z.ZodEnum<{
|
|
6
|
+
default: "default";
|
|
7
|
+
alternate: "alternate";
|
|
8
|
+
moon: "moon";
|
|
9
|
+
purple: "purple";
|
|
10
|
+
solarized: "solarized";
|
|
11
|
+
bluePlanet: "bluePlanet";
|
|
12
|
+
saturn: "saturn";
|
|
13
|
+
kepler: "kepler";
|
|
14
|
+
mars: "mars";
|
|
15
|
+
deepSpace: "deepSpace";
|
|
16
|
+
laserwave: "laserwave";
|
|
17
|
+
elysiajs: "elysiajs";
|
|
18
|
+
fastify: "fastify";
|
|
19
|
+
none: "none";
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Zod schema for Scalar UI metadata
|
|
23
|
+
*/
|
|
24
|
+
export declare const scalarMetaDataSchema: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
title: z.ZodOptional<z.ZodString>;
|
|
26
|
+
description: z.ZodOptional<z.ZodString>;
|
|
27
|
+
ogDescription: z.ZodOptional<z.ZodString>;
|
|
28
|
+
ogTitle: z.ZodOptional<z.ZodString>;
|
|
29
|
+
ogImage: z.ZodOptional<z.ZodString>;
|
|
30
|
+
twitterCard: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
/**
|
|
33
|
+
* Zod schema for Scalar UI configuration options
|
|
34
|
+
*/
|
|
35
|
+
export declare const scalarOptionsSchema: z.ZodObject<{
|
|
36
|
+
theme: z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
default: "default";
|
|
38
|
+
alternate: "alternate";
|
|
39
|
+
moon: "moon";
|
|
40
|
+
purple: "purple";
|
|
41
|
+
solarized: "solarized";
|
|
42
|
+
bluePlanet: "bluePlanet";
|
|
43
|
+
saturn: "saturn";
|
|
44
|
+
kepler: "kepler";
|
|
45
|
+
mars: "mars";
|
|
46
|
+
deepSpace: "deepSpace";
|
|
47
|
+
laserwave: "laserwave";
|
|
48
|
+
elysiajs: "elysiajs";
|
|
49
|
+
fastify: "fastify";
|
|
50
|
+
none: "none";
|
|
51
|
+
}>>;
|
|
52
|
+
favicon: z.ZodOptional<z.ZodString>;
|
|
53
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
54
|
+
hideDownloadButton: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
hideSearch: z.ZodOptional<z.ZodBoolean>;
|
|
56
|
+
customCss: z.ZodOptional<z.ZodString>;
|
|
57
|
+
metaData: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
title: z.ZodOptional<z.ZodString>;
|
|
59
|
+
description: z.ZodOptional<z.ZodString>;
|
|
60
|
+
ogDescription: z.ZodOptional<z.ZodString>;
|
|
61
|
+
ogTitle: z.ZodOptional<z.ZodString>;
|
|
62
|
+
ogImage: z.ZodOptional<z.ZodString>;
|
|
63
|
+
twitterCard: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
cdn: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
/**
|
|
68
|
+
* Zod schema for Bun OpenAPI plugin options
|
|
69
|
+
*/
|
|
70
|
+
export declare const bunOpenApiPluginOptionsSchema: z.ZodObject<{
|
|
71
|
+
jsonPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
72
|
+
yamlPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
73
|
+
docsPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
74
|
+
scalar: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
theme: z.ZodOptional<z.ZodEnum<{
|
|
76
|
+
default: "default";
|
|
77
|
+
alternate: "alternate";
|
|
78
|
+
moon: "moon";
|
|
79
|
+
purple: "purple";
|
|
80
|
+
solarized: "solarized";
|
|
81
|
+
bluePlanet: "bluePlanet";
|
|
82
|
+
saturn: "saturn";
|
|
83
|
+
kepler: "kepler";
|
|
84
|
+
mars: "mars";
|
|
85
|
+
deepSpace: "deepSpace";
|
|
86
|
+
laserwave: "laserwave";
|
|
87
|
+
elysiajs: "elysiajs";
|
|
88
|
+
fastify: "fastify";
|
|
89
|
+
none: "none";
|
|
90
|
+
}>>;
|
|
91
|
+
favicon: z.ZodOptional<z.ZodString>;
|
|
92
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
93
|
+
hideDownloadButton: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
hideSearch: z.ZodOptional<z.ZodBoolean>;
|
|
95
|
+
customCss: z.ZodOptional<z.ZodString>;
|
|
96
|
+
metaData: z.ZodOptional<z.ZodObject<{
|
|
97
|
+
title: z.ZodOptional<z.ZodString>;
|
|
98
|
+
description: z.ZodOptional<z.ZodString>;
|
|
99
|
+
ogDescription: z.ZodOptional<z.ZodString>;
|
|
100
|
+
ogTitle: z.ZodOptional<z.ZodString>;
|
|
101
|
+
ogImage: z.ZodOptional<z.ZodString>;
|
|
102
|
+
twitterCard: z.ZodOptional<z.ZodString>;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
cdn: z.ZodOptional<z.ZodString>;
|
|
105
|
+
}, z.core.$strip>>;
|
|
106
|
+
disableJson: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
107
|
+
disableScalar: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
108
|
+
disableYaml: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
export type ScalarTheme = z.infer<typeof scalarThemeSchema>;
|
|
111
|
+
export type ScalarMetaData = z.infer<typeof scalarMetaDataSchema>;
|
|
112
|
+
export type ScalarOptions = z.infer<typeof scalarOptionsSchema>;
|
|
113
|
+
export type BunOpenApiPluginOptionsBase = z.infer<typeof bunOpenApiPluginOptionsSchema>;
|
|
114
|
+
//# sourceMappingURL=openapi-bun-options.schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-bun-options.schema.d.mts","sourceRoot":"","sources":["../../../src/schemas/openapi-bun-options.schema.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;EAe5B,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;kBASpB,CAAA;AAEb;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4C9B,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCxC,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAC3D,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AACjE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAC/D,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/services/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ModuleMetadata } from '@navios/core';
|
|
2
|
+
import type { oas31 } from 'zod-openapi';
|
|
3
|
+
import { InjectionToken } from '@navios/core';
|
|
4
|
+
type OpenAPIObject = oas31.OpenAPIObject;
|
|
5
|
+
/**
|
|
6
|
+
* Injection token for the document service
|
|
7
|
+
*/
|
|
8
|
+
export declare const OpenApiDocumentServiceToken: InjectionToken<OpenApiDocumentService, undefined, false>;
|
|
9
|
+
/**
|
|
10
|
+
* Service that generates and caches the OpenAPI document.
|
|
11
|
+
*
|
|
12
|
+
* The document is generated once during plugin initialization
|
|
13
|
+
* and served by controllers.
|
|
14
|
+
*/
|
|
15
|
+
export declare class OpenApiDocumentService {
|
|
16
|
+
private options;
|
|
17
|
+
private generator;
|
|
18
|
+
private document;
|
|
19
|
+
private yamlDocument;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the document service by generating the OpenAPI document.
|
|
22
|
+
* Called by the plugin during registration.
|
|
23
|
+
*
|
|
24
|
+
* @param modules - All loaded modules with their metadata
|
|
25
|
+
* @param globalPrefix - Global route prefix (e.g., '/api/v1')
|
|
26
|
+
*/
|
|
27
|
+
initialize(modules: Map<string, ModuleMetadata>, globalPrefix: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the OpenAPI document as JSON-serializable object.
|
|
30
|
+
*/
|
|
31
|
+
getDocument(): OpenAPIObject;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the OpenAPI document as YAML string.
|
|
34
|
+
*/
|
|
35
|
+
getYamlDocument(): string;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=openapi-document.service.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-document.service.d.mts","sourceRoot":"","sources":["../../../src/services/openapi-document.service.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAsB,cAAc,EAAE,MAAM,cAAc,CAAA;AAOjE,KAAK,aAAa,GAAG,KAAK,CAAC,aAAa,CAAA;AAExC;;GAEG;AACH,eAAO,MAAM,2BAA2B,0DAGrC,CAAA;AAEH;;;;;GAKG;AACH,qBAGa,sBAAsB;IACjC,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,SAAS,CAAkC;IAEnD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,YAAY,CAAsB;IAE1C;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAgB5E;;OAEG;IACH,WAAW,IAAI,aAAa;IAS5B;;OAEG;IACH,eAAe,IAAI,MAAM;CAQ1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/tokens/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,6BAA6B,CAAA"}
|