oazapfts 7.2.0 → 7.4.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 +3 -0
- package/dist/cli.cjs +6 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +47 -36
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +36 -0
- package/dist/index-ClBTKGtv.cjs +9 -0
- package/dist/index-ClBTKGtv.cjs.map +1 -0
- package/dist/index-DOhxV2DJ.js +1238 -0
- package/dist/index-DOhxV2DJ.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +36 -0
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.ts +56 -0
- package/dist/plugin.js +26 -22
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-BLWMZ4ss.cjs +0 -9
- package/dist/index-BLWMZ4ss.cjs.map +0 -1
- package/dist/index-BqfbiHqF.js +0 -1130
- package/dist/index-BqfbiHqF.js.map +0 -1
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ Options:
|
|
|
41
41
|
--argumentStyle=<positional | object> (default: positional)
|
|
42
42
|
--allSchemas
|
|
43
43
|
--futureStripLegacyMethods
|
|
44
|
+
--numericBooleanQueryParameters
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
Where `<spec>` is the URL or local path of an OpenAPI or Swagger spec (in either json or yml) and `<filename>` is the location of the `.ts` file to be generated. If the filename is omitted, the code is written to stdout.
|
|
@@ -63,6 +64,8 @@ Where `<spec>` is the URL or local path of an OpenAPI or Swagger spec (in either
|
|
|
63
64
|
By default, when an `operationId` contains special characters (like dots or colons, e.g. `scope1.userAccount.get`), oazapfts generates both a normalized method name (`scope1UserAccountGet`) and a deprecated fallback using the HTTP verb and path (`getUsersById`) for backward compatibility. Use this flag to only generate the normalized operationId-based names.
|
|
64
65
|
The next major version will default to this behavior.
|
|
65
66
|
|
|
67
|
+
- `--numericBooleanQueryParameters` when true, serialize boolean query parameters as `1 | 0` instead of `true | false`.
|
|
68
|
+
|
|
66
69
|
## Consuming the generated API
|
|
67
70
|
|
|
68
71
|
For each operation defined in the spec the generated API will export a function with a name matching the `operationId`. If no ID is specified, a reasonable name is generated from the HTTP verb and the path.
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var y=(t,l,o)=>new Promise((a,u)=>{var i=e=>{try{s(o.next(e))}catch(r){u(r)}},c=e=>{try{s(o.throw(e))}catch(r){u(r)}},s=e=>e.done?a(e.value):Promise.resolve(e.value).then(i,c);s((o=o.apply(t,l)).next())});const g=require("fs/promises"),w=require("minimist"),b=require("path"),n=require("./index-ClBTKGtv.cjs");function j(t){return y(this,null,function*(){const{include:l,exclude:o,optimistic:a,useEnumType:u,enumStyle:i,mergeReadWriteOnly:c,useUnknown:s,argumentStyle:e,allSchemas:r,numericBooleanQueryParameters:f,futureStripLegacyMethods:h,help:x,version:O}=t,[m,p]=t._;if(x&&(S(),process.exit(0)),O){const v=JSON.parse(yield g.readFile(b.join(__dirname,"..","package.json"),"utf8"));console.log(v.version),process.exit(0)}m||(S(),process.exit(1)),e!==void 0&&!n.argumentStyleOptions.includes(e)&&(console.error(`--argumentStyle should be one of <${n.argumentStyleOptions.join(" | ")}>, but got "${e}"`),process.exit(1)),i!==void 0&&!n.enumStyleOptions.includes(i)&&(console.error(`--enumStyle should be one of <${n.enumStyleOptions.join(" | ")}>, but got "${i}"`),process.exit(1));const d=yield n.generateSource(m,{include:l,exclude:o,optimistic:a,useEnumType:u,enumStyle:i,useUnknown:s,mergeReadWriteOnly:c,argumentStyle:e,allSchemas:r,numericBooleanQueryParameters:f,futureStripLegacyMethods:h});p?yield g.writeFile(p,d):console.log(d)})}function S(){console.error(`
|
|
3
3
|
Usage:
|
|
4
4
|
oazapfts <spec> [filename]
|
|
5
5
|
|
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
--help, -h
|
|
10
10
|
--version, -v
|
|
11
11
|
--optimistic
|
|
12
|
-
--useEnumType
|
|
12
|
+
--useEnumType (deprecated, use --enumStyle=enum)
|
|
13
|
+
--enumStyle=<${n.enumStyleOptions.join(" | ")}> (default: union)
|
|
13
14
|
--useUnknown
|
|
14
15
|
--mergeReadWriteOnly
|
|
15
|
-
--argumentStyle=<${
|
|
16
|
+
--argumentStyle=<${n.argumentStyleOptions.join(" | ")}> (default: positional)
|
|
16
17
|
--allSchemas
|
|
18
|
+
--numericBooleanQueryParameters
|
|
17
19
|
--futureStripLegacyMethods
|
|
18
|
-
`)}w(
|
|
20
|
+
`)}j(w(process.argv.slice(2),{alias:{h:"help",v:"version",i:"include",e:"exclude"},boolean:["help","version","optimistic","useEnumType","mergeReadWriteOnly","useUnknown","allSchemas","numericBooleanQueryParameters","futureStripLegacyMethods"],string:["argumentStyle","enumStyle"]})).catch(t=>{console.error(t),process.exit(1)});
|
|
19
21
|
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFile, writeFile } from \"fs/promises\";\nimport minimist, { type ParsedArgs } from \"minimist\";\nimport { join } from \"path\";\n\nimport { generateSource } from \"./\";\nimport { argumentStyleOptions } from \"./generate/generateClientMethod\";\n\nasync function run(argv: ParsedArgs) {\n const {\n include,\n exclude,\n optimistic,\n useEnumType,\n mergeReadWriteOnly,\n useUnknown,\n argumentStyle,\n allSchemas,\n futureStripLegacyMethods,\n help,\n version,\n } = argv;\n const [spec, dest] = argv._;\n\n if (help) {\n printUsage();\n process.exit(0);\n }\n\n if (version) {\n const pkg = JSON.parse(\n await readFile(join(__dirname, \"..\", \"package.json\"), \"utf8\"),\n );\n console.log(pkg.version);\n process.exit(0);\n }\n\n if (!spec) {\n printUsage();\n process.exit(1);\n }\n\n if (\n argumentStyle !== undefined &&\n !argumentStyleOptions.includes(argumentStyle)\n ) {\n console.error(\n `--argumentStyle should be one of <${argumentStyleOptions.join(\n \" | \",\n )}>, but got \"${argumentStyle}\"`,\n );\n process.exit(1);\n }\n\n const code = await generateSource(spec, {\n include,\n exclude,\n optimistic,\n useEnumType,\n useUnknown,\n mergeReadWriteOnly,\n argumentStyle,\n allSchemas,\n futureStripLegacyMethods,\n });\n\n if (dest) await writeFile(dest, code);\n else console.log(code);\n}\n\nfunction printUsage() {\n console.error(`\n Usage:\n oazapfts <spec> [filename]\n\n Options:\n --exclude, -e <tag to exclude>\n --include, -i <tag to include>\n --help, -h\n --version, -v\n --optimistic\n --useEnumType\n --useUnknown\n --mergeReadWriteOnly\n --argumentStyle=<${argumentStyleOptions.join(\" | \")}> (default: positional)\n --allSchemas\n --futureStripLegacyMethods\n`);\n}\n\nrun(\n minimist(process.argv.slice(2), {\n alias: {\n h: \"help\",\n v: \"version\",\n i: \"include\",\n e: \"exclude\",\n },\n boolean: [\n \"help\",\n \"version\",\n \"optimistic\",\n \"useEnumType\",\n \"mergeReadWriteOnly\",\n \"useUnknown\",\n \"allSchemas\",\n \"futureStripLegacyMethods\",\n ],\n string: [\"argumentStyle\"],\n }),\n).catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],"names":["run","argv","__async","include","exclude","optimistic","useEnumType","mergeReadWriteOnly","useUnknown","argumentStyle","allSchemas","futureStripLegacyMethods","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.cjs","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFile, writeFile } from \"fs/promises\";\nimport minimist, { type ParsedArgs } from \"minimist\";\nimport { join } from \"path\";\n\nimport { generateSource } from \"./\";\nimport { argumentStyleOptions } from \"./generate/generateClientMethod\";\nimport { enumStyleOptions } from \"./helpers/getEnumStyle\";\n\nasync function run(argv: ParsedArgs) {\n const {\n include,\n exclude,\n optimistic,\n useEnumType,\n enumStyle,\n mergeReadWriteOnly,\n useUnknown,\n argumentStyle,\n allSchemas,\n numericBooleanQueryParameters,\n futureStripLegacyMethods,\n help,\n version,\n } = argv;\n const [spec, dest] = argv._;\n\n if (help) {\n printUsage();\n process.exit(0);\n }\n\n if (version) {\n const pkg = JSON.parse(\n await readFile(join(__dirname, \"..\", \"package.json\"), \"utf8\"),\n );\n console.log(pkg.version);\n process.exit(0);\n }\n\n if (!spec) {\n printUsage();\n process.exit(1);\n }\n\n if (\n argumentStyle !== undefined &&\n !argumentStyleOptions.includes(argumentStyle)\n ) {\n console.error(\n `--argumentStyle should be one of <${argumentStyleOptions.join(\n \" | \",\n )}>, but got \"${argumentStyle}\"`,\n );\n process.exit(1);\n }\n\n if (enumStyle !== undefined && !enumStyleOptions.includes(enumStyle)) {\n console.error(\n `--enumStyle should be one of <${enumStyleOptions.join(\n \" | \",\n )}>, but got \"${enumStyle}\"`,\n );\n process.exit(1);\n }\n\n const code = await generateSource(spec, {\n include,\n exclude,\n optimistic,\n useEnumType,\n enumStyle,\n useUnknown,\n mergeReadWriteOnly,\n argumentStyle,\n allSchemas,\n numericBooleanQueryParameters,\n futureStripLegacyMethods,\n });\n\n if (dest) await writeFile(dest, code);\n else console.log(code);\n}\n\nfunction printUsage() {\n console.error(`\n Usage:\n oazapfts <spec> [filename]\n\n Options:\n --exclude, -e <tag to exclude>\n --include, -i <tag to include>\n --help, -h\n --version, -v\n --optimistic\n --useEnumType (deprecated, use --enumStyle=enum)\n --enumStyle=<${enumStyleOptions.join(\" | \")}> (default: union)\n --useUnknown\n --mergeReadWriteOnly\n --argumentStyle=<${argumentStyleOptions.join(\" | \")}> (default: positional)\n --allSchemas\n --numericBooleanQueryParameters\n --futureStripLegacyMethods\n`);\n}\n\nrun(\n minimist(process.argv.slice(2), {\n alias: {\n h: \"help\",\n v: \"version\",\n i: \"include\",\n e: \"exclude\",\n },\n boolean: [\n \"help\",\n \"version\",\n \"optimistic\",\n \"useEnumType\",\n \"mergeReadWriteOnly\",\n \"useUnknown\",\n \"allSchemas\",\n \"numericBooleanQueryParameters\",\n \"futureStripLegacyMethods\",\n ],\n string: [\"argumentStyle\", \"enumStyle\"],\n }),\n).catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],"names":["run","argv","__async","include","exclude","optimistic","useEnumType","enumStyle","mergeReadWriteOnly","useUnknown","argumentStyle","allSchemas","numericBooleanQueryParameters","futureStripLegacyMethods","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","enumStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";mUAUA,SAAeA,EAAIC,EAAkB,QAAAC,EAAA,sBACnC,KAAM,CACJ,QAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,WAAAC,EACA,cAAAC,EACA,WAAAC,EACA,8BAAAC,EACA,yBAAAC,EACA,KAAAC,EACA,QAAAC,CAAA,EACEd,EACE,CAACe,EAAMC,CAAI,EAAIhB,EAAK,EAO1B,GALIa,IACFI,EAAA,EACA,QAAQ,KAAK,CAAC,GAGZH,EAAS,CACX,MAAMI,EAAM,KAAK,MACf,MAAMC,EAAAA,SAASC,EAAAA,KAAK,UAAW,KAAM,cAAc,EAAG,MAAM,CAAA,EAE9D,QAAQ,IAAIF,EAAI,OAAO,EACvB,QAAQ,KAAK,CAAC,CAChB,CAEKH,IACHE,EAAA,EACA,QAAQ,KAAK,CAAC,GAIdR,IAAkB,QAClB,CAACY,EAAAA,qBAAqB,SAASZ,CAAa,IAE5C,QAAQ,MACN,qCAAqCY,EAAAA,qBAAqB,KACxD,KAAA,CACD,eAAeZ,CAAa,GAAA,EAE/B,QAAQ,KAAK,CAAC,GAGZH,IAAc,QAAa,CAACgB,EAAAA,iBAAiB,SAAShB,CAAS,IACjE,QAAQ,MACN,iCAAiCgB,EAAAA,iBAAiB,KAChD,KAAA,CACD,eAAehB,CAAS,GAAA,EAE3B,QAAQ,KAAK,CAAC,GAGhB,MAAMiB,EAAO,MAAMC,EAAAA,eAAeT,EAAM,CACtC,QAAAb,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,UAAAC,EACA,WAAAE,EACA,mBAAAD,EACA,cAAAE,EACA,WAAAC,EACA,8BAAAC,EACA,yBAAAC,CAAA,CACD,EAEGI,EAAM,MAAMS,YAAUT,EAAMO,CAAI,EAC/B,QAAQ,IAAIA,CAAI,CACvB,GAEA,SAASN,GAAa,CACpB,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAWGK,EAAAA,iBAAiB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA,uBAGxBD,EAAAA,qBAAqB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA,CAItD,CACD,CAEAtB,EACE2B,EAAS,QAAQ,KAAK,MAAM,CAAC,EAAG,CAC9B,MAAO,CACL,EAAG,OACH,EAAG,UACH,EAAG,UACH,EAAG,SAAA,EAEL,QAAS,CACP,OACA,UACA,aACA,cACA,qBACA,aACA,aACA,gCACA,0BAAA,EAEF,OAAQ,CAAC,gBAAiB,WAAW,CAAA,CACtC,CACH,EAAE,MAAOC,GAAU,CACjB,QAAQ,MAAMA,CAAK,EACnB,QAAQ,KAAK,CAAC,CAChB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { join as
|
|
5
|
-
import { a as i, g as
|
|
2
|
+
import { readFile as w, writeFile as O } from "fs/promises";
|
|
3
|
+
import b from "minimist";
|
|
4
|
+
import { join as j } from "path";
|
|
5
|
+
import { a as t, e as i, g as $ } from "./index-DOhxV2DJ.js";
|
|
6
6
|
async function k(e) {
|
|
7
7
|
const {
|
|
8
|
-
include:
|
|
8
|
+
include: u,
|
|
9
9
|
exclude: c,
|
|
10
|
-
optimistic:
|
|
11
|
-
useEnumType:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
optimistic: m,
|
|
11
|
+
useEnumType: p,
|
|
12
|
+
enumStyle: o,
|
|
13
|
+
mergeReadWriteOnly: d,
|
|
14
|
+
useUnknown: g,
|
|
15
|
+
argumentStyle: n,
|
|
16
|
+
allSchemas: y,
|
|
17
|
+
numericBooleanQueryParameters: f,
|
|
18
|
+
futureStripLegacyMethods: S,
|
|
19
|
+
help: h,
|
|
20
|
+
version: v
|
|
21
|
+
} = e, [s, r] = e._;
|
|
22
|
+
if (h && (l(), process.exit(0)), v) {
|
|
23
|
+
const x = JSON.parse(
|
|
24
|
+
await w(j(__dirname, "..", "package.json"), "utf8")
|
|
23
25
|
);
|
|
24
|
-
console.log(
|
|
26
|
+
console.log(x.version), process.exit(0);
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
`--argumentStyle should be one of <${
|
|
28
|
+
s || (l(), process.exit(1)), n !== void 0 && !t.includes(n) && (console.error(
|
|
29
|
+
`--argumentStyle should be one of <${t.join(
|
|
30
|
+
" | "
|
|
31
|
+
)}>, but got "${n}"`
|
|
32
|
+
), process.exit(1)), o !== void 0 && !i.includes(o) && (console.error(
|
|
33
|
+
`--enumStyle should be one of <${i.join(
|
|
28
34
|
" | "
|
|
29
35
|
)}>, but got "${o}"`
|
|
30
36
|
), process.exit(1));
|
|
31
|
-
const
|
|
32
|
-
include:
|
|
37
|
+
const a = await $(s, {
|
|
38
|
+
include: u,
|
|
33
39
|
exclude: c,
|
|
34
|
-
optimistic:
|
|
35
|
-
useEnumType:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
optimistic: m,
|
|
41
|
+
useEnumType: p,
|
|
42
|
+
enumStyle: o,
|
|
43
|
+
useUnknown: g,
|
|
44
|
+
mergeReadWriteOnly: d,
|
|
45
|
+
argumentStyle: n,
|
|
46
|
+
allSchemas: y,
|
|
47
|
+
numericBooleanQueryParameters: f,
|
|
48
|
+
futureStripLegacyMethods: S
|
|
41
49
|
});
|
|
42
|
-
|
|
50
|
+
r ? await O(r, a) : console.log(a);
|
|
43
51
|
}
|
|
44
|
-
function
|
|
52
|
+
function l() {
|
|
45
53
|
console.error(`
|
|
46
54
|
Usage:
|
|
47
55
|
oazapfts <spec> [filename]
|
|
@@ -52,16 +60,18 @@ function r() {
|
|
|
52
60
|
--help, -h
|
|
53
61
|
--version, -v
|
|
54
62
|
--optimistic
|
|
55
|
-
--useEnumType
|
|
63
|
+
--useEnumType (deprecated, use --enumStyle=enum)
|
|
64
|
+
--enumStyle=<${i.join(" | ")}> (default: union)
|
|
56
65
|
--useUnknown
|
|
57
66
|
--mergeReadWriteOnly
|
|
58
|
-
--argumentStyle=<${
|
|
67
|
+
--argumentStyle=<${t.join(" | ")}> (default: positional)
|
|
59
68
|
--allSchemas
|
|
69
|
+
--numericBooleanQueryParameters
|
|
60
70
|
--futureStripLegacyMethods
|
|
61
71
|
`);
|
|
62
72
|
}
|
|
63
73
|
k(
|
|
64
|
-
|
|
74
|
+
b(process.argv.slice(2), {
|
|
65
75
|
alias: {
|
|
66
76
|
h: "help",
|
|
67
77
|
v: "version",
|
|
@@ -76,9 +86,10 @@ k(
|
|
|
76
86
|
"mergeReadWriteOnly",
|
|
77
87
|
"useUnknown",
|
|
78
88
|
"allSchemas",
|
|
89
|
+
"numericBooleanQueryParameters",
|
|
79
90
|
"futureStripLegacyMethods"
|
|
80
91
|
],
|
|
81
|
-
string: ["argumentStyle"]
|
|
92
|
+
string: ["argumentStyle", "enumStyle"]
|
|
82
93
|
})
|
|
83
94
|
).catch((e) => {
|
|
84
95
|
console.error(e), process.exit(1);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFile, writeFile } from \"fs/promises\";\nimport minimist, { type ParsedArgs } from \"minimist\";\nimport { join } from \"path\";\n\nimport { generateSource } from \"./\";\nimport { argumentStyleOptions } from \"./generate/generateClientMethod\";\n\nasync function run(argv: ParsedArgs) {\n const {\n include,\n exclude,\n optimistic,\n useEnumType,\n mergeReadWriteOnly,\n useUnknown,\n argumentStyle,\n allSchemas,\n futureStripLegacyMethods,\n help,\n version,\n } = argv;\n const [spec, dest] = argv._;\n\n if (help) {\n printUsage();\n process.exit(0);\n }\n\n if (version) {\n const pkg = JSON.parse(\n await readFile(join(__dirname, \"..\", \"package.json\"), \"utf8\"),\n );\n console.log(pkg.version);\n process.exit(0);\n }\n\n if (!spec) {\n printUsage();\n process.exit(1);\n }\n\n if (\n argumentStyle !== undefined &&\n !argumentStyleOptions.includes(argumentStyle)\n ) {\n console.error(\n `--argumentStyle should be one of <${argumentStyleOptions.join(\n \" | \",\n )}>, but got \"${argumentStyle}\"`,\n );\n process.exit(1);\n }\n\n const code = await generateSource(spec, {\n include,\n exclude,\n optimistic,\n useEnumType,\n useUnknown,\n mergeReadWriteOnly,\n argumentStyle,\n allSchemas,\n futureStripLegacyMethods,\n });\n\n if (dest) await writeFile(dest, code);\n else console.log(code);\n}\n\nfunction printUsage() {\n console.error(`\n Usage:\n oazapfts <spec> [filename]\n\n Options:\n --exclude, -e <tag to exclude>\n --include, -i <tag to include>\n --help, -h\n --version, -v\n --optimistic\n --useEnumType\n --useUnknown\n --mergeReadWriteOnly\n --argumentStyle=<${argumentStyleOptions.join(\" | \")}> (default: positional)\n --allSchemas\n --futureStripLegacyMethods\n`);\n}\n\nrun(\n minimist(process.argv.slice(2), {\n alias: {\n h: \"help\",\n v: \"version\",\n i: \"include\",\n e: \"exclude\",\n },\n boolean: [\n \"help\",\n \"version\",\n \"optimistic\",\n \"useEnumType\",\n \"mergeReadWriteOnly\",\n \"useUnknown\",\n \"allSchemas\",\n \"futureStripLegacyMethods\",\n ],\n string: [\"argumentStyle\"],\n }),\n).catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],"names":["run","argv","include","exclude","optimistic","useEnumType","mergeReadWriteOnly","useUnknown","argumentStyle","allSchemas","futureStripLegacyMethods","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFile, writeFile } from \"fs/promises\";\nimport minimist, { type ParsedArgs } from \"minimist\";\nimport { join } from \"path\";\n\nimport { generateSource } from \"./\";\nimport { argumentStyleOptions } from \"./generate/generateClientMethod\";\nimport { enumStyleOptions } from \"./helpers/getEnumStyle\";\n\nasync function run(argv: ParsedArgs) {\n const {\n include,\n exclude,\n optimistic,\n useEnumType,\n enumStyle,\n mergeReadWriteOnly,\n useUnknown,\n argumentStyle,\n allSchemas,\n numericBooleanQueryParameters,\n futureStripLegacyMethods,\n help,\n version,\n } = argv;\n const [spec, dest] = argv._;\n\n if (help) {\n printUsage();\n process.exit(0);\n }\n\n if (version) {\n const pkg = JSON.parse(\n await readFile(join(__dirname, \"..\", \"package.json\"), \"utf8\"),\n );\n console.log(pkg.version);\n process.exit(0);\n }\n\n if (!spec) {\n printUsage();\n process.exit(1);\n }\n\n if (\n argumentStyle !== undefined &&\n !argumentStyleOptions.includes(argumentStyle)\n ) {\n console.error(\n `--argumentStyle should be one of <${argumentStyleOptions.join(\n \" | \",\n )}>, but got \"${argumentStyle}\"`,\n );\n process.exit(1);\n }\n\n if (enumStyle !== undefined && !enumStyleOptions.includes(enumStyle)) {\n console.error(\n `--enumStyle should be one of <${enumStyleOptions.join(\n \" | \",\n )}>, but got \"${enumStyle}\"`,\n );\n process.exit(1);\n }\n\n const code = await generateSource(spec, {\n include,\n exclude,\n optimistic,\n useEnumType,\n enumStyle,\n useUnknown,\n mergeReadWriteOnly,\n argumentStyle,\n allSchemas,\n numericBooleanQueryParameters,\n futureStripLegacyMethods,\n });\n\n if (dest) await writeFile(dest, code);\n else console.log(code);\n}\n\nfunction printUsage() {\n console.error(`\n Usage:\n oazapfts <spec> [filename]\n\n Options:\n --exclude, -e <tag to exclude>\n --include, -i <tag to include>\n --help, -h\n --version, -v\n --optimistic\n --useEnumType (deprecated, use --enumStyle=enum)\n --enumStyle=<${enumStyleOptions.join(\" | \")}> (default: union)\n --useUnknown\n --mergeReadWriteOnly\n --argumentStyle=<${argumentStyleOptions.join(\" | \")}> (default: positional)\n --allSchemas\n --numericBooleanQueryParameters\n --futureStripLegacyMethods\n`);\n}\n\nrun(\n minimist(process.argv.slice(2), {\n alias: {\n h: \"help\",\n v: \"version\",\n i: \"include\",\n e: \"exclude\",\n },\n boolean: [\n \"help\",\n \"version\",\n \"optimistic\",\n \"useEnumType\",\n \"mergeReadWriteOnly\",\n \"useUnknown\",\n \"allSchemas\",\n \"numericBooleanQueryParameters\",\n \"futureStripLegacyMethods\",\n ],\n string: [\"argumentStyle\", \"enumStyle\"],\n }),\n).catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],"names":["run","argv","include","exclude","optimistic","useEnumType","enumStyle","mergeReadWriteOnly","useUnknown","argumentStyle","allSchemas","numericBooleanQueryParameters","futureStripLegacyMethods","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","enumStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";;;;;AAUA,eAAeA,EAAIC,GAAkB;AACnC,QAAM;AAAA,IACJ,SAAAC;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,eAAAC;AAAA,IACA,YAAAC;AAAA,IACA,+BAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,MAAAC;AAAA,IACA,SAAAC;AAAA,EAAA,IACEb,GACE,CAACc,GAAMC,CAAI,IAAIf,EAAK;AAO1B,MALIY,MACFI,EAAA,GACA,QAAQ,KAAK,CAAC,IAGZH,GAAS;AACX,UAAMI,IAAM,KAAK;AAAA,MACf,MAAMC,EAASC,EAAK,WAAW,MAAM,cAAc,GAAG,MAAM;AAAA,IAAA;AAE9D,YAAQ,IAAIF,EAAI,OAAO,GACvB,QAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,EAAKH,MACHE,EAAA,GACA,QAAQ,KAAK,CAAC,IAIdR,MAAkB,UAClB,CAACY,EAAqB,SAASZ,CAAa,MAE5C,QAAQ;AAAA,IACN,qCAAqCY,EAAqB;AAAA,MACxD;AAAA,IAAA,CACD,eAAeZ,CAAa;AAAA,EAAA,GAE/B,QAAQ,KAAK,CAAC,IAGZH,MAAc,UAAa,CAACgB,EAAiB,SAAShB,CAAS,MACjE,QAAQ;AAAA,IACN,iCAAiCgB,EAAiB;AAAA,MAChD;AAAA,IAAA,CACD,eAAehB,CAAS;AAAA,EAAA,GAE3B,QAAQ,KAAK,CAAC;AAGhB,QAAMiB,IAAO,MAAMC,EAAeT,GAAM;AAAA,IACtC,SAAAb;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,YAAAE;AAAA,IACA,oBAAAD;AAAA,IACA,eAAAE;AAAA,IACA,YAAAC;AAAA,IACA,+BAAAC;AAAA,IACA,0BAAAC;AAAA,EAAA,CACD;AAED,EAAII,IAAM,MAAMS,EAAUT,GAAMO,CAAI,IAC/B,QAAQ,IAAIA,CAAI;AACvB;AAEA,SAASN,IAAa;AACpB,UAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAWGK,EAAiB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA,uBAGxBD,EAAqB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA,CAItD;AACD;AAEArB;AAAA,EACE0B,EAAS,QAAQ,KAAK,MAAM,CAAC,GAAG;AAAA,IAC9B,OAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAG;AAAA,MACH,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAAA,IAEL,SAAS;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAEF,QAAQ,CAAC,iBAAiB,WAAW;AAAA,EAAA,CACtC;AACH,EAAE,MAAM,CAACC,MAAU;AACjB,UAAQ,MAAMA,CAAK,GACnB,QAAQ,KAAK,CAAC;AAChB,CAAC;"}
|
package/dist/context.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { InterfaceDeclaration } from 'typescript';
|
|
|
6
6
|
import { OpenAPIV3 } from 'openapi-types';
|
|
7
7
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
8
8
|
import { Statement } from 'typescript';
|
|
9
|
+
import { SyncWaterfallHook } from 'tapable';
|
|
9
10
|
import { TypeAliasDeclaration } from 'typescript';
|
|
10
11
|
import { TypeReferenceNode } from 'typescript';
|
|
11
12
|
|
|
@@ -41,6 +42,10 @@ declare type Document_2 = OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
|
41
42
|
|
|
42
43
|
declare type Document_2_2 = OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
43
44
|
|
|
45
|
+
declare type EnumStyle = (typeof enumStyleOptions)[number];
|
|
46
|
+
|
|
47
|
+
declare const enumStyleOptions: readonly ["union", "enum", "as-const"];
|
|
48
|
+
|
|
44
49
|
declare type HttpMethod = (typeof HttpMethods)[number];
|
|
45
50
|
|
|
46
51
|
declare const HttpMethods: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
@@ -164,11 +169,23 @@ declare type OazapftsOptions = {
|
|
|
164
169
|
exclude?: string[];
|
|
165
170
|
optimistic?: boolean;
|
|
166
171
|
unionUndefined?: boolean;
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use `enumStyle: "enum"` instead.
|
|
174
|
+
*/
|
|
167
175
|
useEnumType?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Controls how enums are generated in TypeScript.
|
|
178
|
+
* Takes precedence over `useEnumType` if both are specified.
|
|
179
|
+
*/
|
|
180
|
+
enumStyle?: EnumStyle;
|
|
168
181
|
mergeReadWriteOnly?: boolean;
|
|
169
182
|
useUnknown?: boolean;
|
|
170
183
|
argumentStyle?: ArgumentStyle;
|
|
171
184
|
allSchemas?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* When true, serialize boolean query parameters as 1/0.
|
|
187
|
+
*/
|
|
188
|
+
numericBooleanQueryParameters?: boolean;
|
|
172
189
|
/**
|
|
173
190
|
* When true, skip generating deprecated legacy method aliases for backward
|
|
174
191
|
* compatibility. Only the primary normalized operationId-based names will
|
|
@@ -260,6 +277,11 @@ declare type UNSTABLE_OazapftsPluginHooks = {
|
|
|
260
277
|
},
|
|
261
278
|
OazapftsContext_2
|
|
262
279
|
]>;
|
|
280
|
+
/**
|
|
281
|
+
* Customize query serializer call arguments for each formatter call.
|
|
282
|
+
* Default behavior is identity (returns the original args unchanged).
|
|
283
|
+
*/
|
|
284
|
+
querySerializerArgs: SyncWaterfallHook<UNSTABLE_QuerySerializerHookArgs>;
|
|
263
285
|
/**
|
|
264
286
|
* Called after the full AST has been generated, before printing to string.
|
|
265
287
|
* Use this to add/modify/remove statements from the final source file.
|
|
@@ -273,4 +295,18 @@ declare type UNSTABLE_OazapftsPluginOptions = {
|
|
|
273
295
|
precedence?: UNSTABLE_OAZAPFTS_PLUGIN_PRECEDENCE;
|
|
274
296
|
};
|
|
275
297
|
|
|
298
|
+
declare type UNSTABLE_QuerySerializerHookArgs = [
|
|
299
|
+
default_2.Expression[],
|
|
300
|
+
{
|
|
301
|
+
method: HttpMethod;
|
|
302
|
+
path: string;
|
|
303
|
+
operation: OpenAPI.OperationObject;
|
|
304
|
+
pathItem: OpenAPI.PathItemObject;
|
|
305
|
+
formatter: string;
|
|
306
|
+
parameters: OpenAPI.ParameterObject[];
|
|
307
|
+
query: OpenAPI.ParameterObject[];
|
|
308
|
+
},
|
|
309
|
+
OazapftsContext_2
|
|
310
|
+
];
|
|
311
|
+
|
|
276
312
|
export { }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";var he=Object.defineProperty,ve=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var oe=Object.getOwnPropertySymbols;var Ae=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var ie=(e,t,r)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,F=(e,t)=>{for(var r in t||(t={}))Ae.call(t,r)&&ie(e,r,t[r]);if(oe)for(var r of oe(t))Ee.call(t,r)&&ie(e,r,t[r]);return e},ae=(e,t)=>ve(e,Ie(t));var C=(e,t,r)=>new Promise((a,o)=>{var c=u=>{try{f(r.next(u))}catch(p){o(p)}},i=u=>{try{f(r.throw(u))}catch(p){o(p)}},f=u=>u.done?a(u.value):Promise.resolve(u.value).then(c,i);f((r=r.apply(e,t)).next())});const s=require("./context-lKBK5qCf.cjs"),Pe=require("@apidevtools/swagger-parser"),n=require("typescript"),N=require("lodash"),B=require("./plugin.cjs");function k(e){return e.replace(/.+\//,"")}function v(e){return typeof e=="object"&&e!==null&&"$ref"in e}function ye(e){if(!e.startsWith("#/"))throw new Error(`External refs are not supported (${e}). Make sure to call SwaggerParser.bundle() first.`);return e.slice(2).split("/").map(t=>decodeURI(t.replace(/~1/g,"/").replace(/~0/g,"~")))}function T(e,{spec:t}){if(!v(e))return e;const r=e.$ref,a=ye(r),o=N.get(t,a);if(typeof o=="undefined")throw new Error(`Can't find ${a}`);return o}function se(e,t){return t?t.map(r=>T(r,e)):[]}function je(e){var o;if(!((o=e.spec.components)!=null&&o.schemas))return;const t="#/components/schemas/",r=e.spec.components.schemas;for(const c of Object.keys(r)){const i=r[c];v(i)||typeof i=="boolean"||i.discriminator&&!i.oneOf&&!i.anyOf&&e.discriminatingSchemas.add(i)}const a=(c,i)=>Object.values(c.mapping||{}).includes(i);for(const c of Object.keys(r)){const i=r[c];if(!(v(i)||typeof i=="boolean"||!i.allOf))for(const f of i.allOf){if(!v(f)||!e.discriminatingSchemas.has(T(f,e)))continue;const u=r[k(f.$ref)];if(v(u))throw new Error("Unexpected nested reference");const p=u.discriminator;a(p,t+c)||(p.mapping||(p.mapping={}),p.mapping[c]=t+c)}}}function Le(e,t){var a;return t&&t.some(o=>{var c,i;return(i=(c=e.opts)==null?void 0:c.exclude)==null?void 0:i.includes(o)})?!0:(a=e.opts)!=null&&a.include?!(t&&t.some(c=>{var i;return(i=e.opts.include)==null?void 0:i.includes(c)})):!1}function ke(e,t,r){const a=Re(e,t),o=Ce(r),c=$e(r);return c&&!o?{primaryName:c,deprecatedLegacyName:a}:{primaryName:c||a}}function Re(e,t){return t=t.replace(/\{(.+?)\}/,"by $1").replace(/\{(.+?)\}/,"and $1"),s.toIdentifier(`${e} ${t}`)}function $e(e){if(!e)return;const t=e.replace(/[^\w\s]/g," ");let r=N.camelCase(t);if(r&&(r=r.replace(/^[^a-zA-Z_$]+/,""),r=N.lowerFirst(r),!!r&&s.isValidIdentifier(r)))return r}function Ce(e){if(!e||e.match(/[^\w\s]/))return;const t=N.camelCase(e);if(s.isValidIdentifier(t))return t}const le={"*/*":"json","application/json":"json","application/x-www-form-urlencoded":"form","multipart/form-data":"multipart"};function Fe(e){return typeof e=="string"&&/^[^/]+\/[^/]+$/.test(e)}function Y(e){return le[e]==="json"||/\bjson\b/i.test(e)}function qe({style:e="form",explode:t=!0,content:r}){if(r){const a=Object.keys(r);if(a.length!==1)throw new Error("Parameters with content property must specify one media type");if(!Y(a[0]))throw new Error("Parameters with content property must specify a JSON compatible media type");return"json"}return t&&e==="deepObject"?"deep":t?"explode":e==="spaceDelimited"?"space":e==="pipeDelimited"?"pipe":"form"}function ce(e,t){return s.createCall(n.factory.createPropertyAccessExpression(n.factory.createIdentifier("QS"),e),{args:t})}function De(e,t){const r=[],a=e.replace(/(.*?)\{(.+?)\}(.*?)(?=\{|$)/g,(o,c,i,f)=>{const u=s.toIdentifier(i);return r.push({expression:s.createCall(n.factory.createIdentifier("encodeURIComponent"),{args:[n.factory.createIdentifier(u)]}),literal:f}),c});return t&&r.push({expression:t,literal:""}),s.createTemplateString(a,r)}function q(e,t,r){return s.createCall(n.factory.createPropertyAccessExpression(n.factory.createIdentifier("oazapfts"),e),{args:t,typeArgs:r})}function Ue(e){if(e!=null&&e.content)for(const t of Object.keys(e.content)){const r=le[t];if(r)return r;if(Y(t))return"json"}}function Be(e,t){var r;return(r=t.opts)!=null&&r.optimistic?q("ok",[e]):e}function fe(e){if(v(e))return k(e.$ref)}function Ke(e,t){const r=o=>{try{return T({$ref:o},t),!1}catch(c){return!0}};if(r(e))return e;let a=2;for(;;){const o=e+String(a);if(r(o))return o;a+=1}}function _e(e){const t=k(e);return/^\d+/.test(t)?ye(e).join("_"):t}function K(e,t){return!!(typeof e!="boolean"&&e.enum&&t&&e.type!=="boolean")}const Qe=["union","enum","as-const"];function _(e){return e.enumStyle!==void 0?e.enumStyle:e.useEnumType?"enum":"union"}function D(e,t){let r=t.typeAliases[e]||0;return r&&(t.typeAliases[e]=++r,e+=r),t.typeAliases[e]=1,e}function de(e,t,r){return r.enumRefs[e]&&r.enumRefs[e].values===t?e:D(e,r)}function me(e,t){const r="x-enumNames"in e?e["x-enumNames"]:"x-enum-varnames"in e?e["x-enum-varnames"]:void 0;if(r){if(!Array.isArray(r))throw new Error("enum names must be an array");if(r.length!==t.length)throw new Error("enum names must have the same length as enum values");if(r.some(a=>typeof a!="string"))throw new Error("enum names must be an array of strings");return r}}function ge(e,t,r=!0){if(t.opts.mergeReadWriteOnly)return{readOnly:!1,writeOnly:!1};const a=(o,c)=>{var p,y,l,d,O,b;if(v(o)){if(!r)return{readOnly:!1,writeOnly:!1};if(c.has(o.$ref))return{readOnly:!1,writeOnly:!1};const I=t.refsOnlyMode.get(o.$ref);if(I)return I;c.add(o.$ref);const h=a(T(o,t),c);return c.delete(o.$ref),t.refsOnlyMode.set(o.$ref,h),h}if(typeof o=="boolean")return{readOnly:!1,writeOnly:!1};let i=(p=o.readOnly)!=null?p:!1,f=(y=o.writeOnly)!=null?y:!1;const u=[];"items"in o&&o.items?u.push(o.items):(u.push(...Object.values((l=o.properties)!=null?l:{})),u.push(...(d=o.allOf)!=null?d:[]),u.push(...(O=o.anyOf)!=null?O:[]),u.push(...(b=o.oneOf)!=null?b:[]));for(const I of u){if(i&&f)break;const h=a(I,c);i=i||h.readOnly,f=f||h.writeOnly}return{readOnly:i,writeOnly:f}};return a(e,new Set)}function ze(e){return typeof e=="boolean"?e:e&&"nullable"in e?!v(e)&&e.nullable:!1}const Ve=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"];function Me(e){return Ve.includes(e)}function He(e){const t={};return e.map(r=>{var o;const a=(o=r.name)==null?void 0:o.text;if(a){if(t[a])return s.updateFunctionDeclaration(r,{name:n.factory.createIdentifier(`${a}${++t[a]}`)});t[a]=1}return r})}function Q(e){const t=Object.keys(e).find(Fe);if(t){const{schema:r}=e[t];if(r)return r}return Object.keys(e).length===0||Object.keys(e).some(r=>r.startsWith("text/"))?{type:"string"}:{type:"string",format:"binary"}}function W(e,t,r,a){var c;const o=a?Ke(e.$ref+"Base",t):e.$ref;if(!t.refs[o]){let i=T(e,t);typeof i!="boolean"&&a&&(i=N.cloneDeep(i),delete i.discriminator);const f=typeof i!="boolean"&&i.title||_e(o),u=s.toIdentifier(f,!0);if(_(t.opts)!=="union"&&K(i,f))return w(t,i,f);const p=D(u,t);t.refs[o]={base:n.factory.createTypeReferenceNode(p,void 0),readOnly:void 0,writeOnly:void 0};const y=w(t,i,void 0);t.aliases.push(s.createTypeAliasDeclaration({modifiers:[s.modifier.export],name:p,type:y}));const{readOnly:l,writeOnly:d}=ge(i,t);if(l){const O=D(s.toIdentifier(f,!0,"readOnly"),t);t.refs[o].readOnly=n.factory.createTypeReferenceNode(O,void 0);const b=w(t,i,f,"readOnly");t.aliases.push(s.createTypeAliasDeclaration({modifiers:[s.modifier.export],name:O,type:b}))}if(d){const O=D(s.toIdentifier(f,!0,"writeOnly"),t);t.refs[o].writeOnly=n.factory.createTypeReferenceNode(O,void 0);const b=w(t,i,f,"writeOnly");t.aliases.push(s.createTypeAliasDeclaration({modifiers:[s.modifier.export],name:O,type:b}))}}return(c=t.refs[o][r||"base"])!=null?c:t.refs[o].base}function J(e,t,r){var l;if(typeof e=="boolean")throw new Error("cannot get enum from boolean schema. schema must be an object");const o=(e.title||N.upperFirst(t)).split(/[^A-Za-z0-9$_]/g).map(d=>N.upperFirst(d)).join(""),c=((l=e.enum)!=null?l:[]).join("_"),i=de(o,c,r);if(r.enumRefs[o]&&o===i)return r.enumRefs[o].type;const f=e.enum?e.enum:[],u=me(e,f),p=f.map((d,O)=>{if(e.type==="number"||e.type==="integer"||e.type==="string"){const b=u?u[O]:String(d);return n.factory.createEnumMember(n.factory.createIdentifier(s.toIdentifier(b,!0)),s.createLiteral(d))}return n.factory.createEnumMember(n.factory.createIdentifier(s.toIdentifier(String(d),!0)),s.createLiteral(d))});r.enumAliases.push(n.factory.createEnumDeclaration([s.modifier.export],i,p));const y=n.factory.createTypeReferenceNode(i,void 0);return r.enumRefs[o]={values:c,type:n.factory.createTypeReferenceNode(i,void 0)},y}function Z(e,t,r){var O;if(typeof e=="boolean")throw new Error("cannot get enum from boolean schema. schema must be an object");const o=(e.title||N.upperFirst(t)).split(/[^A-Za-z0-9$_]/g).map(b=>N.upperFirst(b)).join(""),c=((O=e.enum)!=null?O:[]).join("_"),i=de(o,c,r);if(r.enumRefs[o]&&o===i)return r.enumRefs[o].type;const f=e.enum?e.enum:[],u=me(e,f),p=f.map((b,I)=>{if(e.type==="number"||e.type==="integer"||e.type==="string"){const h=u?u[I]:String(b);return n.factory.createPropertyAssignment(n.factory.createIdentifier(s.toIdentifier(h,!0)),s.createLiteral(b))}return n.factory.createPropertyAssignment(n.factory.createIdentifier(s.toIdentifier(String(b),!0)),s.createLiteral(b))}),y=n.factory.createVariableStatement([s.modifier.export],n.factory.createVariableDeclarationList([n.factory.createVariableDeclaration(i,void 0,void 0,n.factory.createAsExpression(n.factory.createObjectLiteralExpression(p,!0),n.factory.createTypeReferenceNode("const")))],n.NodeFlags.Const)),l=s.createTypeAliasDeclaration({modifiers:[s.modifier.export],name:i,type:n.factory.createIndexedAccessTypeNode(n.factory.createParenthesizedType(n.factory.createTypeQueryNode(n.factory.createIdentifier(i))),n.factory.createTypeOperatorNode(n.SyntaxKind.KeyOfKeyword,n.factory.createTypeQueryNode(n.factory.createIdentifier(i))))});r.enumAliases.push(y,l);const d=n.factory.createTypeReferenceNode(i,void 0);return r.enumRefs[o]={values:c,type:d},d}function G(e){const t=e.map(r=>{if(r===null)return s.keywordType.null;if(typeof r=="boolean")return r?n.factory.createLiteralTypeNode(n.factory.createToken(n.SyntaxKind.TrueKeyword)):n.factory.createLiteralTypeNode(n.factory.createToken(n.SyntaxKind.FalseKeyword));if(typeof r=="number")return n.factory.createLiteralTypeNode(n.factory.createNumericLiteral(r));if(typeof r=="string")return n.factory.createLiteralTypeNode(n.factory.createStringLiteral(r));throw new Error(`Unexpected ${String(r)} of type ${typeof r} in enum`)});return t.length>1?n.factory.createUnionTypeNode(t):t[0]}function be(e,t,r,a){var p,y;const o=_(e.opts);if(o==="union")return G(a);const c=T(t,e);let i=T((p=c.properties)==null?void 0:p[r],e);if(!i&&c.allOf)for(const l of c.allOf){const d=T(l,e);if((y=d.properties)!=null&&y[r]){i=T(d.properties[r],e);break}}if(!i||!K(i,r))return G(a);const f=o==="as-const"?Z(i,r,e):J(i,r,e),u=a.map(l=>{const d=n.factory.createQualifiedName(f.typeName,n.factory.createIdentifier(s.toIdentifier(l,!0)));return o==="as-const"?n.factory.createTypeQueryNode(d):n.factory.createTypeReferenceNode(d)});return u.length===1?u[0]:n.factory.createUnionTypeNode(u)}function M(e,t,r,a){if(r){if(r.propertyName===void 0)throw new Error("Discriminators require a propertyName");const o=new Set(Object.values(r.mapping||{}).map(k));return n.factory.createUnionTypeNode([...Object.entries(r.mapping||{}).map(([c,i])=>[c,{$ref:i}]),...e.filter(c=>{if(!v(c))throw new Error("Discriminators require references, not inline schemas");return!o.has(k(c.$ref))}).map(c=>{var y,l;const i=k(c.$ref),u=(y=T(c,t).properties)==null?void 0:y[r.propertyName];return[(u&&"enum"in u?(l=u==null?void 0:u.enum)==null?void 0:l[0]:"")||i,c]})].map(([c,i])=>n.factory.createIntersectionTypeNode([n.factory.createTypeLiteralNode([s.createPropertySignature({name:r.propertyName,type:be(t,i,r.propertyName,[c])})]),w(t,i,void 0,a)])))}else return n.factory.createUnionTypeNode(N.uniq(e.map(o=>w(t,o,void 0,a))))}function U(e){return e.opts.useUnknown?s.keywordType.unknown:s.keywordType.any}function ue(e,t,r,a,o){const f=Object.keys(e).filter(u=>{const p=e[u],{readOnly:y,writeOnly:l}=ge(p,t,!1);switch(o){case"readOnly":return y||!l;case"writeOnly":return l||!y;default:return!y&&!l}}).map(u=>{const p=e[u],y=r&&r.includes(u);let l=w(t,p,u,o);!y&&t.opts.unionUndefined&&(l=n.factory.createUnionTypeNode([l,s.keywordType.undefined]));const d=s.createPropertySignature({questionToken:!y,name:u,type:l});if(typeof p!="boolean"&&"description"in p&&p.description){const O=p.description.replace("*/","*\\/");n.addSyntheticLeadingComment(d,n.SyntaxKind.MultiLineCommentTrivia,`* ${O} `,!0)}return d});if(a){const u=a===!0?U(t):w(t,a,void 0,o);f.push(s.createIndexSignature(u))}return n.factory.createTypeLiteralNode(f)}function w(e,t,r,a){const o=Te(e,t,r,a);return ze(t)?n.factory.createUnionTypeNode([o,s.keywordType.null]):o}function Te(e,t,r,a){var o,c;if(t===void 0)return U(e);if(v(t))return W(t,e,a);if(t===!0)return U(e);if(t===!1)return s.keywordType.never;if(t.oneOf){const i=F({},t);return delete i.oneOf,M(t.oneOf.map(f=>N.mergeWith({},i,f,(u,p)=>{if(N.isArray(u))return u.concat(p)})),e,t.discriminator,a)}if(t.anyOf)return M(t.anyOf,e,void 0,a);if((o=t.discriminator)!=null&&o.mapping){const i=t.discriminator.mapping;return M(Object.values(i).map(f=>({$ref:f})),e,void 0,a)}if(t.allOf){const i=[];for(const f of t.allOf)if(v(f)&&e.discriminatingSchemas.has(T(f,e))){const p=T(f,e).discriminator,y=Object.entries((c=p.mapping)!=null?c:{}).filter(([,l])=>T({$ref:l},e)===t).map(([l])=>l);y.length>0&&i.push(n.factory.createTypeLiteralNode([s.createPropertySignature({name:p.propertyName,type:be(e,f,p.propertyName,y)})])),i.push(W(f,e,a,!0))}else i.push(w(e,F({required:t.required},f),void 0,a));return(t.properties||t.additionalProperties)&&i.push(ue(t.properties||{},e,t.required,t.additionalProperties,a)),n.factory.createIntersectionTypeNode(i)}if(Array.isArray(t.type))return n.factory.createUnionTypeNode(t.type.map(i=>{const f=ae(F({},t),{type:i});return"items"in f&&i!=="array"&&delete f.items,"properties"in f&&i!=="object"&&delete f.properties,Te(e,f,r,a)}));if("items"in t){const i=t.items;if(i&&!v(i)&&i.enum){const f=_(e.opts);let u;return f!=="union"&&K(i,r)?u=f==="as-const"?Z(i,r,e):J(i,r,e):u=s.createEnumTypeNode(i.enum),n.factory.createArrayTypeNode(u)}return n.factory.createArrayTypeNode(w(e,t.items,void 0,a))}if("prefixItems"in t&&Array.isArray(t.prefixItems))return n.factory.createTupleTypeNode(t.prefixItems.map(i=>w(e,i)));if(t.properties||t.additionalProperties)return ue(t.properties||{},e,t.required,t.additionalProperties,a);if(t.enum){const i=_(e.opts);return i!=="union"&&K(t,r)?i==="as-const"?Z(t,r,e):J(t,r,e):s.createEnumTypeNode(t.enum)}if(t.format=="binary")return n.factory.createTypeReferenceNode("Blob",[]);if("const"in t&&t.const)return G([t.const]);if(t.type!==void 0){if(t.type===null)return s.keywordType.null;if(We(t.type))return s.keywordType[t.type]}return U(e)}function We(e){return e in s.keywordType}function H(e,t){if(e.content){const r=Q(e.content);return w(t,r)}return w(t,v(e)?e:e.schema)}function Je(e,t){if(!t)return"text";const r=Object.values(t).map(o=>T(o,e));return r.some(o=>{var c;return Object.keys((c=o.content)!=null?c:{}).length>0})?r.some(o=>{var i;return Object.keys((i=o.content)!=null?i:{}).some(Y)})?"json":r.some(o=>{var c;return Object.keys((c=o.content)!=null?c:[]).some(i=>i.startsWith("text/"))})?"text":"blob":"text"}function Ze(e,t,r){return n.factory.createUnionTypeNode(Object.entries(e).map(([a,o])=>{const c=a==="default"?s.keywordType.number:n.factory.createLiteralTypeNode(n.factory.createNumericLiteral(a)),i=[s.createPropertySignature({name:"status",type:c})],f=Ge(o,t,r);return f!==s.keywordType.void&&i.push(s.createPropertySignature({name:"data",type:f})),n.factory.createTypeLiteralNode(i)}))}function Ge(e,t,r){const a=T(e,t);return!a||!a.content?s.keywordType.void:w(t,Q(a.content),void 0,r)}const Ye=["positional","object"];function Xe(e,t,r,a,o,c){var ne;const{operationId:i,requestBody:f,responses:u,summary:p,description:y,tags:l}=r;if(Le(o,l))return[];const{primaryName:d,deprecatedLegacyName:O}=ke(e,t,i),b=se(o,a.parameters);for(const m of se(o,r.parameters))b.find(E=>E.name===m.name&&E.in===m.in)||b.push(m);const I=new Map;N.sortBy(b,"name.length").forEach(m=>{const S=s.toIdentifier(m.name),L=[...I.values()].includes(S)?N.upperFirst(m.in):"";I.set(m,S+L)});const h=m=>{const S=I.get(m);if(!S)throw new Error(`Can't find parameter: ${m.name}`);return S},P=[];let j,A;switch((ne=o.opts.argumentStyle)!=null?ne:"positional"){case"positional":const[m,S]=N.partition(b,"required"),E=m.map(g=>s.createParameter(h(T(g,o)),{type:H(g,o)}));if(P.push(...E),f){j=T(f,o);const g=Q(j.content),$=w(o,g,void 0,"writeOnly");A=s.toIdentifier($.name||fe(g)||"body"),P.push(s.createParameter(A,{type:$,questionToken:!j.required}))}S.length&&P.push(s.createParameter(s.createObjectBinding(S.map(g=>T(g,o)).map(g=>({name:h(g)}))),{initializer:n.factory.createObjectLiteralExpression(),type:n.factory.createTypeLiteralNode(S.map(g=>s.createPropertySignature({name:h(T(g,o)),questionToken:!0,type:H(g,o)})))}));break;case"object":const L=b.map(g=>s.createPropertySignature({name:h(T(g,o)),questionToken:!g.required,type:H(g,o)}));if(f){j=T(f,o);const g=Q(j.content),$=w(o,g,void 0,"writeOnly");A=s.toIdentifier($.name||fe(g)||"body"),L.push(s.createPropertySignature({name:A,questionToken:!j.required,type:$}))}if(L.length===0)break;P.push(s.createParameter(s.createObjectBinding([...b.map(g=>T(g,o)).map(g=>({name:h(g)})),...A?[{name:A}]:[]]),{type:n.factory.createTypeLiteralNode(L)}));break}P.push(s.createParameter("opts",{type:n.factory.createTypeReferenceNode("Oazapfts.RequestOpts",void 0),questionToken:!0}));const z=Je(o,u),V=b.filter(m=>m.in==="query"),X=b.filter(m=>m.in==="header");let x;if(V.length){const m=N.groupBy(V,qe);x=ce("query",Object.entries(m).map(([S,E])=>{const L=c.querySerializerArgs.call([s.createObjectLiteral(E.map(g=>[g.name,h(g)]))],{method:e,path:t,operation:r,pathItem:a,formatter:S,parameters:E,query:V},o);return ce(S,L)}))}const we=De(t,x),R=[n.factory.createSpreadAssignment(n.factory.createIdentifier("opts"))];e!=="GET"&&R.push(n.factory.createPropertyAssignment("method",n.factory.createStringLiteral(e))),A&&R.push(s.createPropertyAssignment("body",n.factory.createIdentifier(A))),X.length&&R.push(n.factory.createPropertyAssignment("headers",q("mergeHeaders",[n.factory.createPropertyAccessChain(n.factory.createIdentifier("opts"),n.factory.createToken(n.SyntaxKind.QuestionDotToken),"headers"),n.factory.createObjectLiteralExpression([...X.map(m=>s.createPropertyAssignment(m.name,n.factory.createIdentifier(h(m))))],!0)])));const ee=[we];if(R.length){const m=Ue(j),S=n.factory.createObjectLiteralExpression(R,!0);ee.push(m?q(m,[S]):S)}const te=s.block(n.factory.createReturnStatement(Be(q({json:"fetchJson",text:"fetchText",blob:"fetchBlob"}[z],ee,z==="json"||z==="blob"?[Ze(u,o,"readOnly")||n.SyntaxKind.AnyKeyword]:void 0),o))),re=[s.addComment(s.createFunctionDeclaration(d,{modifiers:[s.modifier.export]},P,te),p||y)];if(O&&!o.opts.futureStripLegacyMethods){const m=[`@deprecated Use {@link ${d}} instead.`,p||y].filter(Boolean).join(`
|
|
2
|
+
`);re.push(s.addComment(s.createFunctionDeclaration(O,{modifiers:[s.modifier.export]},P,te),m))}return re}function xe(e){if(typeof e=="string")return n.factory.createImportDeclaration(void 0,void 0,n.factory.createStringLiteral(e));if(e.length===2&&typeof e[0]=="object"&&"namespace"in e[0]){const[{namespace:t},{from:r}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,void 0,n.factory.createNamespaceImport(n.factory.createIdentifier(t))),n.factory.createStringLiteral(r))}if(e.length===2&&typeof e[0]=="string"&&typeof e[1]=="object"&&"from"in e[1]){const[t,{from:r}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,n.factory.createIdentifier(t),void 0),n.factory.createStringLiteral(r))}if(e.length===2&&Array.isArray(e[0])){const[t,{from:r}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,void 0,n.factory.createNamedImports(t.map(pe))),n.factory.createStringLiteral(r))}if(e.length===3){const[t,r,{from:a}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,n.factory.createIdentifier(t),n.factory.createNamedImports(r.map(pe))),n.factory.createStringLiteral(a))}throw new Error(`Invalid import format: ${JSON.stringify(e)}`)}function pe(e){return typeof e=="string"?n.factory.createImportSpecifier(!1,void 0,n.factory.createIdentifier(e)):n.factory.createImportSpecifier(!1,e.as?n.factory.createIdentifier(e.name):void 0,n.factory.createIdentifier(e.as||e.name))}function et(e){const t=[];return t.push(n.factory.createPropertyAssignment("headers",e.headers?n.factory.createObjectLiteralExpression(Object.entries(e.headers).filter(([,r])=>r!==void 0).map(([r,a])=>n.factory.createPropertyAssignment(n.factory.createStringLiteral(r),tt(a)))):n.factory.createObjectLiteralExpression([]))),e.baseUrl!==void 0&&t.push(n.factory.createPropertyAssignment("baseUrl",n.factory.createStringLiteral(e.baseUrl))),e.fetch&&t.push(n.factory.createPropertyAssignment("fetch",e.fetch)),e.FormData&&t.push(n.factory.createPropertyAssignment("FormData",e.FormData)),n.factory.createVariableStatement([n.factory.createModifier(n.SyntaxKind.ExportKeyword)],n.factory.createVariableDeclarationList([n.factory.createVariableDeclaration("defaults",void 0,n.factory.createTypeReferenceNode(n.factory.createQualifiedName(n.factory.createIdentifier("Oazapfts"),"Defaults"),[n.factory.createTypeReferenceNode(n.factory.createQualifiedName(n.factory.createIdentifier("Oazapfts"),"CustomHeaders"))]),n.factory.createObjectLiteralExpression(t,!0))],n.NodeFlags.Const))}function tt(e){return e===null?n.factory.createNull():typeof e=="boolean"?e?n.factory.createTrue():n.factory.createFalse():typeof e=="number"?n.factory.createNumericLiteral(e):n.factory.createStringLiteral(String(e))}function rt(e,t){return C(this,null,function*(){var o;je(e),yield t.prepare.promise(e);const r=[];for(const[c,i]of Object.entries(e.spec.paths||{}))if(i)for(const[f,u]of Object.entries(i)){if(!u)continue;const p=f.toUpperCase();if(!Me(p))continue;let y=Xe(p,c,u,i,e,t);y=yield t.generateMethod.promise(y,{method:p,path:c,operation:u,pathItem:i},e),r.push(...y)}if(e.opts.allSchemas&&((o=e.spec.components)!=null&&o.schemas))for(const[c,i]of Object.entries(e.spec.components.schemas))W({$ref:`#/components/schemas/${c}`},e,i);let a=nt(e,r);return a=yield t.astGenerated.promise(a,e),a})}function nt(e,t){let r=[...e.imports.map(xe),et(e.defaults),...e.init,s.createServersStatement(e.servers),...e.aliases,...He(t),...e.enumAliases];if(e.banner&&r.length>0){const a=`*
|
|
3
|
+
* ${e.banner.split(`
|
|
4
|
+
`).join(`
|
|
5
|
+
* `)}
|
|
6
|
+
`;r[0]=n.addSyntheticLeadingComment(r[0],n.SyntaxKind.MultiLineCommentTrivia,a,!0)}return n.factory.createSourceFile(r,n.factory.createToken(n.SyntaxKind.EndOfFileToken),n.NodeFlags.None)}function ot(e,t){return e.some(r=>{const a=r.schema&&T(r.schema,t);return!!a&&typeof a=="object"&&a.type==="boolean"})}function it(){return B.UNSTABLE_createPlugin(e=>{e.querySerializerArgs.tap("numericBooleanQueryParameters",(t,r,a)=>!a.opts.numericBooleanQueryParameters||!ot(r.query,a)?t:[...t,n.factory.createPropertyAccessExpression(n.factory.createIdentifier("QS"),"numericBooleanReserved")])},{precedence:B.UNSTABLE_OAZAPFTS_PLUGIN_PRECEDENCE.LAZY})}function at(e){return[it()]}function st(r){return C(this,arguments,function*(e,t={}){const a=yield Ne(e),o=s.createContext(a,t);o.banner=[a.info.title,a.info.version,o.banner].filter(Boolean).join(`
|
|
7
|
+
`);const c=yield Oe(o,t.UNSTABLE_plugins);return Se(c)})}function Oe(r){return C(this,arguments,function*(e,t=[]){const a=B.UNSTABLE_createHooks();return yield B.UNSTABLE_applyPlugins(a,[...at(),...t]),rt(e,a)})}function Se(e){return s.printFile(e)}function Ne(e){return C(this,null,function*(){typeof e=="string"&&e.startsWith("http")&&(e=yield(yield fetch(e)).json());const t=yield Pe.bundle(e);if(!ct(t))throw new Error(`Only OpenAPI v3 is supported
|
|
8
|
+
You may convert you spec with https://github.com/swagger-api/swagger-converter or swagger2openapi package`);return t})}function ct(e){return"openapi"in e&&e.openapi.startsWith("3")}exports.argumentStyleOptions=Ye;exports.enumStyleOptions=Qe;exports.generateAst=Oe;exports.generateSource=st;exports.parseSpec=Ne;exports.printAst=Se;
|
|
9
|
+
//# sourceMappingURL=index-ClBTKGtv.cjs.map
|