oazapfts 7.0.0 → 7.1.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 +3 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +26 -22
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +1 -0
- package/dist/index-BM1c7__L.cjs +8 -0
- package/dist/{index-BTckgXdX.cjs.map → index-BM1c7__L.cjs.map} +1 -1
- package/dist/{index-0o7BUGZA.js → index-TF3n0ut8.js} +350 -346
- package/dist/{index-0o7BUGZA.js.map → index-TF3n0ut8.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/plugin.d.ts +1 -0
- package/package.json +3 -3
- package/dist/index-BTckgXdX.cjs +0 -8
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ Options:
|
|
|
39
39
|
--useUnknown
|
|
40
40
|
--mergeReadWriteOnly
|
|
41
41
|
--argumentStyle=<positional | object> (default: positional)
|
|
42
|
+
--allSchemas
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
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.
|
|
@@ -55,6 +56,8 @@ Where `<spec>` is the URL or local path of an OpenAPI or Swagger spec (in either
|
|
|
55
56
|
|
|
56
57
|
- `--argumentStyle` if "object" generated functions take single object style argument for parameters and requestBody, by default it's "positional" and parameters are separate as positional arguments
|
|
57
58
|
|
|
59
|
+
- `--allSchemas` generate types for all schemas included in the spec
|
|
60
|
+
|
|
58
61
|
## Consuming the generated API
|
|
59
62
|
|
|
60
63
|
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 g=(i,c,s)=>new Promise((l,t)=>{var a=e=>{try{n(s.next(e))}catch(o){t(o)}},u=e=>{try{n(s.throw(e))}catch(o){t(o)}},n=e=>e.done?l(e.value):Promise.resolve(e.value).then(a,u);n((s=s.apply(i,c)).next())});const y=require("fs/promises"),x=require("minimist"),v=require("path"),r=require("./index-BM1c7__L.cjs");function O(i){return g(this,null,function*(){const{include:c,exclude:s,optimistic:l,useEnumType:t,mergeReadWriteOnly:a,useUnknown:u,argumentStyle:n,allSchemas:e,help:o,version:h}=i,[p,m]=i._;if(o&&(f(),process.exit(0)),h){const S=JSON.parse(yield y.readFile(v.join(__dirname,"..","package.json"),"utf8"));console.log(S.version),process.exit(0)}p||(f(),process.exit(1)),n!==void 0&&!r.argumentStyleOptions.includes(n)&&(console.error(`--argumentStyle should be one of <${r.argumentStyleOptions.join(" | ")}>, but got "${n}"`),process.exit(1));const d=yield r.generateSource(p,{include:c,exclude:s,optimistic:l,useEnumType:t,useUnknown:u,mergeReadWriteOnly:a,argumentStyle:n,allSchemas:e});m?yield y.writeFile(m,d):console.log(d)})}function f(){console.error(`
|
|
3
3
|
Usage:
|
|
4
4
|
oazapfts <spec> [filename]
|
|
5
5
|
|
|
@@ -13,5 +13,6 @@
|
|
|
13
13
|
--useUnknown
|
|
14
14
|
--mergeReadWriteOnly
|
|
15
15
|
--argumentStyle=<${r.argumentStyleOptions.join(" | ")}> (default: positional)
|
|
16
|
-
|
|
16
|
+
--allSchemas
|
|
17
|
+
`)}O(x(process.argv.slice(2),{alias:{h:"help",v:"version",i:"include",e:"exclude"},boolean:["help","version","optimistic","useEnumType","mergeReadWriteOnly","useUnknown","allSchemas"],string:["argumentStyle"]})).catch(i=>{console.error(i),process.exit(1)});
|
|
17
18
|
//# 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 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 });\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`);\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 ],\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","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";mUASA,SAAeA,EAAIC,EAAkB,QAAAC,EAAA,sBACnC,KAAM,CACJ,QAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,mBAAAC,EACA,WAAAC,EACA,cAAAC,EACA,KAAAC,EACA,QAAAC,CAAA,
|
|
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 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 });\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`);\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 ],\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","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";mUASA,SAAeA,EAAIC,EAAkB,QAAAC,EAAA,sBACnC,KAAM,CACJ,QAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,mBAAAC,EACA,WAAAC,EACA,cAAAC,EACA,WAAAC,EACA,KAAAC,EACA,QAAAC,CAAA,EACEX,EACE,CAACY,EAAMC,CAAI,EAAIb,EAAK,EAO1B,GALIU,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,GAIdN,IAAkB,QAClB,CAACU,EAAAA,qBAAqB,SAASV,CAAa,IAE5C,QAAQ,MACN,qCAAqCU,EAAAA,qBAAqB,KACxD,KAAA,CACD,eAAeV,CAAa,GAAA,EAE/B,QAAQ,KAAK,CAAC,GAGhB,MAAMW,EAAO,MAAMC,EAAAA,eAAeR,EAAM,CACtC,QAAAV,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,WAAAE,EACA,mBAAAD,EACA,cAAAE,EACA,WAAAC,CAAA,CACD,EAEGI,EAAM,MAAMQ,YAAUR,EAAMM,CAAI,EAC/B,QAAQ,IAAIA,CAAI,CACvB,GAEA,SAASL,GAAa,CACpB,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAaOI,EAAAA,qBAAqB,KAAK,KAAK,CAAC;AAAA;AAAA,CAEtD,CACD,CAEAnB,EACEuB,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,YAAA,EAEF,OAAQ,CAAC,eAAe,CAAA,CACzB,CACH,EAAE,MAAOC,GAAU,CACjB,QAAQ,MAAMA,CAAK,EACnB,QAAQ,KAAK,CAAC,CAChB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { join as
|
|
5
|
-
import { a as i, g as w } from "./index-
|
|
6
|
-
async function
|
|
2
|
+
import { readFile as h, writeFile as S } from "fs/promises";
|
|
3
|
+
import v from "minimist";
|
|
4
|
+
import { join as x } from "path";
|
|
5
|
+
import { a as i, g as w } from "./index-TF3n0ut8.js";
|
|
6
|
+
async function O(e) {
|
|
7
7
|
const {
|
|
8
|
-
include:
|
|
9
|
-
exclude:
|
|
10
|
-
optimistic:
|
|
8
|
+
include: l,
|
|
9
|
+
exclude: a,
|
|
10
|
+
optimistic: c,
|
|
11
11
|
useEnumType: u,
|
|
12
12
|
mergeReadWriteOnly: p,
|
|
13
13
|
useUnknown: m,
|
|
14
14
|
argumentStyle: o,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
allSchemas: d,
|
|
16
|
+
help: g,
|
|
17
|
+
version: f
|
|
17
18
|
} = e, [n, s] = e._;
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
await
|
|
19
|
+
if (g && (r(), process.exit(0)), f) {
|
|
20
|
+
const y = JSON.parse(
|
|
21
|
+
await h(x(__dirname, "..", "package.json"), "utf8")
|
|
21
22
|
);
|
|
22
|
-
console.log(
|
|
23
|
+
console.log(y.version), process.exit(0);
|
|
23
24
|
}
|
|
24
25
|
n || (r(), process.exit(1)), o !== void 0 && !i.includes(o) && (console.error(
|
|
25
26
|
`--argumentStyle should be one of <${i.join(
|
|
@@ -27,15 +28,16 @@ async function S(e) {
|
|
|
27
28
|
)}>, but got "${o}"`
|
|
28
29
|
), process.exit(1));
|
|
29
30
|
const t = await w(n, {
|
|
30
|
-
include:
|
|
31
|
-
exclude:
|
|
32
|
-
optimistic:
|
|
31
|
+
include: l,
|
|
32
|
+
exclude: a,
|
|
33
|
+
optimistic: c,
|
|
33
34
|
useEnumType: u,
|
|
34
35
|
useUnknown: m,
|
|
35
36
|
mergeReadWriteOnly: p,
|
|
36
|
-
argumentStyle: o
|
|
37
|
+
argumentStyle: o,
|
|
38
|
+
allSchemas: d
|
|
37
39
|
});
|
|
38
|
-
s ? await
|
|
40
|
+
s ? await S(s, t) : console.log(t);
|
|
39
41
|
}
|
|
40
42
|
function r() {
|
|
41
43
|
console.error(`
|
|
@@ -52,10 +54,11 @@ function r() {
|
|
|
52
54
|
--useUnknown
|
|
53
55
|
--mergeReadWriteOnly
|
|
54
56
|
--argumentStyle=<${i.join(" | ")}> (default: positional)
|
|
57
|
+
--allSchemas
|
|
55
58
|
`);
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
O(
|
|
61
|
+
v(process.argv.slice(2), {
|
|
59
62
|
alias: {
|
|
60
63
|
h: "help",
|
|
61
64
|
v: "version",
|
|
@@ -68,7 +71,8 @@ S(
|
|
|
68
71
|
"optimistic",
|
|
69
72
|
"useEnumType",
|
|
70
73
|
"mergeReadWriteOnly",
|
|
71
|
-
"useUnknown"
|
|
74
|
+
"useUnknown",
|
|
75
|
+
"allSchemas"
|
|
72
76
|
],
|
|
73
77
|
string: ["argumentStyle"]
|
|
74
78
|
})
|
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 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 });\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`);\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 ],\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","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";;;;;AASA,eAAeA,EAAIC,GAAkB;AACnC,QAAM;AAAA,IACJ,SAAAC;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,eAAAC;AAAA,IACA,MAAAC;AAAA,IACA,SAAAC;AAAA,EAAA,
|
|
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 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 });\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`);\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 ],\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","help","version","spec","dest","printUsage","pkg","readFile","join","argumentStyleOptions","code","generateSource","writeFile","minimist","error"],"mappings":";;;;;AASA,eAAeA,EAAIC,GAAkB;AACnC,QAAM;AAAA,IACJ,SAAAC;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,eAAAC;AAAA,IACA,YAAAC;AAAA,IACA,MAAAC;AAAA,IACA,SAAAC;AAAA,EAAA,IACEV,GACE,CAACW,GAAMC,CAAI,IAAIZ,EAAK;AAO1B,MALIS,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,IAIdN,MAAkB,UAClB,CAACU,EAAqB,SAASV,CAAa,MAE5C,QAAQ;AAAA,IACN,qCAAqCU,EAAqB;AAAA,MACxD;AAAA,IAAA,CACD,eAAeV,CAAa;AAAA,EAAA,GAE/B,QAAQ,KAAK,CAAC;AAGhB,QAAMW,IAAO,MAAMC,EAAeR,GAAM;AAAA,IACtC,SAAAV;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC;AAAA,IACA,YAAAE;AAAA,IACA,oBAAAD;AAAA,IACA,eAAAE;AAAA,IACA,YAAAC;AAAA,EAAA,CACD;AAED,EAAII,IAAM,MAAMQ,EAAUR,GAAMM,CAAI,IAC/B,QAAQ,IAAIA,CAAI;AACvB;AAEA,SAASL,IAAa;AACpB,UAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAaOI,EAAqB,KAAK,KAAK,CAAC;AAAA;AAAA,CAEtD;AACD;AAEAlB;AAAA,EACEsB,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,IAAA;AAAA,IAEF,QAAQ,CAAC,eAAe;AAAA,EAAA,CACzB;AACH,EAAE,MAAM,CAACC,MAAU;AACjB,UAAQ,MAAMA,CAAK,GACnB,QAAQ,KAAK,CAAC;AAChB,CAAC;"}
|
package/dist/context.d.ts
CHANGED
|
@@ -168,6 +168,7 @@ declare type OazapftsOptions = {
|
|
|
168
168
|
mergeReadWriteOnly?: boolean;
|
|
169
169
|
useUnknown?: boolean;
|
|
170
170
|
argumentStyle?: ArgumentStyle;
|
|
171
|
+
allSchemas?: boolean;
|
|
171
172
|
/**
|
|
172
173
|
* Plugins to apply during code generation.
|
|
173
174
|
* Each plugin receives hooks and can tap into generation steps.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";var me=Object.defineProperty,ge=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var X=(e,r,t)=>r in e?me(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,R=(e,r)=>{for(var t in r||(r={}))Oe.call(r,t)&&X(e,t,r[t]);if(Z)for(var t of Z(r))be.call(r,t)&&X(e,t,r[t]);return e},x=(e,r)=>ge(e,Te(r));var $=(e,r,t)=>new Promise((a,o)=>{var s=p=>{try{c(t.next(p))}catch(u){o(u)}},i=p=>{try{c(t.throw(p))}catch(u){o(u)}},c=p=>p.done?a(p.value):Promise.resolve(p.value).then(s,i);c((t=t.apply(e,r)).next())});const f=require("./context-lKBK5qCf.cjs"),we=require("@apidevtools/swagger-parser"),n=require("typescript"),v=require("lodash"),ee=require("./plugin.cjs");function k(e){return e.replace(/.+\//,"")}function h(e){return typeof e=="object"&&e!==null&&"$ref"in e}function ae(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(r=>decodeURI(r.replace(/~1/g,"/").replace(/~0/g,"~")))}function g(e,{spec:r}){if(!h(e))return e;const t=e.$ref,a=ae(t),o=v.get(r,a);if(typeof o=="undefined")throw new Error(`Can't find ${a}`);return o}function re(e,r){return r?r.map(t=>g(t,e)):[]}function Se(e){var o;if(!((o=e.spec.components)!=null&&o.schemas))return;const r="#/components/schemas/",t=e.spec.components.schemas;for(const s of Object.keys(t)){const i=t[s];h(i)||typeof i=="boolean"||i.discriminator&&!i.oneOf&&!i.anyOf&&e.discriminatingSchemas.add(i)}const a=(s,i)=>Object.values(s.mapping||{}).includes(i);for(const s of Object.keys(t)){const i=t[s];if(!(h(i)||typeof i=="boolean"||!i.allOf))for(const c of i.allOf){if(!h(c)||!e.discriminatingSchemas.has(g(c,e)))continue;const p=t[k(c.$ref)];if(h(p))throw new Error("Unexpected nested reference");const u=p.discriminator;a(u,r+s)||(u.mapping||(u.mapping={}),u.mapping[s]=r+s)}}}function Ne(e,r){var a;return r&&r.some(o=>{var s,i;return(i=(s=e.opts)==null?void 0:s.exclude)==null?void 0:i.includes(o)})?!0:(a=e.opts)!=null&&a.include?!(r&&r.some(s=>{var i;return(i=e.opts.include)==null?void 0:i.includes(s)})):!1}function he(e,r,t){const a=ve(t);return a||(r=r.replace(/\{(.+?)\}/,"by $1").replace(/\{(.+?)\}/,"and $1"),f.toIdentifier(`${e} ${r}`))}function ve(e){if(e&&!e.match(/[^\w\s]/)&&(e=v.camelCase(e),f.isValidIdentifier(e)))return e}const se={"*/*":"json","application/json":"json","application/x-www-form-urlencoded":"form","multipart/form-data":"multipart"};function Ie(e){return typeof e=="string"&&/^[^/]+\/[^/]+$/.test(e)}function z(e){return se[e]==="json"||/\bjson\b/i.test(e)}function Ae({style:e="form",explode:r=!0,content:t}){if(t){const a=Object.keys(t);if(a.length!==1)throw new Error("Parameters with content property must specify one media type");if(!z(a[0]))throw new Error("Parameters with content property must specify a JSON compatible media type");return"json"}return r&&e==="deepObject"?"deep":r?"explode":e==="spaceDelimited"?"space":e==="pipeDelimited"?"pipe":"form"}function te(e,r){return f.createCall(n.factory.createPropertyAccessExpression(n.factory.createIdentifier("QS"),e),{args:r})}function Ee(e,r){const t=[],a=e.replace(/(.*?)\{(.+?)\}(.*?)(?=\{|$)/g,(o,s,i,c)=>{const p=f.toIdentifier(i);return t.push({expression:f.createCall(n.factory.createIdentifier("encodeURIComponent"),{args:[n.factory.createIdentifier(p)]}),literal:c}),s});return r&&t.push({expression:r,literal:""}),f.createTemplateString(a,t)}function q(e,r,t){return f.createCall(n.factory.createPropertyAccessExpression(n.factory.createIdentifier("oazapfts"),e),{args:r,typeArgs:t})}function je(e){if(e!=null&&e.content)for(const r of Object.keys(e.content)){const t=se[r];if(t)return t;if(z(r))return"json"}}function ke(e,r){var t;return(t=r.opts)!=null&&t.optimistic?q("ok",[e]):e}function ne(e){if(h(e))return k(e.$ref)}function Pe(e,r){const t=o=>{try{return g({$ref:o},r),!1}catch(s){return!0}};if(t(e))return e;let a=2;for(;;){const o=e+String(a);if(t(o))return o;a+=1}}function Le(e){const r=k(e);return/^\d+/.test(r)?ae(e).join("_"):r}function D(e,r,t){return!!(typeof e!="boolean"&&e.enum&&r.opts.useEnumType&&t&&e.type!=="boolean")}function F(e,r){let t=r.typeAliases[e]||0;return t&&(r.typeAliases[e]=++t,e+=t),r.typeAliases[e]=1,e}function fe(e,r,t=!0){if(r.opts.mergeReadWriteOnly)return{readOnly:!1,writeOnly:!1};const a=(o,s)=>{var u,l,y,T,O,S;if(h(o)){if(!t)return{readOnly:!1,writeOnly:!1};if(s.has(o.$ref))return{readOnly:!1,writeOnly:!1};const I=r.refsOnlyMode.get(o.$ref);if(I)return I;s.add(o.$ref);const N=a(g(o,r),s);return s.delete(o.$ref),r.refsOnlyMode.set(o.$ref,N),N}if(typeof o=="boolean")return{readOnly:!1,writeOnly:!1};let i=(u=o.readOnly)!=null?u:!1,c=(l=o.writeOnly)!=null?l:!1;const p=[];"items"in o&&o.items?p.push(o.items):(p.push(...Object.values((y=o.properties)!=null?y:{})),p.push(...(T=o.allOf)!=null?T:[]),p.push(...(O=o.anyOf)!=null?O:[]),p.push(...(S=o.oneOf)!=null?S:[]));for(const I of p){if(i&&c)break;const N=a(I,s);i=i||N.readOnly,c=c||N.writeOnly}return{readOnly:i,writeOnly:c}};return a(e,new Set)}function $e(e){return typeof e=="boolean"?e:e&&"nullable"in e?!h(e)&&e.nullable:!1}const Re=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"];function qe(e){return Re.includes(e)}function Fe(e){const r={};return e.map(t=>{var o;const a=(o=t.name)==null?void 0:o.text;if(a){if(r[a])return f.updateFunctionDeclaration(t,{name:n.factory.createIdentifier(`${a}${++r[a]}`)});r[a]=1}return t})}function U(e){const r=Object.keys(e).find(Ie);if(r){const{schema:t}=e[r];if(t)return t}return Object.keys(e).length===0||Object.keys(e).some(t=>t.startsWith("text/"))?{type:"string"}:{type:"string",format:"binary"}}function V(e,r,t,a){var s;const o=a?Pe(e.$ref+"Base",r):e.$ref;if(!r.refs[o]){let i=g(e,r);typeof i!="boolean"&&a&&(i=v.cloneDeep(i),delete i.discriminator);const c=typeof i!="boolean"&&i.title||Le(o),p=f.toIdentifier(c,!0);if(D(i,r,c))return b(r,i,c);const u=F(p,r);r.refs[o]={base:n.factory.createTypeReferenceNode(u,void 0),readOnly:void 0,writeOnly:void 0};const l=b(r,i,void 0);r.aliases.push(f.createTypeAliasDeclaration({modifiers:[f.modifier.export],name:u,type:l}));const{readOnly:y,writeOnly:T}=fe(i,r);if(y){const O=F(f.toIdentifier(c,!0,"readOnly"),r);r.refs[o].readOnly=n.factory.createTypeReferenceNode(O,void 0);const S=b(r,i,c,"readOnly");r.aliases.push(f.createTypeAliasDeclaration({modifiers:[f.modifier.export],name:O,type:S}))}if(T){const O=F(f.toIdentifier(c,!0,"writeOnly"),r);r.refs[o].writeOnly=n.factory.createTypeReferenceNode(O,void 0);const S=b(r,i,c,"writeOnly");r.aliases.push(f.createTypeAliasDeclaration({modifiers:[f.modifier.export],name:O,type:S}))}}return(s=r.refs[o][t||"base"])!=null?s:r.refs[o].base}function H(e,r,t){if(typeof e=="boolean")throw new Error("cannot get enum from boolean schema. schema must be an object");const o=(e.title||v.upperFirst(r)).split(/[^A-Za-z0-9$_]/g).map(y=>v.upperFirst(y)).join(""),s=Ce(e.enum?e.enum:[]),i=De(o,s,t);if(t.enumRefs[o]&&o===i)return t.enumRefs[o].type;const c=e.enum?e.enum:[],p=Ue(e,c),u=c.map((y,T)=>{if(e.type==="number"||e.type==="integer"||e.type==="string"){const O=p?p[T]:String(y);return n.factory.createEnumMember(n.factory.createIdentifier(f.toIdentifier(O,!0)),f.createLiteral(y))}return n.factory.createEnumMember(n.factory.createIdentifier(f.toIdentifier(y,!0)),f.createLiteral(y))});t.enumAliases.push(n.factory.createEnumDeclaration([f.modifier.export],i,u));const l=n.factory.createTypeReferenceNode(i,void 0);return t.enumRefs[o]={values:s,type:n.factory.createTypeReferenceNode(i,void 0)},l}function Ce(e){return e.join("_")}function De(e,r,t){return t.enumRefs[e]&&t.enumRefs[e].values==r?e:F(e,t)}function Ue(e,r){const t="x-enumNames"in e?e["x-enumNames"]:"x-enum-varnames"in e?e["x-enum-varnames"]:void 0;if(t){if(!Array.isArray(t))throw new Error("enum names must be an array");if(t.length!==r.length)throw new Error("enum names must have the same length as enum values");if(t.some(a=>typeof a!="string"))throw new Error("enum names must be an array of strings");return t}}function _(e){const r=e.map(t=>{if(t===null)return f.keywordType.null;if(typeof t=="boolean")return t?n.factory.createLiteralTypeNode(n.factory.createToken(n.SyntaxKind.TrueKeyword)):n.factory.createLiteralTypeNode(n.factory.createToken(n.SyntaxKind.FalseKeyword));if(typeof t=="number")return n.factory.createLiteralTypeNode(n.factory.createNumericLiteral(t));if(typeof t=="string")return n.factory.createLiteralTypeNode(n.factory.createStringLiteral(t));throw new Error(`Unexpected ${String(t)} of type ${typeof t} in enum`)});return r.length>1?n.factory.createUnionTypeNode(r):r[0]}function ce(e,r,t,a){var p,u;if(!e.opts.useEnumType)return _(a);const o=g(r,e);let s=g((p=o.properties)==null?void 0:p[t],e);if(!s&&o.allOf)for(const l of o.allOf){const y=g(l,e);if((u=y.properties)!=null&&u[t]){s=g(y.properties[t],e);break}}if(!s||!D(s,e,t))return _(a);const i=H(s,t,e),c=a.map(l=>n.factory.createTypeReferenceNode(n.factory.createQualifiedName(i.typeName,n.factory.createIdentifier(f.toIdentifier(l,!0)))));return c.length===1?c[0]:n.factory.createUnionTypeNode(c)}function K(e,r,t,a){if(t){if(t.propertyName===void 0)throw new Error("Discriminators require a propertyName");const o=new Set(Object.values(t.mapping||{}).map(k));return n.factory.createUnionTypeNode([...Object.entries(t.mapping||{}).map(([s,i])=>[s,{$ref:i}]),...e.filter(s=>{if(!h(s))throw new Error("Discriminators require references, not inline schemas");return!o.has(k(s.$ref))}).map(s=>{var l,y;const i=k(s.$ref),p=(l=g(s,r).properties)==null?void 0:l[t.propertyName];return[(p&&"enum"in p?(y=p==null?void 0:p.enum)==null?void 0:y[0]:"")||i,s]})].map(([s,i])=>n.factory.createIntersectionTypeNode([n.factory.createTypeLiteralNode([f.createPropertySignature({name:t.propertyName,type:ce(r,i,t.propertyName,[s])})]),b(r,i,void 0,a)])))}else return n.factory.createUnionTypeNode(v.uniq(e.map(o=>b(r,o,void 0,a))))}function C(e){return e.opts.useUnknown?f.keywordType.unknown:f.keywordType.any}function oe(e,r,t,a,o){const c=Object.keys(e).filter(p=>{const u=e[p],{readOnly:l,writeOnly:y}=fe(u,r,!1);switch(o){case"readOnly":return l||!y;case"writeOnly":return y||!l;default:return!l&&!y}}).map(p=>{const u=e[p],l=t&&t.includes(p);let y=b(r,u,p,o);!l&&r.opts.unionUndefined&&(y=n.factory.createUnionTypeNode([y,f.keywordType.undefined]));const T=f.createPropertySignature({questionToken:!l,name:p,type:y});if(typeof u!="boolean"&&"description"in u&&u.description){const O=u.description.replace("*/","*\\/");n.addSyntheticLeadingComment(T,n.SyntaxKind.MultiLineCommentTrivia,`* ${O} `,!0)}return T});if(a){const p=a===!0?C(r):b(r,a,void 0,o);c.push(f.createIndexSignature(p))}return n.factory.createTypeLiteralNode(c)}function b(e,r,t,a){const o=pe(e,r,t,a);return $e(r)?n.factory.createUnionTypeNode([o,f.keywordType.null]):o}function pe(e,r,t,a){var o,s;if(r===void 0)return C(e);if(h(r))return V(r,e,a);if(r===!0)return C(e);if(r===!1)return f.keywordType.never;if(r.oneOf){const i=R({},r);return delete i.oneOf,K(r.oneOf.map(c=>v.mergeWith({},i,c,(p,u)=>{if(v.isArray(p))return p.concat(u)})),e,r.discriminator,a)}if(r.anyOf)return K(r.anyOf,e,void 0,a);if((o=r.discriminator)!=null&&o.mapping){const i=r.discriminator.mapping;return K(Object.values(i).map(c=>({$ref:c})),e,void 0,a)}if(r.allOf){const i=[];for(const c of r.allOf)if(h(c)&&e.discriminatingSchemas.has(g(c,e))){const u=g(c,e).discriminator,l=Object.entries((s=u.mapping)!=null?s:{}).filter(([,y])=>g({$ref:y},e)===r).map(([y])=>y);l.length>0&&i.push(n.factory.createTypeLiteralNode([f.createPropertySignature({name:u.propertyName,type:ce(e,c,u.propertyName,l)})])),i.push(V(c,e,a,!0))}else i.push(b(e,R({required:r.required},c),void 0,a));return(r.properties||r.additionalProperties)&&i.push(oe(r.properties||{},e,r.required,r.additionalProperties,a)),n.factory.createIntersectionTypeNode(i)}if(Array.isArray(r.type))return n.factory.createUnionTypeNode(r.type.map(i=>{const c=x(R({},r),{type:i});return"items"in c&&i!=="array"&&delete c.items,"properties"in c&&i!=="object"&&delete c.properties,pe(e,c,t,a)}));if("items"in r){const i=r.items;if(i&&!h(i)&&i.enum){const c=D(i,e,t)?H(i,t,e):f.createEnumTypeNode(i.enum);return n.factory.createArrayTypeNode(c)}return n.factory.createArrayTypeNode(b(e,r.items,void 0,a))}if("prefixItems"in r&&Array.isArray(r.prefixItems))return n.factory.createTupleTypeNode(r.prefixItems.map(i=>b(e,i)));if(r.properties||r.additionalProperties)return oe(r.properties||{},e,r.required,r.additionalProperties,a);if(r.enum)return D(r,e,t)?H(r,t,e):f.createEnumTypeNode(r.enum);if(r.format=="binary")return n.factory.createTypeReferenceNode("Blob",[]);if("const"in r&&r.const)return _([r.const]);if(r.type!==void 0){if(r.type===null)return f.keywordType.null;if(Be(r.type))return f.keywordType[r.type]}return C(e)}function Be(e){return e in f.keywordType}function M(e,r){if(e.content){const t=U(e.content);return b(r,t)}return b(r,h(e)?e:e.schema)}function Ke(e,r){if(!r)return"text";const t=Object.values(r).map(o=>g(o,e));return t.some(o=>{var s;return Object.keys((s=o.content)!=null?s:{}).length>0})?t.some(o=>{var i;return Object.keys((i=o.content)!=null?i:{}).some(z)})?"json":t.some(o=>{var s;return Object.keys((s=o.content)!=null?s:[]).some(i=>i.startsWith("text/"))})?"text":"blob":"text"}function Me(e,r,t){return n.factory.createUnionTypeNode(Object.entries(e).map(([a,o])=>{const s=a==="default"?f.keywordType.number:n.factory.createLiteralTypeNode(n.factory.createNumericLiteral(a)),i=[f.createPropertySignature({name:"status",type:s})],c=Ve(o,r,t);return c!==f.keywordType.void&&i.push(f.createPropertySignature({name:"data",type:c})),n.factory.createTypeLiteralNode(i)}))}function Ve(e,r,t){const a=g(e,r);return!a||!a.content?f.keywordType.void:b(r,U(a.content),void 0,t)}const He=["positional","object"];function _e(e,r,t,a,o){var Y;const{operationId:s,requestBody:i,responses:c,summary:p,description:u,tags:l}=t;if(Ne(o,l))return[];const y=he(e,r,s),T=re(o,a.parameters);for(const d of re(o,t.parameters))T.find(j=>j.name===d.name&&j.in===d.in)||T.push(d);const O=new Map;v.sortBy(T,"name.length").forEach(d=>{const w=f.toIdentifier(d.name),E=[...O.values()].includes(w)?v.upperFirst(d.in):"";O.set(d,w+E)});const S=d=>{const w=O.get(d);if(!w)throw new Error(`Can't find parameter: ${d.name}`);return w},I=[];let N,A;switch((Y=o.opts.argumentStyle)!=null?Y:"positional"){case"positional":const[d,w]=v.partition(T,"required"),j=d.map(m=>f.createParameter(S(g(m,o)),{type:M(m,o)}));if(I.push(...j),i){N=g(i,o);const m=U(N.content),L=b(o,m,void 0,"writeOnly");A=f.toIdentifier(L.name||ne(m)||"body"),I.push(f.createParameter(A,{type:L,questionToken:!N.required}))}w.length&&I.push(f.createParameter(f.createObjectBinding(w.map(m=>g(m,o)).map(m=>({name:S(m)}))),{initializer:n.factory.createObjectLiteralExpression(),type:n.factory.createTypeLiteralNode(w.map(m=>f.createPropertySignature({name:S(g(m,o)),questionToken:!0,type:M(m,o)})))}));break;case"object":const E=T.map(m=>f.createPropertySignature({name:S(g(m,o)),questionToken:!m.required,type:M(m,o)}));if(i){N=g(i,o);const m=U(N.content),L=b(o,m,void 0,"writeOnly");A=f.toIdentifier(L.name||ne(m)||"body"),E.push(f.createPropertySignature({name:A,questionToken:!N.required,type:L}))}if(E.length===0)break;I.push(f.createParameter(f.createObjectBinding([...T.map(m=>g(m,o)).map(m=>({name:S(m)})),...A?[{name:A}]:[]]),{type:n.factory.createTypeLiteralNode(E)}));break}I.push(f.createParameter("opts",{type:n.factory.createTypeReferenceNode("Oazapfts.RequestOpts",void 0),questionToken:!0}));const B=Ke(o,c),W=T.filter(d=>d.in==="query"),J=T.filter(d=>d.in==="header");let Q;if(W.length){const d=v.groupBy(W,Ae);Q=te("query",Object.entries(d).map(([w,j])=>te(w,[f.createObjectLiteral(j.map(E=>[E.name,S(E)]))])))}const de=Ee(r,Q),P=[n.factory.createSpreadAssignment(n.factory.createIdentifier("opts"))];e!=="GET"&&P.push(n.factory.createPropertyAssignment("method",n.factory.createStringLiteral(e))),A&&P.push(f.createPropertyAssignment("body",n.factory.createIdentifier(A))),J.length&&P.push(n.factory.createPropertyAssignment("headers",q("mergeHeaders",[n.factory.createPropertyAccessChain(n.factory.createIdentifier("opts"),n.factory.createToken(n.SyntaxKind.QuestionDotToken),"headers"),n.factory.createObjectLiteralExpression([...J.map(d=>f.createPropertyAssignment(d.name,n.factory.createIdentifier(S(d))))],!0)])));const G=[de];if(P.length){const d=je(N),w=n.factory.createObjectLiteralExpression(P,!0);G.push(d?q(d,[w]):w)}return[f.addComment(f.createFunctionDeclaration(y,{modifiers:[f.modifier.export]},I,f.block(n.factory.createReturnStatement(ke(q({json:"fetchJson",text:"fetchText",blob:"fetchBlob"}[B],G,B==="json"||B==="blob"?[Me(c,o,"readOnly")||n.SyntaxKind.AnyKeyword]:void 0),o)))),p||u)]}function ze(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:r},{from:t}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,void 0,n.factory.createNamespaceImport(n.factory.createIdentifier(r))),n.factory.createStringLiteral(t))}if(e.length===2&&typeof e[0]=="string"&&typeof e[1]=="object"&&"from"in e[1]){const[r,{from:t}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,n.factory.createIdentifier(r),void 0),n.factory.createStringLiteral(t))}if(e.length===2&&Array.isArray(e[0])){const[r,{from:t}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,void 0,n.factory.createNamedImports(r.map(ie))),n.factory.createStringLiteral(t))}if(e.length===3){const[r,t,{from:a}]=e;return n.factory.createImportDeclaration(void 0,n.factory.createImportClause(!1,n.factory.createIdentifier(r),n.factory.createNamedImports(t.map(ie))),n.factory.createStringLiteral(a))}throw new Error(`Invalid import format: ${JSON.stringify(e)}`)}function ie(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 We(e){const r=[];return r.push(n.factory.createPropertyAssignment("headers",e.headers?n.factory.createObjectLiteralExpression(Object.entries(e.headers).filter(([,t])=>t!==void 0).map(([t,a])=>n.factory.createPropertyAssignment(n.factory.createStringLiteral(t),Je(a)))):n.factory.createObjectLiteralExpression([]))),e.baseUrl!==void 0&&r.push(n.factory.createPropertyAssignment("baseUrl",n.factory.createStringLiteral(e.baseUrl))),e.fetch&&r.push(n.factory.createPropertyAssignment("fetch",e.fetch)),e.FormData&&r.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(r,!0))],n.NodeFlags.Const))}function Je(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 Qe(e,r){return $(this,null,function*(){var o;Se(e),yield r.prepare.promise(e);const t=[];for(const[s,i]of Object.entries(e.spec.paths||{}))if(i)for(const[c,p]of Object.entries(i)){if(!p)continue;const u=c.toUpperCase();if(!qe(u))continue;let l=_e(u,s,p,i,e);l=yield r.generateMethod.promise(l,{method:u,path:s,operation:p,pathItem:i},e),t.push(...l)}if(e.opts.allSchemas&&((o=e.spec.components)!=null&&o.schemas))for(const[s,i]of Object.entries(e.spec.components.schemas))V({$ref:`#/components/schemas/${s}`},e,i);let a=Ge(e,t);return a=yield r.astGenerated.promise(a,e),a})}function Ge(e,r){let t=[...e.imports.map(ze),We(e.defaults),...e.init,f.createServersStatement(e.servers),...e.aliases,...Fe(r),...e.enumAliases];if(e.banner&&t.length>0){const a=`*
|
|
2
|
+
* ${e.banner.split(`
|
|
3
|
+
`).join(`
|
|
4
|
+
* `)}
|
|
5
|
+
`;t[0]=n.addSyntheticLeadingComment(t[0],n.SyntaxKind.MultiLineCommentTrivia,a,!0)}return n.factory.createSourceFile(t,n.factory.createToken(n.SyntaxKind.EndOfFileToken),n.NodeFlags.None)}function Ye(t){return $(this,arguments,function*(e,r={}){const a=yield le(e),o=f.createContext(a,r);o.banner=[a.info.title,a.info.version,o.banner].filter(Boolean).join(`
|
|
6
|
+
`);const s=yield ue(o,r.UNSTABLE_plugins);return ye(s)})}function ue(t){return $(this,arguments,function*(e,r=[]){const a=ee.UNSTABLE_createHooks();return yield ee.UNSTABLE_applyPlugins(a,r),Qe(e,a)})}function ye(e){return f.printFile(e)}function le(e){return $(this,null,function*(){typeof e=="string"&&e.startsWith("http")&&(e=yield(yield fetch(e)).json());const r=yield we.bundle(e);if(!Ze(r))throw new Error(`Only OpenAPI v3 is supported
|
|
7
|
+
You may convert you spec with https://github.com/swagger-api/swagger-converter or swagger2openapi package`);return r})}function Ze(e){return"openapi"in e&&e.openapi.startsWith("3")}exports.argumentStyleOptions=He;exports.generateAst=ue;exports.generateSource=Ye;exports.parseSpec=le;exports.printAst=ye;
|
|
8
|
+
//# sourceMappingURL=index-BM1c7__L.cjs.map
|