@povio/openapi-codegen-cli 3.0.0-rc.9 → 3.1.0-rc.1
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 +129 -0
- package/dist/acl.d.mts +1 -1
- package/dist/{config-C1ME3Ay4.d.mts → config-BU7wVf7U.d.mts} +1 -1
- package/dist/{generate.runner-DSZ2ivlU.mjs → generate.runner-BXTc97I0.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-NA2XZmIv.mjs → generateCodeFromOpenAPIDoc-C-n0Knj8.mjs} +298 -205
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +14 -3
- package/dist/metro.d.mts +45 -0
- package/dist/metro.mjs +185 -0
- package/dist/openapi-B14GzSA_.d.mts +170 -0
- package/dist/openapi-codegen.runner-QGd35-a3.mjs +42 -0
- package/dist/openapi-source.runner-D19XnvMe.mjs +39 -0
- package/dist/sh.mjs +3 -3
- package/dist/tiny.d.mts +21 -0
- package/dist/tiny.mjs +631 -0
- package/dist/vite.d.mts +21 -6
- package/dist/vite.mjs +80 -23
- package/dist/zod.d.mts +1 -1
- package/package.json +13 -2
- /package/dist/{error-handling-B4aYKmyL.d.mts → error-handling-CDeKUFHF.d.mts} +0 -0
- /package/dist/{options-BPAjzilp.d.mts → options-CE4Koxof.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -215,6 +215,16 @@ import { ErrorHandler, OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
|
|
|
215
215
|
</OpenApiQueryConfig.Provider>;
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
+
### Runtime response validation
|
|
219
|
+
|
|
220
|
+
Use `OpenApiQueryConfig.Provider` to allow generated GET query hooks to return invalid response data while still logging the response Zod error to the console. Non-GET requests still throw on invalid response data.
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
<OpenApiQueryConfig.Provider allowInvalidResponseData={import.meta.env.DEV}>
|
|
224
|
+
<App />
|
|
225
|
+
</OpenApiQueryConfig.Provider>
|
|
226
|
+
```
|
|
227
|
+
|
|
218
228
|
### OpenApiWorkspaceContext (Path + ACL defaults)
|
|
219
229
|
|
|
220
230
|
Set `workspaceContext` to a list of param names in codegen config (or pass `--workspaceContext officeId,projectId`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params.
|
|
@@ -277,6 +287,125 @@ export default defineConfig({
|
|
|
277
287
|
The plugin runs on both `vite serve` and `vite build`, and watches local OpenAPI files in dev mode.
|
|
278
288
|
If you provide `formatGeneratedFile`, the plugin formats each generated file in memory before comparing and writing it, which helps avoid unnecessary HMR when the formatted output is unchanged.
|
|
279
289
|
|
|
290
|
+
For Tiny projects that generate the OpenAPI JSON from ORPC before client codegen, use the wrapper plugin:
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
import { defineConfig } from "vite";
|
|
294
|
+
import { generateOpenApiFile as writeOpenApiFile, generateORPCOpenAPISpec } from "@povio/openapi-codegen-cli/tiny";
|
|
295
|
+
import { tinyOpenApiCodegen } from "@povio/openapi-codegen-cli/vite";
|
|
296
|
+
import { apiModules } from "../packages/fake-be/src/orpc/api/modules";
|
|
297
|
+
import { contract } from "../packages/fake-be/src/orpc/api/contract";
|
|
298
|
+
import { getOpenApiSchemaName } from "../packages/fake-be/src/orpc/spec";
|
|
299
|
+
import { userRoles } from "../packages/fake-be/src/roles";
|
|
300
|
+
|
|
301
|
+
const generateOpenApiFile = (options) =>
|
|
302
|
+
writeOpenApiFile({
|
|
303
|
+
...options,
|
|
304
|
+
generateOpenApiSpec: () =>
|
|
305
|
+
generateORPCOpenAPISpec({
|
|
306
|
+
contract,
|
|
307
|
+
apiModules,
|
|
308
|
+
userRoles,
|
|
309
|
+
apiRoot: "../packages/fake-be/src/orpc/api",
|
|
310
|
+
dbTablesRoot: "../packages/fake-be/src/db/tables",
|
|
311
|
+
getOpenApiSchemaName,
|
|
312
|
+
}),
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
export default defineConfig({
|
|
316
|
+
plugins: [
|
|
317
|
+
tinyOpenApiCodegen(
|
|
318
|
+
{
|
|
319
|
+
input: "./openapi.generated.json",
|
|
320
|
+
output: "./src/data",
|
|
321
|
+
inlineEndpoints: true,
|
|
322
|
+
incremental: true,
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
generateOpenApiFile,
|
|
326
|
+
watchFolders: ["../packages/fake-be/src/orpc", "../packages/fake-be/src/db"],
|
|
327
|
+
},
|
|
328
|
+
),
|
|
329
|
+
],
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
When `VITE_PUBLIC_API_MODE` or `EXPO_PUBLIC_API_MODE` is `real`, the Tiny wrapper skips ORPC OpenAPI generation and behaves like `openApiCodegen`.
|
|
334
|
+
|
|
335
|
+
### Metro Plugin
|
|
336
|
+
|
|
337
|
+
You can run codegen directly from React Native Metro config:
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
import { fileURLToPath } from "url";
|
|
341
|
+
import { getDefaultConfig } from "@react-native/metro-config";
|
|
342
|
+
import { withOpenApiCodegen } from "@povio/openapi-codegen-cli/metro";
|
|
343
|
+
|
|
344
|
+
const root = fileURLToPath(new URL("./", import.meta.url));
|
|
345
|
+
const config = getDefaultConfig(root);
|
|
346
|
+
|
|
347
|
+
export default withOpenApiCodegen(
|
|
348
|
+
config,
|
|
349
|
+
{
|
|
350
|
+
input: "./openapi.yaml",
|
|
351
|
+
output: "./src/data",
|
|
352
|
+
inlineEndpoints: true,
|
|
353
|
+
incremental: true,
|
|
354
|
+
formatGeneratedFile: async ({ fileName, content }) => {
|
|
355
|
+
void fileName;
|
|
356
|
+
return content;
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
{ root },
|
|
360
|
+
);
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The Metro wrapper runs generation when the config is loaded, waits for it before Metro transforms or serves the first request, and watches local OpenAPI files while the dev server is running.
|
|
364
|
+
If you provide `formatGeneratedFile`, it behaves the same way as the Vite plugin.
|
|
365
|
+
|
|
366
|
+
For Tiny projects, use the Metro wrapper:
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
import { getDefaultConfig } from "@react-native/metro-config";
|
|
370
|
+
import { generateOpenApiFile as writeOpenApiFile, generateORPCOpenAPISpec } from "@povio/openapi-codegen-cli/tiny";
|
|
371
|
+
import { tinyOpenApiCodegenMetro } from "@povio/openapi-codegen-cli/metro";
|
|
372
|
+
import { apiModules } from "../../packages/fake-be/src/orpc/api/modules";
|
|
373
|
+
import { contract } from "../../packages/fake-be/src/orpc/api/contract";
|
|
374
|
+
import { getOpenApiSchemaName } from "../../packages/fake-be/src/orpc/spec";
|
|
375
|
+
import { userRoles } from "../../packages/fake-be/src/roles";
|
|
376
|
+
|
|
377
|
+
const root = __dirname;
|
|
378
|
+
const config = getDefaultConfig(root);
|
|
379
|
+
const generateOpenApiFile = (options) =>
|
|
380
|
+
writeOpenApiFile({
|
|
381
|
+
...options,
|
|
382
|
+
generateOpenApiSpec: () =>
|
|
383
|
+
generateORPCOpenAPISpec({
|
|
384
|
+
contract,
|
|
385
|
+
apiModules,
|
|
386
|
+
userRoles,
|
|
387
|
+
apiRoot: "../../packages/fake-be/src/orpc/api",
|
|
388
|
+
dbTablesRoot: "../../packages/fake-be/src/db/tables",
|
|
389
|
+
getOpenApiSchemaName,
|
|
390
|
+
}),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
export default tinyOpenApiCodegenMetro(
|
|
394
|
+
config,
|
|
395
|
+
{
|
|
396
|
+
input: "./assets/openapi/main.json",
|
|
397
|
+
output: "./utils/rest/openapi",
|
|
398
|
+
inlineEndpoints: true,
|
|
399
|
+
incremental: true,
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
root,
|
|
403
|
+
generateOpenApiFile,
|
|
404
|
+
watchFolders: ["../../packages/fake-be/src/orpc", "../../packages/fake-be/src/db"],
|
|
405
|
+
},
|
|
406
|
+
);
|
|
407
|
+
```
|
|
408
|
+
|
|
280
409
|
### Enums
|
|
281
410
|
|
|
282
411
|
If you're using Enums in your backend DTOs with `@Expose()` and `@IsEnum`, they may still not appear correctly in the OpenAPI schema unless you also provide both `enum` **and** `enumName` to `@ApiProperty`.
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-CDeKUFHF.mjs";
|
|
2
2
|
import * as react from "react";
|
|
3
3
|
import { PropsWithChildren } from "react";
|
|
4
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-C-n0Knj8.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
4
|
|