swallowkit 0.4.0-beta.3 → 1.0.0-beta.10

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 (111) hide show
  1. package/LICENSE +21 -21
  2. package/README.ja.md +254 -183
  3. package/README.md +311 -184
  4. package/dist/__tests__/fixtures.d.ts +14 -0
  5. package/dist/__tests__/fixtures.d.ts.map +1 -0
  6. package/dist/__tests__/fixtures.js +85 -0
  7. package/dist/__tests__/fixtures.js.map +1 -0
  8. package/dist/cli/commands/create-model.d.ts.map +1 -1
  9. package/dist/cli/commands/create-model.js +16 -15
  10. package/dist/cli/commands/create-model.js.map +1 -1
  11. package/dist/cli/commands/dev-seeds.d.ts +35 -0
  12. package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
  13. package/dist/cli/commands/dev-seeds.js +292 -0
  14. package/dist/cli/commands/dev-seeds.js.map +1 -0
  15. package/dist/cli/commands/dev.d.ts +8 -0
  16. package/dist/cli/commands/dev.d.ts.map +1 -1
  17. package/dist/cli/commands/dev.js +308 -87
  18. package/dist/cli/commands/dev.js.map +1 -1
  19. package/dist/cli/commands/index.d.ts +1 -0
  20. package/dist/cli/commands/index.d.ts.map +1 -1
  21. package/dist/cli/commands/index.js +3 -1
  22. package/dist/cli/commands/index.js.map +1 -1
  23. package/dist/cli/commands/init.d.ts +13 -0
  24. package/dist/cli/commands/init.d.ts.map +1 -1
  25. package/dist/cli/commands/init.js +2639 -1708
  26. package/dist/cli/commands/init.js.map +1 -1
  27. package/dist/cli/commands/scaffold.d.ts +3 -0
  28. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  29. package/dist/cli/commands/scaffold.js +283 -118
  30. package/dist/cli/commands/scaffold.js.map +1 -1
  31. package/dist/cli/index.js +17 -1
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/core/config.d.ts +2 -1
  34. package/dist/core/config.d.ts.map +1 -1
  35. package/dist/core/config.js +31 -1
  36. package/dist/core/config.js.map +1 -1
  37. package/dist/core/scaffold/functions-generator.d.ts +5 -0
  38. package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
  39. package/dist/core/scaffold/functions-generator.js +649 -211
  40. package/dist/core/scaffold/functions-generator.js.map +1 -1
  41. package/dist/core/scaffold/model-parser.d.ts +1 -1
  42. package/dist/core/scaffold/model-parser.d.ts.map +1 -1
  43. package/dist/core/scaffold/model-parser.js +105 -101
  44. package/dist/core/scaffold/model-parser.js.map +1 -1
  45. package/dist/core/scaffold/nextjs-generator.js +181 -181
  46. package/dist/core/scaffold/openapi-generator.d.ts +3 -0
  47. package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
  48. package/dist/core/scaffold/openapi-generator.js +190 -0
  49. package/dist/core/scaffold/openapi-generator.js.map +1 -0
  50. package/dist/core/scaffold/ui-generator.js +656 -656
  51. package/dist/database/base-model.d.ts +3 -3
  52. package/dist/database/base-model.js +3 -3
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +2 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/types/index.d.ts +4 -0
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/utils/package-manager.d.ts +109 -0
  60. package/dist/utils/package-manager.d.ts.map +1 -0
  61. package/dist/utils/package-manager.js +215 -0
  62. package/dist/utils/package-manager.js.map +1 -0
  63. package/package.json +81 -73
  64. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +445 -0
  65. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
  66. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +524 -0
  67. package/src/__tests__/config.test.ts +122 -0
  68. package/src/__tests__/dev-seeds.test.ts +112 -0
  69. package/src/__tests__/dev.test.ts +42 -0
  70. package/src/__tests__/fixtures.ts +83 -0
  71. package/src/__tests__/functions-generator.test.ts +101 -0
  72. package/src/__tests__/init.test.ts +80 -0
  73. package/src/__tests__/nextjs-generator.test.ts +97 -0
  74. package/src/__tests__/openapi-generator.test.ts +43 -0
  75. package/src/__tests__/package-manager.test.ts +189 -0
  76. package/src/__tests__/scaffold.test.ts +39 -0
  77. package/src/__tests__/string-utils.test.ts +75 -0
  78. package/src/__tests__/ui-generator.test.ts +144 -0
  79. package/src/cli/commands/create-model.ts +141 -0
  80. package/src/cli/commands/dev-seeds.ts +358 -0
  81. package/src/cli/commands/dev.ts +805 -0
  82. package/src/cli/commands/index.ts +9 -0
  83. package/src/cli/commands/init.ts +3370 -0
  84. package/src/cli/commands/provision.ts +193 -0
  85. package/src/cli/commands/scaffold.ts +786 -0
  86. package/src/cli/index.ts +74 -0
  87. package/src/core/config.ts +244 -0
  88. package/src/core/scaffold/functions-generator.ts +674 -0
  89. package/src/core/scaffold/model-parser.ts +627 -0
  90. package/src/core/scaffold/nextjs-generator.ts +217 -0
  91. package/src/core/scaffold/openapi-generator.ts +212 -0
  92. package/src/core/scaffold/ui-generator.ts +945 -0
  93. package/src/database/base-model.ts +184 -0
  94. package/src/database/client.ts +140 -0
  95. package/src/database/repository.ts +104 -0
  96. package/src/database/runtime-check.ts +25 -0
  97. package/src/index.ts +27 -0
  98. package/src/types/index.ts +45 -0
  99. package/src/utils/package-manager.ts +229 -0
  100. package/dist/cli/commands/build.d.ts +0 -6
  101. package/dist/cli/commands/build.d.ts.map +0 -1
  102. package/dist/cli/commands/build.js +0 -177
  103. package/dist/cli/commands/build.js.map +0 -1
  104. package/dist/cli/commands/deploy.d.ts +0 -3
  105. package/dist/cli/commands/deploy.d.ts.map +0 -1
  106. package/dist/cli/commands/deploy.js +0 -147
  107. package/dist/cli/commands/deploy.js.map +0 -1
  108. package/dist/cli/commands/setup.d.ts +0 -6
  109. package/dist/cli/commands/setup.d.ts.map +0 -1
  110. package/dist/cli/commands/setup.js +0 -254
  111. package/dist/cli/commands/setup.js.map +0 -1
