vite-plugin-openapi-codegen 0.0.3 → 1.0.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/README.md +40 -0
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,40 @@ src/generated/
|
|
|
47
47
|
client.ts
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Real Example Project
|
|
51
|
+
|
|
52
|
+
This repository includes a real minimal Vite project under `example/` that demonstrates
|
|
53
|
+
automatic generation from `vite.config.ts`.
|
|
54
|
+
|
|
55
|
+
Key files:
|
|
56
|
+
|
|
57
|
+
- `example/vite.config.ts` wires the plugin into Vite
|
|
58
|
+
- `example/openapi.json` is the input spec
|
|
59
|
+
- `example/src/http.ts` provides the runtime symbols used by generated clients
|
|
60
|
+
- `example/src/generated/*` is generated during build/dev and is gitignored
|
|
61
|
+
|
|
62
|
+
Run the example build:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
vp build example --config ./example/vite.config.ts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run the example dev server:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
vp example --config ./example/vite.config.ts
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
After either command, generated files are written to:
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
example/src/generated/
|
|
78
|
+
api-types.d.ts
|
|
79
|
+
types.ts
|
|
80
|
+
api.ts
|
|
81
|
+
client.ts
|
|
82
|
+
```
|
|
83
|
+
|
|
50
84
|
## Runtime Contract
|
|
51
85
|
|
|
52
86
|
By default, generated clients import the following symbols from `#/integrations/http`:
|
|
@@ -211,3 +245,9 @@ vp test
|
|
|
211
245
|
vp check
|
|
212
246
|
vp pack
|
|
213
247
|
```
|
|
248
|
+
|
|
249
|
+
To validate the real example project as part of local development:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
vp build example --config ./example/vite.config.ts
|
|
253
|
+
```
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import * as ts from "typescript";
|
|
4
4
|
//#region src/ast.ts
|
|
@@ -477,6 +477,7 @@ function renderGeneratedArtifacts(spec, options, preCollectedOperations) {
|
|
|
477
477
|
async function generate(root, options) {
|
|
478
478
|
const inputPath = resolve(root, options.input);
|
|
479
479
|
const outputDir = resolve(root, options.output);
|
|
480
|
+
mkdirSync(outputDir, { recursive: true });
|
|
480
481
|
const spec = JSON.parse(readFileSync(inputPath, "utf-8"));
|
|
481
482
|
const operations = collectOperations(spec, options.pathPrefix ?? "/api/", options.stripPrefix ?? true);
|
|
482
483
|
const artifacts = renderGeneratedArtifacts(spec, options, operations);
|