@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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { ModuleMetadata } from '@navios/core'
|
|
2
|
+
import type { oas31 } from 'zod-openapi'
|
|
3
|
+
|
|
4
|
+
import { inject, Injectable, InjectionToken } from '@navios/core'
|
|
5
|
+
import { OpenApiGeneratorService } from '@navios/openapi'
|
|
6
|
+
|
|
7
|
+
import { stringify as yamlStringify } from 'yaml'
|
|
8
|
+
|
|
9
|
+
import { OpenApiOptionsToken } from '../tokens/openapi-options.token.mjs'
|
|
10
|
+
|
|
11
|
+
type OpenAPIObject = oas31.OpenAPIObject
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Injection token for the document service
|
|
15
|
+
*/
|
|
16
|
+
export const OpenApiDocumentServiceToken =
|
|
17
|
+
InjectionToken.create<OpenApiDocumentService>(
|
|
18
|
+
Symbol.for('OpenApiDocumentService'),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Service that generates and caches the OpenAPI document.
|
|
23
|
+
*
|
|
24
|
+
* The document is generated once during plugin initialization
|
|
25
|
+
* and served by controllers.
|
|
26
|
+
*/
|
|
27
|
+
@Injectable({
|
|
28
|
+
token: OpenApiDocumentServiceToken,
|
|
29
|
+
})
|
|
30
|
+
export class OpenApiDocumentService {
|
|
31
|
+
private options = inject(OpenApiOptionsToken)
|
|
32
|
+
private generator = inject(OpenApiGeneratorService)
|
|
33
|
+
|
|
34
|
+
private document: OpenAPIObject | null = null
|
|
35
|
+
private yamlDocument: string | null = null
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Initializes the document service by generating the OpenAPI document.
|
|
39
|
+
* Called by the plugin during registration.
|
|
40
|
+
*
|
|
41
|
+
* @param modules - All loaded modules with their metadata
|
|
42
|
+
* @param globalPrefix - Global route prefix (e.g., '/api/v1')
|
|
43
|
+
*/
|
|
44
|
+
initialize(modules: Map<string, ModuleMetadata>, globalPrefix: string): void {
|
|
45
|
+
// Generate document
|
|
46
|
+
this.document = this.generator.generate(modules, this.options)
|
|
47
|
+
|
|
48
|
+
// Apply global prefix to servers if not already set
|
|
49
|
+
if (
|
|
50
|
+
globalPrefix &&
|
|
51
|
+
(!this.document.servers || this.document.servers.length === 0)
|
|
52
|
+
) {
|
|
53
|
+
this.document.servers = [{ url: globalPrefix }]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Pre-generate YAML
|
|
57
|
+
this.yamlDocument = yamlStringify(this.document)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the OpenAPI document as JSON-serializable object.
|
|
62
|
+
*/
|
|
63
|
+
getDocument(): OpenAPIObject {
|
|
64
|
+
if (!this.document) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
'OpenApiDocumentService not initialized. Call initialize() first.',
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
return this.document
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns the OpenAPI document as YAML string.
|
|
74
|
+
*/
|
|
75
|
+
getYamlDocument(): string {
|
|
76
|
+
if (!this.yamlDocument) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'OpenApiDocumentService not initialized. Call initialize() first.',
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
return this.yamlDocument
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OpenApiOptionsToken, type BunOpenApiPluginOptions } from './openapi-options.token.mjs'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OpenApiGeneratorOptions } from '@navios/openapi'
|
|
2
|
+
|
|
3
|
+
import { InjectionToken } from '@navios/core'
|
|
4
|
+
|
|
5
|
+
import type { BunOpenApiPluginOptionsBase } from '../schemas/index.mjs'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Combined options for the Bun OpenAPI plugin.
|
|
9
|
+
* Extends OpenApiGeneratorOptions with Bun-specific settings.
|
|
10
|
+
*/
|
|
11
|
+
export interface BunOpenApiPluginOptions
|
|
12
|
+
extends OpenApiGeneratorOptions, Partial<BunOpenApiPluginOptionsBase> {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Injection token for OpenAPI plugin options.
|
|
16
|
+
*
|
|
17
|
+
* Controllers inject this to access the plugin configuration
|
|
18
|
+
* (paths, Scalar theme, info, etc.)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @Injectable()
|
|
23
|
+
* class OpenApiJsonController {
|
|
24
|
+
* private options = inject(OpenApiOptionsToken)
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const OpenApiOptionsToken =
|
|
29
|
+
InjectionToken.create<BunOpenApiPluginOptions>(
|
|
30
|
+
Symbol.for('BunOpenApiPluginOptions'),
|
|
31
|
+
)
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "Node18",
|
|
5
|
+
"outDir": "dist"
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{ "path": "./tsconfig.lib.json" },
|
|
9
|
+
{ "path": "../core" },
|
|
10
|
+
{ "path": "../di" },
|
|
11
|
+
{ "path": "../openapi" },
|
|
12
|
+
{ "path": "../adapter-bun" },
|
|
13
|
+
{ "path": "../builder" }
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { withFilter } from 'rolldown/filter'
|
|
2
|
+
import { defineConfig } from 'tsdown'
|
|
3
|
+
import swc from 'unplugin-swc'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
entry: ['src/index.mts'],
|
|
7
|
+
outDir: 'lib',
|
|
8
|
+
format: ['esm', 'cjs'],
|
|
9
|
+
clean: true,
|
|
10
|
+
tsconfig: 'tsconfig.lib.json',
|
|
11
|
+
treeshake: true,
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
platform: 'node',
|
|
14
|
+
external: [
|
|
15
|
+
'@navios/core',
|
|
16
|
+
'@navios/openapi',
|
|
17
|
+
'@navios/adapter-bun',
|
|
18
|
+
'@navios/builder',
|
|
19
|
+
'zod',
|
|
20
|
+
],
|
|
21
|
+
dts: true,
|
|
22
|
+
target: 'es2022',
|
|
23
|
+
plugins: [
|
|
24
|
+
withFilter(
|
|
25
|
+
swc.rolldown({
|
|
26
|
+
jsc: {
|
|
27
|
+
target: 'es2022',
|
|
28
|
+
parser: {
|
|
29
|
+
syntax: 'typescript',
|
|
30
|
+
decorators: true,
|
|
31
|
+
},
|
|
32
|
+
transform: {
|
|
33
|
+
decoratorVersion: '2022-03',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
// Only run this transform if the file contains a decorator.
|
|
38
|
+
{ transform: { code: '@' } },
|
|
39
|
+
),
|
|
40
|
+
],
|
|
41
|
+
})
|