@@ -12,113 +12,113 @@ const model_parser_1 = require("./model-parser");
12
12
  * BFF callFunction ヘルパー (lib/api/call-function.ts) のコードを生成
13
13
  */
14
14
  function generateBFFCallFunction() {
15
- return `import { NextRequest, NextResponse } from 'next/server';
16
- import { z } from 'zod/v4';
17
-
18
- /**
19
- * SwallowKit BFF Call Function Helper
20
- * Azure Functions を呼び出す汎用ヘルパー
21
- *
22
- * @example
23
- * // シンプルな GET
24
- * return callFunction({ method: 'GET', path: '/api/todo', responseSchema: z.array(TodoSchema) });
25
- *
26
- * // バリデーション付き POST
27
- * return callFunction({ method: 'POST', path: '/api/todo', body, inputSchema: InputSchema, responseSchema: TodoSchema, successStatus: 201 });
28
- *
29
- * // カスタムビジネスロジック関数の呼び出し
30
- * return callFunction({ method: 'POST', path: '/api/todo/archive', body: { ids } });
31
- */
32
-
33
- function getFunctionsBaseUrl(): string {
34
- return process.env.BACKEND_FUNCTIONS_BASE_URL || 'http://localhost:7071';
35
- }
36
-
37
- interface CallFunctionConfig<TInput = any, TOutput = any> {
38
- /** HTTP メソッド */
39
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
40
- /** Azure Functions のパス (例: '/api/todo', '/api/todo/123') */
41
- path: string;
42
- /** リクエストボディ (POST/PUT 用) */
43
- body?: any;
44
- /** 入力バリデーション用 Zod スキーマ (省略時はバリデーションなし) */
45
- inputSchema?: z.ZodSchema<TInput>;
46
- /** 出力バリデーション用 Zod スキーマ (省略時はそのまま返す) */
47
- responseSchema?: z.ZodSchema<TOutput>;
48
- /** 成功時の HTTP ステータスコード (デフォルト: 200) */
49
- successStatus?: number;
50
- }
51
-
52
- export async function callFunction<TInput = any, TOutput = any>(
53
- config: CallFunctionConfig<TInput, TOutput>
54
- ): Promise<NextResponse> {
55
- const { method, path, body, inputSchema, responseSchema, successStatus = 200 } = config;
56
-
57
- try {
58
- // 入力バリデーション
59
- let validatedBody = body;
60
- if (inputSchema && body !== undefined) {
61
- const result = inputSchema.safeParse(body);
62
- if (!result.success) {
63
- console.error('[BFF] Validation failed:', result.error.issues);
64
- return NextResponse.json(
65
- { error: 'Validation failed', details: result.error.issues },
66
- { status: 400 }
67
- );
68
- }
69
- validatedBody = result.data;
70
- }
71
-
72
- // Azure Functions を呼び出し
73
- const functionsBaseUrl = getFunctionsBaseUrl();
74
- const url = functionsBaseUrl + path;
75
- console.log(\`[BFF] \${method} \${url}\`);
76
-
77
- const response = await fetch(url, {
78
- method,
79
- headers: { 'Content-Type': 'application/json' },
80
- body: validatedBody !== undefined ? JSON.stringify(validatedBody) : undefined,
81
- });
82
-
83
- console.log('[BFF] Functions response status:', response.status);
84
-
85
- // エラーレスポンスの転送
86
- if (!response.ok) {
87
- const text = await response.text();
88
- console.error('[BFF] Functions error:', { status: response.status, body: text });
89
-
90
- let errorMessage = 'Request failed';
91
- try {
92
- const error = JSON.parse(text);
93
- errorMessage = error.error || errorMessage;
94
- } catch {
95
- errorMessage = text || errorMessage;
96
- }
97
- return NextResponse.json({ error: errorMessage }, { status: response.status });
98
- }
99
-
100
- // DELETE 204 の場合はボディなし
101
- if (response.status === 204 || method === 'DELETE') {
102
- return new NextResponse(null, { status: 204 });
103
- }
104
-
105
- // レスポンスの取得と出力バリデーション
106
- const data = await response.json();
107
-
108
- if (responseSchema) {
109
- const validated = responseSchema.parse(data);
110
- return NextResponse.json(validated, { status: successStatus });
111
- }
112
-
113
- return NextResponse.json(data, { status: successStatus });
114
- } catch (error: any) {
115
- console.error(\`[BFF] Error:\`, error);
116
- return NextResponse.json(
117
- { error: error.message || 'Internal server error' },
118
- { status: 500 }
119
- );
120
- }
121
- }
15
+ return `import { NextRequest, NextResponse } from 'next/server';
16
+ import { z } from 'zod/v4';
17
+
18
+ /**
19
+ * SwallowKit BFF Call Function Helper
20
+ * Azure Functions を呼び出す汎用ヘルパー
21
+ *
22
+ * @example
23
+ * // シンプルな GET
24
+ * return callFunction({ method: 'GET', path: '/api/todo', responseSchema: z.array(TodoSchema) });
25
+ *
26
+ * // バリデーション付き POST
27
+ * return callFunction({ method: 'POST', path: '/api/todo', body, inputSchema: InputSchema, responseSchema: TodoSchema, successStatus: 201 });
28
+ *
29
+ * // カスタムビジネスロジック関数の呼び出し
30
+ * return callFunction({ method: 'POST', path: '/api/todo/archive', body: { ids } });
31
+ */
32
+
33
+ function getFunctionsBaseUrl(): string {
34
+ return process.env.BACKEND_FUNCTIONS_BASE_URL || process.env.FUNCTIONS_BASE_URL || 'http://localhost:7071';
35
+ }
36
+
37
+ interface CallFunctionConfig<TInput = any, TOutput = any> {
38
+ /** HTTP メソッド */
39
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
40
+ /** Azure Functions のパス (例: '/api/todo', '/api/todo/123') */
41
+ path: string;
42
+ /** リクエストボディ (POST/PUT 用) */
43
+ body?: any;
44
+ /** 入力バリデーション用 Zod スキーマ (省略時はバリデーションなし) */
45
+ inputSchema?: z.ZodSchema<TInput>;
46
+ /** 出力バリデーション用 Zod スキーマ (省略時はそのまま返す) */
47
+ responseSchema?: z.ZodSchema<TOutput>;
48
+ /** 成功時の HTTP ステータスコード (デフォルト: 200) */
49
+ successStatus?: number;
50
+ }
51
+
52
+ export async function callFunction<TInput = any, TOutput = any>(
53
+ config: CallFunctionConfig<TInput, TOutput>
54
+ ): Promise<NextResponse> {
55
+ const { method, path, body, inputSchema, responseSchema, successStatus = 200 } = config;
56
+
57
+ try {
58
+ // 入力バリデーション
59
+ let validatedBody = body;
60
+ if (inputSchema && body !== undefined) {
61
+ const result = inputSchema.safeParse(body);
62
+ if (!result.success) {
63
+ console.error('[BFF] Validation failed:', result.error.issues);
64
+ return NextResponse.json(
65
+ { error: 'Validation failed', details: result.error.issues },
66
+ { status: 400 }
67
+ );
68
+ }
69
+ validatedBody = result.data;
70
+ }
71
+
72
+ // Azure Functions を呼び出し
73
+ const functionsBaseUrl = getFunctionsBaseUrl();
74
+ const url = functionsBaseUrl + path;
75
+ console.log(\`[BFF] \${method} \${url}\`);
76
+
77
+ const response = await fetch(url, {
78
+ method,
79
+ headers: { 'Content-Type': 'application/json' },
80
+ body: validatedBody !== undefined ? JSON.stringify(validatedBody) : undefined,
81
+ });
82
+
83
+ console.log('[BFF] Functions response status:', response.status);
84
+
85
+ // エラーレスポンスの転送
86
+ if (!response.ok) {
87
+ const text = await response.text();
88
+ console.error('[BFF] Functions error:', { status: response.status, body: text });
89
+
90
+ let errorMessage = 'Request failed';
91
+ try {
92
+ const error = JSON.parse(text);
93
+ errorMessage = error.error || errorMessage;
94
+ } catch {
95
+ errorMessage = text || errorMessage;
96
+ }
97
+ return NextResponse.json({ error: errorMessage }, { status: response.status });
98
+ }
99
+
100
+ // DELETE 204 の場合はボディなし
101
+ if (response.status === 204 || method === 'DELETE') {
102
+ return new NextResponse(null, { status: 204 });
103
+ }
104
+
105
+ // レスポンスの取得と出力バリデーション
106
+ const data = await response.json();
107
+
108
+ if (responseSchema) {
109
+ const validated = responseSchema.parse(data);
110
+ return NextResponse.json(validated, { status: successStatus });
111
+ }
112
+
113
+ return NextResponse.json(data, { status: successStatus });
114
+ } catch (error: any) {
115
+ console.error(\`[BFF] Error:\`, error);
116
+ return NextResponse.json(
117
+ { error: error.message || 'Internal server error' },
118
+ { status: 500 }
119
+ );
120
+ }
121
+ }
122
122
  `;
123
123
  }
124
124
  /**
@@ -129,81 +129,81 @@ function generateCompactBFFRoutes(model, sharedPackageName) {
129
129
  const modelCamel = (0, model_parser_1.toCamelCase)(modelName);
130
130
  const modelKebab = (0, model_parser_1.toKebabCase)(modelName);
131
131
  const schemaName = model.schemaName;
132
- const listRoute = `import { NextRequest } from 'next/server';
133
- import { callFunction } from '@/lib/api/call-function';
134
- import { ${schemaName} } from '${sharedPackageName}';
135
- import { z } from 'zod/v4';
136
-
137
- const InputSchema = ${schemaName}.omit({ id: true, createdAt: true, updatedAt: true });
138
-
139
- // GET /api/${modelCamel} - 一覧取得
140
- export async function GET() {
141
- return callFunction({
142
- method: 'GET',
143
- path: '/api/${modelCamel}',
144
- responseSchema: z.array(${schemaName}),
145
- });
146
- }
147
-
148
- // POST /api/${modelCamel} - 新規作成
149
- export async function POST(request: NextRequest) {
150
- const body = await request.json();
151
- return callFunction({
152
- method: 'POST',
153
- path: '/api/${modelCamel}',
154
- body,
155
- inputSchema: InputSchema,
156
- responseSchema: ${schemaName},
157
- successStatus: 201,
158
- });
159
- }
132
+ const listRoute = `import { NextRequest } from 'next/server';
133
+ import { callFunction } from '@/lib/api/call-function';
134
+ import { ${schemaName} } from '${sharedPackageName}';
135
+ import { z } from 'zod/v4';
136
+
137
+ const InputSchema = ${schemaName}.omit({ id: true, createdAt: true, updatedAt: true });
138
+
139
+ // GET /api/${modelCamel} - 一覧取得
140
+ export async function GET() {
141
+ return callFunction({
142
+ method: 'GET',
143
+ path: '/api/${modelCamel}',
144
+ responseSchema: z.array(${schemaName}),
145
+ });
146
+ }
147
+
148
+ // POST /api/${modelCamel} - 新規作成
149
+ export async function POST(request: NextRequest) {
150
+ const body = await request.json();
151
+ return callFunction({
152
+ method: 'POST',
153
+ path: '/api/${modelCamel}',
154
+ body,
155
+ inputSchema: InputSchema,
156
+ responseSchema: ${schemaName},
157
+ successStatus: 201,
158
+ });
159
+ }
160
160
  `;
161
- const detailRoute = `import { NextRequest } from 'next/server';
162
- import { callFunction } from '@/lib/api/call-function';
163
- import { ${schemaName} } from '${sharedPackageName}';
164
-
165
- const InputSchema = ${schemaName}.omit({ id: true, createdAt: true, updatedAt: true });
166
-
167
- // GET /api/${modelCamel}/{id} - 詳細取得
168
- export async function GET(
169
- _request: NextRequest,
170
- { params }: { params: Promise<{ id: string }> }
171
- ) {
172
- const { id } = await params;
173
- return callFunction({
174
- method: 'GET',
175
- path: \`/api/${modelCamel}/\${id}\`,
176
- responseSchema: ${schemaName},
177
- });
178
- }
179
-
180
- // PUT /api/${modelCamel}/{id} - 更新
181
- export async function PUT(
182
- request: NextRequest,
183
- { params }: { params: Promise<{ id: string }> }
184
- ) {
185
- const { id } = await params;
186
- const body = await request.json();
187
- return callFunction({
188
- method: 'PUT',
189
- path: \`/api/${modelCamel}/\${id}\`,
190
- body,
191
- inputSchema: InputSchema,
192
- responseSchema: ${schemaName},
193
- });
194
- }
195
-
196
- // DELETE /api/${modelCamel}/{id} - 削除
197
- export async function DELETE(
198
- _request: NextRequest,
199
- { params }: { params: Promise<{ id: string }> }
200
- ) {
201
- const { id } = await params;
202
- return callFunction({
203
- method: 'DELETE',
204
- path: \`/api/${modelCamel}/\${id}\`,
205
- });
206
- }
161
+ const detailRoute = `import { NextRequest } from 'next/server';
162
+ import { callFunction } from '@/lib/api/call-function';
163
+ import { ${schemaName} } from '${sharedPackageName}';
164
+
165
+ const InputSchema = ${schemaName}.omit({ id: true, createdAt: true, updatedAt: true });
166
+
167
+ // GET /api/${modelCamel}/{id} - 詳細取得
168
+ export async function GET(
169
+ _request: NextRequest,
170
+ { params }: { params: Promise<{ id: string }> }
171
+ ) {
172
+ const { id } = await params;
173
+ return callFunction({
174
+ method: 'GET',
175
+ path: \`/api/${modelCamel}/\${id}\`,
176
+ responseSchema: ${schemaName},
177
+ });
178
+ }
179
+
180
+ // PUT /api/${modelCamel}/{id} - 更新
181
+ export async function PUT(
182
+ request: NextRequest,
183
+ { params }: { params: Promise<{ id: string }> }
184
+ ) {
185
+ const { id } = await params;
186
+ const body = await request.json();
187
+ return callFunction({
188
+ method: 'PUT',
189
+ path: \`/api/${modelCamel}/\${id}\`,
190
+ body,
191
+ inputSchema: InputSchema,
192
+ responseSchema: ${schemaName},
193
+ });
194
+ }
195
+
196
+ // DELETE /api/${modelCamel}/{id} - 削除
197
+ export async function DELETE(
198
+ _request: NextRequest,
199
+ { params }: { params: Promise<{ id: string }> }
200
+ ) {
201
+ const { id } = await params;
202
+ return callFunction({
203
+ method: 'DELETE',
204
+ path: \`/api/${modelCamel}/\${id}\`,
205
+ });
206
+ }
207
207
  `;
208
208
  return {
209
209
  listRoute,
@@ -0,0 +1,3 @@
1
+ import { ModelInfo } from "./model-parser";
2
+ export declare function generateOpenApiDocument(models: ModelInfo[], rootModel: ModelInfo): string;
3
+ //# sourceMappingURL=openapi-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-generator.d.ts","sourceRoot":"","sources":["../../../src/core/scaffold/openapi-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAe,MAAM,gBAAgB,CAAC;AAqFnE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CA8HzF"}
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateOpenApiDocument = generateOpenApiDocument;
4
+ const model_parser_1 = require("./model-parser");
5
+ function toScalarSchema(field) {
6
+ if (field.enumValues?.length) {
7
+ return {
8
+ type: "string",
9
+ enum: field.enumValues,
10
+ };
11
+ }
12
+ switch (field.type) {
13
+ case "string":
14
+ return {
15
+ type: "string",
16
+ format: field.name.toLowerCase().endsWith("at") ? "date-time" : undefined,
17
+ };
18
+ case "date":
19
+ return {
20
+ type: "string",
21
+ format: "date-time",
22
+ };
23
+ case "number":
24
+ return {
25
+ type: "number",
26
+ };
27
+ case "boolean":
28
+ return {
29
+ type: "boolean",
30
+ };
31
+ default:
32
+ return {
33
+ type: "object",
34
+ additionalProperties: true,
35
+ };
36
+ }
37
+ }
38
+ function toFieldSchema(field) {
39
+ const schema = field.isNestedSchema && field.nestedModelName
40
+ ? {
41
+ $ref: `#/components/schemas/${field.nestedModelName}`,
42
+ }
43
+ : toScalarSchema(field);
44
+ if (field.isArray) {
45
+ return {
46
+ type: "array",
47
+ items: schema,
48
+ };
49
+ }
50
+ return schema;
51
+ }
52
+ function createComponentSchema(model) {
53
+ const properties = {};
54
+ const required = [];
55
+ for (const field of model.fields) {
56
+ properties[field.name] = toFieldSchema(field);
57
+ if (!field.isOptional) {
58
+ required.push(field.name);
59
+ }
60
+ }
61
+ return {
62
+ type: "object",
63
+ properties,
64
+ required,
65
+ };
66
+ }
67
+ function generateOpenApiDocument(models, rootModel) {
68
+ const rootModelRoute = (0, model_parser_1.toCamelCase)(rootModel.name);
69
+ const components = Object.fromEntries(models.map((model) => [model.name, createComponentSchema(model)]));
70
+ const document = {
71
+ openapi: "3.0.3",
72
+ info: {
73
+ title: `${rootModel.name} API`,
74
+ version: "1.0.0",
75
+ description: "Generated from SwallowKit Zod model metadata.",
76
+ },
77
+ paths: {
78
+ [`/api/${rootModelRoute}`]: {
79
+ get: {
80
+ operationId: `${rootModelRoute}GetAll`,
81
+ responses: {
82
+ "200": {
83
+ description: "Successful response",
84
+ content: {
85
+ "application/json": {
86
+ schema: {
87
+ type: "array",
88
+ items: {
89
+ $ref: `#/components/schemas/${rootModel.name}`,
90
+ },
91
+ },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ },
97
+ post: {
98
+ operationId: `${rootModelRoute}Create`,
99
+ requestBody: {
100
+ required: true,
101
+ content: {
102
+ "application/json": {
103
+ schema: {
104
+ $ref: `#/components/schemas/${rootModel.name}`,
105
+ },
106
+ },
107
+ },
108
+ },
109
+ responses: {
110
+ "201": {
111
+ description: "Created response",
112
+ content: {
113
+ "application/json": {
114
+ schema: {
115
+ $ref: `#/components/schemas/${rootModel.name}`,
116
+ },
117
+ },
118
+ },
119
+ },
120
+ },
121
+ },
122
+ },
123
+ [`/api/${rootModelRoute}/{id}`]: {
124
+ parameters: [
125
+ {
126
+ name: "id",
127
+ in: "path",
128
+ required: true,
129
+ schema: {
130
+ type: "string",
131
+ },
132
+ },
133
+ ],
134
+ get: {
135
+ operationId: `${rootModelRoute}GetById`,
136
+ responses: {
137
+ "200": {
138
+ description: "Successful response",
139
+ content: {
140
+ "application/json": {
141
+ schema: {
142
+ $ref: `#/components/schemas/${rootModel.name}`,
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ put: {
150
+ operationId: `${rootModelRoute}Update`,
151
+ requestBody: {
152
+ required: true,
153
+ content: {
154
+ "application/json": {
155
+ schema: {
156
+ $ref: `#/components/schemas/${rootModel.name}`,
157
+ },
158
+ },
159
+ },
160
+ },
161
+ responses: {
162
+ "200": {
163
+ description: "Updated response",
164
+ content: {
165
+ "application/json": {
166
+ schema: {
167
+ $ref: `#/components/schemas/${rootModel.name}`,
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ },
174
+ delete: {
175
+ operationId: `${rootModelRoute}Delete`,
176
+ responses: {
177
+ "204": {
178
+ description: "Deleted response",
179
+ },
180
+ },
181
+ },
182
+ },
183
+ },
184
+ components: {
185
+ schemas: components,
186
+ },
187
+ };
188
+ return JSON.stringify(document, null, 2);
189
+ }
190
+ //# sourceMappingURL=openapi-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-generator.js","sourceRoot":"","sources":["../../../src/core/scaffold/openapi-generator.ts"],"names":[],"mappings":";;AAqFA,0DA8HC;AAnND,iDAAmE;AAenE,SAAS,cAAc,CAAC,KAAgB;IACtC,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAC7B,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,KAAK,CAAC,UAAU;SACvB,CAAC;IACJ,CAAC;IAED,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;aAC1E,CAAC;QACJ,KAAK,MAAM;YACT,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,WAAW;aACpB,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO;gBACL,IAAI,EAAE,QAAQ;aACf,CAAC;QACJ,KAAK,SAAS;YACZ,OAAO;gBACL,IAAI,EAAE,SAAS;aAChB,CAAC;QACJ;YACE,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,IAAI;aAC3B,CAAC;IACN,CAAC;AACH,CAAC;AAED,SAAS,aAA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