@cinnabun/openapi 0.0.1 → 0.0.7

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/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @cinnabun/openapi
2
+
3
+ Auto-generate OpenAPI 3.1 specs and Swagger UI for Cinnabun applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @cinnabun/openapi
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { CinnabunApp, CinnabunFactory } from "@cinnabun/core";
15
+ import { OpenApiModule } from "@cinnabun/openapi";
16
+
17
+ @CinnabunApp({
18
+ port: 3000,
19
+ scanPaths: [],
20
+ imports: [
21
+ OpenApiModule.forRoot({
22
+ title: "My API",
23
+ version: "1.0.0",
24
+ docsPath: "/api-docs",
25
+ jsonPath: "/api-docs/json",
26
+ }),
27
+ ],
28
+ })
29
+ class App {}
30
+
31
+ CinnabunFactory.run(App);
32
+ ```
33
+
34
+ Access Swagger UI at `http://localhost:3000/api-docs` and the JSON spec at `http://localhost:3000/api-docs/json`.
35
+
36
+ ## Decorators
37
+
38
+ Annotate controllers and DTOs for richer documentation:
39
+
40
+ ```typescript
41
+ import { RestController, GetMapping, PostMapping, Body } from "@cinnabun/core";
42
+ import { ApiTags, ApiOperation, ApiResponse, ApiProperty } from "@cinnabun/openapi";
43
+
44
+ @ApiTags("Users")
45
+ @RestController("/api/users")
46
+ class UserController {
47
+ @GetMapping("/")
48
+ @ApiOperation({ summary: "List all users" })
49
+ @ApiResponse({ status: 200, description: "User list" })
50
+ findAll() {
51
+ return [];
52
+ }
53
+
54
+ @PostMapping("/")
55
+ @ApiOperation({ summary: "Create user" })
56
+ @ApiResponse({ status: 201, description: "Created" })
57
+ create(@Body() body: CreateUserDto) {
58
+ return body;
59
+ }
60
+ }
61
+
62
+ class CreateUserDto {
63
+ @ApiProperty()
64
+ name!: string;
65
+
66
+ @ApiProperty()
67
+ email!: string;
68
+ }
69
+ ```
70
+
71
+ ## Configuration
72
+
73
+ ```typescript
74
+ interface OpenApiModuleOptions {
75
+ title?: string;
76
+ version?: string;
77
+ description?: string;
78
+ docsPath?: string; // default: "/api-docs"
79
+ jsonPath?: string; // default: "/api-docs/json"
80
+ }
81
+ ```
82
+
83
+ ## License
84
+
85
+ MIT
@@ -1,6 +1,7 @@
1
+ import { type Constructor } from "@cinnabun/core";
1
2
  import type { OpenApiModuleOptions } from "./interfaces/openapi-options.js";
2
3
  export declare class OpenApiModule {
3
- static forRoot(options: OpenApiModuleOptions): Function;
4
+ static forRoot(options: OpenApiModuleOptions): Constructor;
4
5
  static getOptions(): OpenApiModuleOptions;
5
6
  static resetCache(): void;
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cinnabun/openapi",
3
- "version": "0.0.1",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { Module, RestController, GetMapping } from "@cinnabun/core";
1
+ import { Module, RestController, GetMapping, type Constructor } from "@cinnabun/core";
2
2
  import type { OpenApiModuleOptions } from "./interfaces/openapi-options.js";
3
3
  import { scanRoutes } from "./generator/route-scanner.js";
4
4
  import { generateSpec, type OpenApiSpec } from "./generator/openapi-generator.js";
@@ -7,7 +7,7 @@ let moduleOptions: OpenApiModuleOptions | null = null;
7
7
  let cachedSpec: OpenApiSpec | null = null;
8
8
 
9
9
  export class OpenApiModule {
10
- static forRoot(options: OpenApiModuleOptions): Function {
10
+ static forRoot(options: OpenApiModuleOptions): Constructor {
11
11
  moduleOptions = options;
12
12
  cachedSpec = null;
13
13