@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.
Files changed (60) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +8 -0
  3. package/README.md +286 -0
  4. package/dist/src/controllers/index.d.mts +4 -0
  5. package/dist/src/controllers/index.d.mts.map +1 -0
  6. package/dist/src/controllers/openapi-json.controller.d.mts +10 -0
  7. package/dist/src/controllers/openapi-json.controller.d.mts.map +1 -0
  8. package/dist/src/controllers/openapi-ui.controller.d.mts +10 -0
  9. package/dist/src/controllers/openapi-ui.controller.d.mts.map +1 -0
  10. package/dist/src/controllers/openapi-yaml.controller.d.mts +10 -0
  11. package/dist/src/controllers/openapi-yaml.controller.d.mts.map +1 -0
  12. package/dist/src/index.d.mts +8 -0
  13. package/dist/src/index.d.mts.map +1 -0
  14. package/dist/src/openapi-bun.plugin.d.mts +68 -0
  15. package/dist/src/openapi-bun.plugin.d.mts.map +1 -0
  16. package/dist/src/schemas/index.d.mts +2 -0
  17. package/dist/src/schemas/index.d.mts.map +1 -0
  18. package/dist/src/schemas/openapi-bun-options.schema.d.mts +114 -0
  19. package/dist/src/schemas/openapi-bun-options.schema.d.mts.map +1 -0
  20. package/dist/src/services/index.d.mts +2 -0
  21. package/dist/src/services/index.d.mts.map +1 -0
  22. package/dist/src/services/openapi-document.service.d.mts +38 -0
  23. package/dist/src/services/openapi-document.service.d.mts.map +1 -0
  24. package/dist/src/tokens/index.d.mts +2 -0
  25. package/dist/src/tokens/index.d.mts.map +1 -0
  26. package/dist/src/tokens/openapi-options.token.d.mts +25 -0
  27. package/dist/src/tokens/openapi-options.token.d.mts.map +1 -0
  28. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  29. package/dist/tsconfig.tsbuildinfo +1 -0
  30. package/dist/tsdown.config.d.mts +3 -0
  31. package/dist/tsdown.config.d.mts.map +1 -0
  32. package/dist/vitest.config.d.mts +3 -0
  33. package/dist/vitest.config.d.mts.map +1 -0
  34. package/lib/index.cjs +4326 -0
  35. package/lib/index.cjs.map +1 -0
  36. package/lib/index.d.cts +262 -0
  37. package/lib/index.d.cts.map +1 -0
  38. package/lib/index.d.mts +262 -0
  39. package/lib/index.d.mts.map +1 -0
  40. package/lib/index.mjs +4311 -0
  41. package/lib/index.mjs.map +1 -0
  42. package/package.json +48 -0
  43. package/project.json +66 -0
  44. package/src/controllers/index.mts +3 -0
  45. package/src/controllers/openapi-json.controller.mts +51 -0
  46. package/src/controllers/openapi-ui.controller.mts +72 -0
  47. package/src/controllers/openapi-yaml.controller.mts +46 -0
  48. package/src/index.mts +30 -0
  49. package/src/openapi-bun.plugin.mts +167 -0
  50. package/src/schemas/index.mts +10 -0
  51. package/src/schemas/openapi-bun-options.schema.mts +135 -0
  52. package/src/services/index.mts +4 -0
  53. package/src/services/openapi-document.service.mts +83 -0
  54. package/src/tokens/index.mts +1 -0
  55. package/src/tokens/openapi-options.token.mts +31 -0
  56. package/tsconfig.json +15 -0
  57. package/tsconfig.lib.json +8 -0
  58. package/tsconfig.spec.json +8 -0
  59. package/tsdown.config.mts +41 -0
  60. 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,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist"
5
+ },
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/**/*.spec.mts", "src/**/*.spec-d.mts"]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "types": ["vitest/globals"]
6
+ },
7
+ "include": ["src/**/*.spec.mts", "src/**/*.spec-d.mts"]
8
+ }
@@ -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
+ })
@@ -0,0 +1,11 @@
1
+ import { defineProject } from 'vitest/config'
2
+
3
+ export default defineProject({
4
+ test: {
5
+ typecheck: {
6
+ enabled: true,
7
+ tsconfig: './tsconfig.lib.json',
8
+ },
9
+ include: ['src/**/*.spec.mts', 'src/**/*.spec-d.mts'],
10
+ },
11
+ })