oazapfts 7.1.0 → 7.3.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 +5 -0
- package/dist/cli.cjs +6 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +50 -39
- package/dist/cli.js.map +1 -1
- package/dist/{context-j-dMIA6M.js → context-Cu4eE5cx.js} +4 -4
- package/dist/{context-j-dMIA6M.js.map → context-Cu4eE5cx.js.map} +1 -1
- package/dist/context.d.ts +18 -0
- package/dist/context.js +1 -1
- package/dist/index-D2W38DVS.js +1189 -0
- package/dist/index-D2W38DVS.js.map +1 -0
- package/dist/index-DLicGIOu.cjs +9 -0
- package/dist/index-DLicGIOu.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +2 -2
- package/dist/plugin.d.ts +18 -0
- package/package.json +1 -1
- package/dist/index-BM1c7__L.cjs +0 -8
- package/dist/index-BM1c7__L.cjs.map +0 -1
- package/dist/index-TF3n0ut8.js +0 -1089
- package/dist/index-TF3n0ut8.js.map +0 -1
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ Options:
|
|
|
40
40
|
--mergeReadWriteOnly
|
|
41
41
|
--argumentStyle=<positional | object> (default: positional)
|
|
42
42
|
--allSchemas
|
|
43
|
+
--futureStripLegacyMethods
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
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.
|
|
@@ -58,6 +59,10 @@ Where `<spec>` is the URL or local path of an OpenAPI or Swagger spec (in either
|
|
|
58
59
|
|
|
59
60
|
- `--allSchemas` generate types for all schemas included in the spec
|
|
60
61
|
|
|
62
|
+
- `--futureStripLegacyMethods` skip generating deprecated legacy method aliases.
|
|
63
|
+
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
|
+
The next major version will default to this behavior.
|
|
65
|
+
|
|
61
66
|
## Consuming the generated API
|
|
62
67
|
|
|
63
68
|
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 g=(
|
|
2
|
+
"use strict";var g=(t,l,o)=>new Promise((c,u)=>{var i=e=>{try{s(o.next(e))}catch(r){u(r)}},a=e=>{try{s(o.throw(e))}catch(r){u(r)}},s=e=>e.done?c(e.value):Promise.resolve(e.value).then(i,a);s((o=o.apply(t,l)).next())});const y=require("fs/promises"),v=require("minimist"),w=require("path"),n=require("./index-DLicGIOu.cjs");function b(t){return g(this,null,function*(){const{include:l,exclude:o,optimistic:c,useEnumType:u,enumStyle:i,mergeReadWriteOnly:a,useUnknown:s,argumentStyle:e,allSchemas:r,futureStripLegacyMethods:f,help:h,version:x}=t,[p,m]=t._;if(h&&(S(),process.exit(0)),x){const O=JSON.parse(yield y.readFile(w.join(__dirname,"..","package.json"),"utf8"));console.log(O.version),process.exit(0)}p||(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(p,{include:l,exclude:o,optimistic:c,useEnumType:u,enumStyle:i,useUnknown:s,mergeReadWriteOnly:a,argumentStyle:e,allSchemas:r,futureStripLegacyMethods:f});m?yield y.writeFile(m,d):console.log(d)})}function S(){console.error(`
|
|
3
3
|
Usage:
|
|
4
4
|
oazapfts <spec> [filename]
|
|
5
5
|
|
|
@@ -9,10 +9,12 @@
|
|
|
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
|
|
17
|
-
|
|
18
|
+
--futureStripLegacyMethods
|
|
19
|
+
`)}b(v(process.argv.slice(2),{alias:{h:"help",v:"version",i:"include",e:"exclude"},boolean:["help","version","optimistic","useEnumType","mergeReadWriteOnly","useUnknown","allSchemas","futureStripLegacyMethods"],string:["argumentStyle","enumStyle"]})).catch(t=>{console.error(t),process.exit(1)});
|
|
18
20
|
//# 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 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":";
|
|
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 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 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 --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\", \"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","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,yBAAAC,EACA,KAAAC,EACA,QAAAC,CAAA,EACEb,EACE,CAACc,EAAMC,CAAI,EAAIf,EAAK,EAO1B,GALIY,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,GAIdP,IAAkB,QAClB,CAACW,EAAAA,qBAAqB,SAASX,CAAa,IAE5C,QAAQ,MACN,qCAAqCW,EAAAA,qBAAqB,KACxD,KAAA,CACD,eAAeX,CAAa,GAAA,EAE/B,QAAQ,KAAK,CAAC,GAGZH,IAAc,QAAa,CAACe,EAAAA,iBAAiB,SAASf,CAAS,IACjE,QAAQ,MACN,iCAAiCe,EAAAA,iBAAiB,KAChD,KAAA,CACD,eAAef,CAAS,GAAA,EAE3B,QAAQ,KAAK,CAAC,GAGhB,MAAMgB,EAAO,MAAMC,EAAAA,eAAeT,EAAM,CACtC,QAAAZ,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,UAAAC,EACA,WAAAE,EACA,mBAAAD,EACA,cAAAE,EACA,WAAAC,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,CAGtD,CACD,CAEArB,EACE0B,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,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,45 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { join as
|
|
5
|
-
import { a as i, g as
|
|
6
|
-
async function
|
|
2
|
+
import { readFile as x, writeFile as w } from "fs/promises";
|
|
3
|
+
import O from "minimist";
|
|
4
|
+
import { join as b } from "path";
|
|
5
|
+
import { a as t, e as i, g as j } from "./index-D2W38DVS.js";
|
|
6
|
+
async function $(e) {
|
|
7
7
|
const {
|
|
8
|
-
include:
|
|
9
|
-
exclude:
|
|
10
|
-
optimistic:
|
|
11
|
-
useEnumType:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
include: a,
|
|
9
|
+
exclude: c,
|
|
10
|
+
optimistic: m,
|
|
11
|
+
useEnumType: p,
|
|
12
|
+
enumStyle: o,
|
|
13
|
+
mergeReadWriteOnly: d,
|
|
14
|
+
useUnknown: g,
|
|
15
|
+
argumentStyle: n,
|
|
16
|
+
allSchemas: f,
|
|
17
|
+
futureStripLegacyMethods: y,
|
|
18
|
+
help: S,
|
|
19
|
+
version: h
|
|
20
|
+
} = e, [s, r] = e._;
|
|
21
|
+
if (S && (u(), process.exit(0)), h) {
|
|
22
|
+
const v = JSON.parse(
|
|
23
|
+
await x(b(__dirname, "..", "package.json"), "utf8")
|
|
22
24
|
);
|
|
23
|
-
console.log(
|
|
25
|
+
console.log(v.version), process.exit(0);
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
`--argumentStyle should be one of <${
|
|
27
|
+
s || (u(), process.exit(1)), n !== void 0 && !t.includes(n) && (console.error(
|
|
28
|
+
`--argumentStyle should be one of <${t.join(
|
|
29
|
+
" | "
|
|
30
|
+
)}>, but got "${n}"`
|
|
31
|
+
), process.exit(1)), o !== void 0 && !i.includes(o) && (console.error(
|
|
32
|
+
`--enumStyle should be one of <${i.join(
|
|
27
33
|
" | "
|
|
28
34
|
)}>, but got "${o}"`
|
|
29
35
|
), process.exit(1));
|
|
30
|
-
const
|
|
31
|
-
include:
|
|
32
|
-
exclude:
|
|
33
|
-
optimistic:
|
|
34
|
-
useEnumType:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const l = await j(s, {
|
|
37
|
+
include: a,
|
|
38
|
+
exclude: c,
|
|
39
|
+
optimistic: m,
|
|
40
|
+
useEnumType: p,
|
|
41
|
+
enumStyle: o,
|
|
42
|
+
useUnknown: g,
|
|
43
|
+
mergeReadWriteOnly: d,
|
|
44
|
+
argumentStyle: n,
|
|
45
|
+
allSchemas: f,
|
|
46
|
+
futureStripLegacyMethods: y
|
|
39
47
|
});
|
|
40
|
-
|
|
48
|
+
r ? await w(r, l) : console.log(l);
|
|
41
49
|
}
|
|
42
|
-
function
|
|
50
|
+
function u() {
|
|
43
51
|
console.error(`
|
|
44
52
|
Usage:
|
|
45
53
|
oazapfts <spec> [filename]
|
|
@@ -50,15 +58,17 @@ function r() {
|
|
|
50
58
|
--help, -h
|
|
51
59
|
--version, -v
|
|
52
60
|
--optimistic
|
|
53
|
-
--useEnumType
|
|
61
|
+
--useEnumType (deprecated, use --enumStyle=enum)
|
|
62
|
+
--enumStyle=<${i.join(" | ")}> (default: union)
|
|
54
63
|
--useUnknown
|
|
55
64
|
--mergeReadWriteOnly
|
|
56
|
-
--argumentStyle=<${
|
|
65
|
+
--argumentStyle=<${t.join(" | ")}> (default: positional)
|
|
57
66
|
--allSchemas
|
|
67
|
+
--futureStripLegacyMethods
|
|
58
68
|
`);
|
|
59
69
|
}
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
$(
|
|
71
|
+
O(process.argv.slice(2), {
|
|
62
72
|
alias: {
|
|
63
73
|
h: "help",
|
|
64
74
|
v: "version",
|
|
@@ -72,9 +82,10 @@ O(
|
|
|
72
82
|
"useEnumType",
|
|
73
83
|
"mergeReadWriteOnly",
|
|
74
84
|
"useUnknown",
|
|
75
|
-
"allSchemas"
|
|
85
|
+
"allSchemas",
|
|
86
|
+
"futureStripLegacyMethods"
|
|
76
87
|
],
|
|
77
|
-
string: ["argumentStyle"]
|
|
88
|
+
string: ["argumentStyle", "enumStyle"]
|
|
78
89
|
})
|
|
79
90
|
).catch((e) => {
|
|
80
91
|
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 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":";;;;;
|
|
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 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 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 --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\", \"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","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,0BAAAC;AAAA,IACA,MAAAC;AAAA,IACA,SAAAC;AAAA,EAAA,IACEZ,GACE,CAACa,GAAMC,CAAI,IAAId,EAAK;AAO1B,MALIW,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,IAIdP,MAAkB,UAClB,CAACW,EAAqB,SAASX,CAAa,MAE5C,QAAQ;AAAA,IACN,qCAAqCW,EAAqB;AAAA,MACxD;AAAA,IAAA,CACD,eAAeX,CAAa;AAAA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,
|
|
561
561
|
h as n,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
562
|
+
U as o,
|
|
563
|
+
J as p,
|
|
564
|
+
$ as q,
|
|
565
565
|
ye as r,
|
|
566
566
|
me as s,
|
|
567
567
|
P as t,
|
|
@@ -569,4 +569,4 @@ export {
|
|
|
569
569
|
ee as v,
|
|
570
570
|
pe as w
|
|
571
571
|
};
|
|
572
|
-
//# sourceMappingURL=context-
|
|
572
|
+
//# sourceMappingURL=context-Cu4eE5cx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-j-dMIA6M.js","sources":["../src/helpers/getOnlyModeSuffix.ts","../src/helpers/toIdentifier.ts","../src/generate/tscodegen.ts","../src/generate/generateServers.ts","../src/context.ts"],"sourcesContent":["import { OnlyMode } from \"../context\";\n\nconst onlyModeSuffixes: Record<OnlyMode, string> = {\n readOnly: \"Read\",\n writeOnly: \"Write\",\n};\n\nexport function getOnlyModeSuffix(onlyMode?: OnlyMode) {\n if (!onlyMode) return \"\";\n return onlyModeSuffixes[onlyMode];\n}\n","import _ from \"lodash\";\nimport { OnlyMode } from \"../context\";\nimport { isValidIdentifier } from \"../generate/tscodegen\";\nimport { getOnlyModeSuffix } from \"./getOnlyModeSuffix\";\n\nexport function toIdentifier(s: string, upper = false, onlyMode?: OnlyMode) {\n let cc = _.camelCase(s) + getOnlyModeSuffix(onlyMode);\n if (upper) cc = _.upperFirst(cc);\n if (isValidIdentifier(cc)) return cc;\n return \"$\" + cc;\n}\n","import ts from \"typescript\";\nimport { toIdentifier } from \"../helpers/toIdentifier\";\n\nconst factory = ts.factory;\n\nexport const questionToken = factory.createToken(ts.SyntaxKind.QuestionToken);\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) return undefined;\n if (token === true) return questionToken;\n return token;\n}\n\nexport const keywordType = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n void: factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),\n never: factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword),\n null: factory.createLiteralTypeNode(factory.createNull()),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n};\n\ntype KeywordTypeName = keyof typeof keywordType;\n\nexport function createKeywordType(type: KeywordTypeName) {\n return keywordType[type];\n}\n\nexport const modifier = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n};\n\nexport function createLiteral(v: string | boolean | number) {\n switch (typeof v) {\n case \"string\":\n return factory.createStringLiteral(v);\n case \"boolean\":\n return v ? factory.createTrue() : factory.createFalse();\n case \"number\":\n return String(v).charAt(0) === \"-\"\n ? factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n factory.createNumericLiteral(String(-v)),\n )\n : factory.createNumericLiteral(String(v));\n }\n}\n\nexport function createEnumTypeNode(values: Array<string | boolean | number>) {\n const types = values.map((v) =>\n v === null\n ? keywordType.null\n : factory.createLiteralTypeNode(createLiteral(v)),\n );\n return types.length > 1 ? factory.createUnionTypeNode(types) : types[0];\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n type: ts.TypeNode;\n}) {\n return factory.createTypeAliasDeclaration(\n modifiers,\n name,\n typeParameters,\n type,\n );\n}\n\nexport function createInterfaceAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n inheritedNodeNames,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n type: ts.TypeNode;\n inheritedNodeNames?: (string | ts.Identifier)[];\n}) {\n const heritageClauses = inheritedNodeNames\n ? [\n factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n inheritedNodeNames.map((name) => {\n const extendedInterfaceName =\n typeof name === \"string\" ? name : name.escapedText.toString();\n return factory.createExpressionWithTypeArguments(\n factory.createIdentifier(\n toIdentifier(extendedInterfaceName, true),\n ),\n undefined,\n );\n }),\n ),\n ]\n : [];\n return factory.createInterfaceDeclaration(\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n (type as ts.TypeLiteralNode).members,\n );\n}\n\nexport function toExpression(ex: ts.Expression | string) {\n if (typeof ex === \"string\") return factory.createIdentifier(ex);\n return ex;\n}\n\nexport function createCall(\n expression: ts.Expression | string,\n {\n typeArgs,\n args,\n }: {\n typeArgs?: Array<ts.TypeNode>;\n args?: Array<ts.Expression>;\n } = {},\n) {\n return factory.createCallExpression(toExpression(expression), typeArgs, args);\n}\n\nexport function createMethodCall(\n method: string,\n opts: {\n typeArgs?: Array<ts.TypeNode>;\n args?: Array<ts.Expression>;\n },\n) {\n return createCall(\n factory.createPropertyAccessExpression(factory.createThis(), method),\n opts,\n );\n}\n\nexport function createObjectLiteral(props: [string, string | ts.Expression][]) {\n return factory.createObjectLiteralExpression(\n props.map(([name, identifier]) =>\n createPropertyAssignment(name, toExpression(identifier)),\n ),\n true,\n );\n}\n\nexport function createPropertyAssignment(\n name: string,\n expression: ts.Expression,\n) {\n if (ts.isIdentifier(expression)) {\n if (expression.text === name) {\n return factory.createShorthandPropertyAssignment(name);\n }\n }\n return factory.createPropertyAssignment(propertyName(name), expression);\n}\n\nexport function block(...statements: ts.Statement[]) {\n return factory.createBlock(statements, true);\n}\n\nexport function createArrowFunction(\n parameters: ts.ParameterDeclaration[],\n body: ts.ConciseBody,\n {\n modifiers,\n typeParameters,\n type,\n equalsGreaterThanToken,\n }: {\n modifiers?: ts.Modifier[];\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n equalsGreaterThanToken?: ts.EqualsGreaterThanToken;\n } = {},\n) {\n return factory.createArrowFunction(\n modifiers,\n typeParameters,\n parameters,\n type,\n equalsGreaterThanToken,\n body,\n );\n}\n\nexport function createFunctionDeclaration(\n name: string | ts.Identifier | undefined,\n {\n modifiers,\n asteriskToken,\n typeParameters,\n type,\n }: {\n modifiers?: ts.Modifier[];\n asteriskToken?: ts.AsteriskToken;\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n },\n parameters: ts.ParameterDeclaration[],\n body?: ts.Block,\n): ts.FunctionDeclaration {\n return factory.createFunctionDeclaration(\n modifiers,\n asteriskToken,\n name,\n typeParameters,\n parameters,\n type,\n body,\n );\n}\n\nexport function createClassDeclaration({\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n members,\n}: {\n modifiers?: Array<ts.Modifier>;\n name?: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n heritageClauses?: Array<ts.HeritageClause>;\n members: Array<ts.ClassElement>;\n}) {\n return factory.createClassDeclaration(\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n members,\n );\n}\n\nexport function createConstructor({\n modifiers,\n parameters,\n body,\n}: {\n modifiers?: Array<ts.Modifier>;\n parameters: Array<ts.ParameterDeclaration>;\n body?: ts.Block;\n}) {\n return factory.createConstructorDeclaration(modifiers, parameters, body);\n}\n\nexport function createMethod(\n name:\n | string\n | ts.Identifier\n | ts.StringLiteral\n | ts.NumericLiteral\n | ts.ComputedPropertyName,\n {\n modifiers,\n asteriskToken,\n questionToken,\n typeParameters,\n type,\n }: {\n modifiers?: ts.Modifier[];\n asteriskToken?: ts.AsteriskToken;\n questionToken?: ts.QuestionToken | boolean;\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n } = {},\n parameters: ts.ParameterDeclaration[] = [],\n body?: ts.Block,\n): ts.MethodDeclaration {\n return factory.createMethodDeclaration(\n modifiers,\n asteriskToken,\n name,\n createQuestionToken(questionToken),\n typeParameters,\n parameters,\n type,\n body,\n );\n}\n\nexport function createParameter(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n modifiers?: Array<ts.Modifier>;\n dotDotDotToken?: ts.DotDotDotToken;\n questionToken?: ts.QuestionToken | boolean;\n type?: ts.TypeNode;\n initializer?: ts.Expression;\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(\n modifiers,\n dotDotDotToken,\n name,\n createQuestionToken(questionToken),\n type,\n initializer,\n );\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === \"string\") {\n return isValidIdentifier(name)\n ? factory.createIdentifier(name)\n : factory.createStringLiteral(name);\n }\n return name;\n}\n\nexport function createPropertySignature({\n modifiers,\n name,\n questionToken,\n type,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: ts.PropertyName | string;\n questionToken?: ts.QuestionToken | boolean;\n type?: ts.TypeNode;\n}) {\n return factory.createPropertySignature(\n modifiers,\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n );\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = \"key\",\n indexType = keywordType.string,\n }: {\n indexName?: string;\n indexType?: ts.TypeNode;\n modifiers?: Array<ts.Modifier>;\n } = {},\n) {\n return factory.createIndexSignature(\n modifiers,\n [createParameter(indexName, { type: indexType })],\n type,\n );\n}\n\nexport function createObjectBinding(\n elements: Array<{\n name: string | ts.BindingName;\n dotDotDotToken?: ts.DotDotDotToken;\n propertyName?: string | ts.PropertyName;\n initializer?: ts.Expression;\n }>,\n) {\n return factory.createObjectBindingPattern(\n elements.map(({ dotDotDotToken, propertyName, name, initializer }) =>\n factory.createBindingElement(\n dotDotDotToken,\n propertyName,\n name,\n initializer,\n ),\n ),\n );\n}\n\nexport function createTemplateString(\n head: string,\n spans: Array<{ literal: string; expression: ts.Expression }>,\n) {\n if (!spans.length) return factory.createStringLiteral(head);\n return factory.createTemplateExpression(\n factory.createTemplateHead(head),\n spans.map(({ expression, literal }, i) =>\n factory.createTemplateSpan(\n expression,\n i === spans.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal),\n ),\n ),\n );\n}\n\nexport function findNode<T extends ts.Node>(\n nodes: ts.NodeArray<ts.Node>,\n kind: T extends { kind: infer K } ? K : never,\n test?: (node: T) => boolean | undefined,\n): T {\n const node = nodes.find(\n (s) => s.kind === kind && (!test || test(s as T)),\n ) as T;\n if (!node) throw new Error(`Node not found: ${kind}`);\n return node;\n}\n\nexport function getName(name: ts.Node) {\n if (ts.isIdentifier(name)) {\n return name.escapedText;\n }\n if (ts.isLiteralExpression(name)) {\n return name.text;\n }\n return \"\";\n}\n\nexport function getFirstDeclarationName(n: ts.VariableStatement) {\n const name = ts.getNameOfDeclaration(n.declarationList.declarations[0]);\n return name ? getName(name) : \"\";\n}\n\nexport function findFirstVariableDeclaration(\n nodes: ts.NodeArray<ts.Node>,\n name: string,\n) {\n const statement = findNode<ts.VariableStatement>(\n nodes,\n ts.SyntaxKind.VariableStatement,\n (n) => getFirstDeclarationName(n) === name,\n );\n const [first] = statement.declarationList.declarations;\n if (!first) throw new Error(`Missing ${name} declaration`);\n return first;\n}\n\nexport function changePropertyValue(\n o: ts.ObjectLiteralExpression,\n property: string,\n value: ts.Expression,\n) {\n const p = o.properties.find(\n (p) => ts.isPropertyAssignment(p) && getName(p.name) === property,\n );\n if (p && ts.isPropertyAssignment(p)) {\n // p.initializer is readonly, this might break in a future TS version, but works fine for now.\n Object.assign(p, { initializer: value });\n } else {\n throw new Error(`No such property: ${property}`);\n }\n}\n\ntype Visitor = (\n node: ts.Node,\n context: ts.TransformationContext,\n) => void | ts.Node;\n\nfunction createTransformer(visitor: Visitor) {\n return <T extends ts.Node>(context: ts.TransformationContext) =>\n (rootNode: T) => {\n function visit(node: ts.Node): ts.Node {\n const result = visitor(node, context);\n\n if (result) {\n return result;\n }\n\n return ts.visitEachChild(node, visit, context);\n }\n\n return ts.visitNode(rootNode, visit);\n };\n}\n\nexport function transform<T extends ts.Node>(\n source: T,\n ...visitors: Visitor[]\n) {\n const result = ts.transform(source, visitors.map(createTransformer));\n\n return result.transformed[0] as T;\n}\n\nexport function appendNodes<T extends ts.Node>(\n array: ts.NodeArray<T>,\n ...nodes: T[]\n) {\n return factory.createNodeArray([...array, ...nodes]);\n}\n\nexport function addComment<T extends ts.Node>(node: T, comment?: string) {\n if (!comment) return node;\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `*\\n * ${comment.replace(/\\n/g, \"\\n * \")}\\n `,\n true,\n );\n}\n\nconst printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n});\n\nexport function printNode(node: ts.Node) {\n const file = ts.createSourceFile(\n \"someFileName.ts\",\n \"\",\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS,\n );\n return printer.printNode(ts.EmitHint.Unspecified, node, file);\n}\n\nexport function printNodes(nodes: ts.Node[]) {\n const file = ts.createSourceFile(\n \"someFileName.ts\",\n \"\",\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS,\n );\n return nodes\n .map((node) => printer.printNode(ts.EmitHint.Unspecified, node, file))\n .join(\"\\n\");\n}\n\nexport function printFile(sourceFile: ts.SourceFile) {\n return printer.printFile(sourceFile);\n}\n\nexport function isValidIdentifier(str: string) {\n if (!str.length || str.trim() !== str) return false;\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest);\n return (\n !!node &&\n node.kind === ts.SyntaxKind.Identifier &&\n ts.identifierToKeywordKind(node) === undefined\n );\n}\n\nexport function updateVariableDeclaration(\n node: ts.VariableDeclaration,\n updates: Partial<ts.VariableDeclaration>,\n) {\n return ts.factory.updateVariableDeclaration(\n node,\n updates.name || node.name,\n updates.exclamationToken || node.exclamationToken,\n updates.type || node.type,\n updates.initializer || node.initializer,\n );\n}\n\nexport function updateFunctionDeclaration(\n node: ts.FunctionDeclaration,\n updates: Partial<ts.FunctionDeclaration>,\n) {\n return ts.factory.updateFunctionDeclaration(\n node,\n updates.modifiers || node.modifiers,\n updates.asteriskToken || node.asteriskToken,\n updates.name || node.name,\n updates.typeParameters || node.typeParameters,\n updates.parameters || node.parameters,\n updates.type || node.type,\n updates.body || node.body,\n );\n}\n","import _ from \"lodash\";\nimport * as cg from \"./tscodegen\";\nimport ts from \"typescript\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport { ServerObject } from \"../helpers/openApi3-x\";\n\nconst factory = ts.factory;\n\nfunction createTemplate(url: string) {\n const tokens = url.split(/{([\\s\\S]+?)}/g);\n const chunks = _.chunk(tokens.slice(1), 2);\n return cg.createTemplateString(\n tokens[0],\n chunks.map(([expression, literal]) => ({\n expression: factory.createIdentifier(expression),\n literal,\n })),\n );\n}\n\nfunction createServerFunction(\n template: string,\n vars: Record<string, OpenAPIV3.ServerVariableObject>,\n) {\n const params = [\n cg.createParameter(\n cg.createObjectBinding(\n Object.entries(vars || {}).map(([name, value]) => {\n return {\n name,\n initializer: cg.createLiteral(value.default),\n };\n }),\n ),\n {\n type: factory.createTypeLiteralNode(\n Object.entries(vars || {}).map(([name, value]) => {\n return cg.createPropertySignature({\n name,\n type: value.enum\n ? cg.createEnumTypeNode(value.enum)\n : factory.createUnionTypeNode([\n cg.keywordType.string,\n cg.keywordType.number,\n cg.keywordType.boolean,\n ]),\n });\n }),\n ),\n },\n ),\n ];\n\n return cg.createArrowFunction(params, createTemplate(template));\n}\n\nfunction generateServerExpression(server: ServerObject) {\n return server.variables\n ? createServerFunction(server.url, server.variables)\n : factory.createStringLiteral(server.url);\n}\n\nfunction defaultUrl(server?: ServerObject) {\n if (!server) return \"/\";\n const { url, variables } = server;\n if (!variables) return url;\n return url.replace(/\\{(.+?)\\}/g, (m, name) =>\n variables[name] ? String(variables[name].default) : m,\n );\n}\n\nexport function defaultBaseUrl(servers?: ServerObject[]) {\n return defaultUrl(servers?.[0]);\n}\n\nfunction serverName(server: ServerObject, index: number) {\n return server.description\n ? _.camelCase(server.description.replace(/\\W+/, \" \"))\n : `server${index + 1}`;\n}\n\nexport function generateServers(servers: ServerObject[]) {\n return cg.createObjectLiteral(\n servers.map((server, i) => [\n serverName(server, i),\n generateServerExpression(server),\n ]),\n );\n}\n\nexport function createServersStatement(servers: ServerObject[]) {\n return ts.factory.createVariableStatement(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createVariableDeclarationList(\n [\n ts.factory.createVariableDeclaration(\n \"servers\",\n undefined,\n undefined,\n generateServers(servers),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n );\n}\n","import ts, {\n InterfaceDeclaration,\n Statement,\n TypeAliasDeclaration,\n TypeReferenceNode,\n} from \"typescript\";\nimport type { OazapftsOptions } from \"./\";\nimport type {\n Document,\n SchemaObject,\n ServerObject,\n} from \"./helpers/openApi3-x\";\nimport { defaultBaseUrl } from \"./generate/generateServers\";\nimport _ from \"lodash\";\nimport { CustomHeaders } from \"@oazapfts/runtime\";\n\n// ─── Data types for template parts ──────────────────────────────────────────\n\nexport type ImportSpecifier = {\n name: string;\n as?: string;\n};\nexport type DefaultImport = [string, { from: string }];\nexport type NamespaceImport = [{ namespace: string }, { from: string }];\nexport type ImportsWithoutDefault = [\n (ImportSpecifier | string)[],\n { from: string },\n];\nexport type ImportWithDefault = [\n string,\n (ImportSpecifier | string)[],\n { from: string },\n];\n\nexport type Import =\n | string\n | ImportsWithoutDefault\n | DefaultImport\n | ImportWithDefault\n | NamespaceImport;\n\nexport type OnlyMode = \"readOnly\" | \"writeOnly\";\nexport type OnlyModes = Record<OnlyMode, boolean>;\n\nexport type ReadonlyDeep<T> = {\n readonly [P in keyof T]: ReadonlyDeep<T[P]>;\n};\n\nexport type Defaults = {\n baseUrl?: string;\n headers?: CustomHeaders;\n FormData?: ts.ClassExpression | ts.Identifier;\n fetch?: ts.FunctionExpression | ts.ArrowFunction | ts.Identifier;\n};\n\nexport type OazapftsContext = {\n readonly opts: ReadonlyDeep<OazapftsOptions>;\n readonly spec: Document;\n\n /** Banner comment at the top of the file (the text content, not including comment markers) */\n banner: string;\n /** Import declarations (AST nodes) */\n imports: Import[];\n /** Runtime defaults (baseUrl, etc.) - will be generated as `export const defaults = { ... }` */\n defaults: Defaults;\n /** Server definitions - will be generated as `export const servers = { ... }` */\n servers: ServerObject[];\n /** Initialization statements (e.g., `const oazapfts = Oazapfts.runtime(defaults)`) */\n init: Statement[];\n\n // see `preprocessComponents` for the definition of a discriminating schema\n discriminatingSchemas: Set<SchemaObject>;\n\n aliases: (TypeAliasDeclaration | InterfaceDeclaration)[];\n\n enumAliases: Statement[];\n enumRefs: Record<string, { values: string; type: TypeReferenceNode }>;\n\n // Collect the types of all referenced schemas so we can export them later\n // Referenced schemas can be pointing at the following versions:\n // - \"base\": The regular type/interface e.g. ExampleSchema\n // - \"readOnly\": The readOnly version e.g. ExampleSchemaRead\n // - \"writeOnly\": The writeOnly version e.g. ExampleSchemaWrite\n refs: Record<\n string,\n {\n base: TypeReferenceNode;\n readOnly?: TypeReferenceNode;\n writeOnly?: TypeReferenceNode;\n }\n >;\n\n // Maps a referenced schema to its readOnly/writeOnly status\n // This field should be used exclusively within the `checkSchemaOnlyMode` method\n refsOnlyMode: Map<string, OnlyModes>;\n\n // Keep track of already used type aliases\n typeAliases: Record<string, number>;\n};\n\nexport function createContext(\n inputSpec: Document,\n opts: OazapftsContext[\"opts\"] = {},\n): OazapftsContext {\n const spec = _.cloneDeep(inputSpec);\n\n return {\n opts,\n spec,\n\n // Template parts\n banner: `DO NOT MODIFY - This file has been generated using oazapfts.\nSee https://www.npmjs.com/package/oazapfts`,\n imports: [\n [{ namespace: \"Oazapfts\" }, { from: \"@oazapfts/runtime\" }],\n [{ namespace: \"QS\" }, { from: \"@oazapfts/runtime/query\" }],\n ],\n defaults: { baseUrl: defaultBaseUrl(spec.servers), headers: {} },\n servers: spec.servers || [],\n init: createInit(),\n\n // Internal state\n discriminatingSchemas: new Set(),\n aliases: [],\n enumAliases: [],\n enumRefs: {},\n refs: {},\n refsOnlyMode: new Map(),\n typeAliases: {},\n };\n}\n\n/** Creates: const oazapfts = Oazapfts.runtime(defaults); */\nfunction createInit(): Statement[] {\n return [\n ts.factory.createVariableStatement(\n undefined,\n ts.factory.createVariableDeclarationList(\n [\n ts.factory.createVariableDeclaration(\n \"oazapfts\",\n undefined,\n undefined,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(\"Oazapfts\"),\n \"runtime\",\n ),\n undefined,\n [ts.factory.createIdentifier(\"defaults\")],\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n ];\n}\n"],"names":["onlyModeSuffixes","getOnlyModeSuffix","onlyMode","toIdentifier","s","upper","cc","_","isValidIdentifier","factory","ts","questionToken","createQuestionToken","token","keywordType","createKeywordType","type","modifier","createLiteral","v","createEnumTypeNode","values","types","createTypeAliasDeclaration","modifiers","name","typeParameters","createInterfaceAliasDeclaration","inheritedNodeNames","heritageClauses","extendedInterfaceName","toExpression","ex","createCall","expression","typeArgs","args","createMethodCall","method","opts","createObjectLiteral","props","identifier","createPropertyAssignment","propertyName","block","statements","createArrowFunction","parameters","body","equalsGreaterThanToken","createFunctionDeclaration","asteriskToken","createClassDeclaration","members","createConstructor","createMethod","createParameter","dotDotDotToken","initializer","createPropertySignature","createIndexSignature","indexName","indexType","createObjectBinding","elements","createTemplateString","head","spans","literal","i","findNode","nodes","kind","test","node","getName","getFirstDeclarationName","n","findFirstVariableDeclaration","statement","first","changePropertyValue","o","property","value","p","createTransformer","visitor","context","rootNode","visit","result","transform","source","visitors","appendNodes","array","addComment","comment","printer","printNode","file","printNodes","printFile","sourceFile","str","updateVariableDeclaration","updates","updateFunctionDeclaration","createTemplate","url","tokens","chunks","cg.createTemplateString","createServerFunction","template","vars","params","cg.createParameter","cg.createObjectBinding","cg.createLiteral","cg.createPropertySignature","cg.createEnumTypeNode","cg.keywordType","cg.createArrowFunction","generateServerExpression","server","defaultUrl","variables","m","defaultBaseUrl","servers","serverName","index","generateServers","cg.createObjectLiteral","createServersStatement","createContext","inputSpec","spec","createInit"],"mappings":";;AAEA,MAAMA,IAA6C;AAAA,EACjD,UAAU;AAAA,EACV,WAAW;AACb;AAEO,SAASC,EAAkBC,GAAqB;AACrD,SAAKA,IACEF,EAAiBE,CAAQ,IADV;AAExB;ACLO,SAASC,EAAaC,GAAWC,IAAQ,IAAOH,GAAqB;AAC1E,MAAII,IAAKC,EAAE,UAAUH,CAAC,IAAIH,EAAkBC,CAAQ;AAEpD,SADIG,MAAOC,IAAKC,EAAE,WAAWD,CAAE,IAC3BE,EAAkBF,CAAE,IAAUA,IAC3B,MAAMA;AACf;ACPA,MAAMG,IAAUC,EAAG,SAENC,IAAgBF,EAAQ,YAAYC,EAAG,WAAW,aAAa;AAErE,SAASE,EAAoBC,GAAoC;AACtE,MAAKA;AACL,WAAIA,MAAU,KAAaF,IACpBE;AACT;AAEO,MAAMC,IAAc;AAAA,EACzB,KAAKL,EAAQ,sBAAsBC,EAAG,WAAW,UAAU;AAAA,EAC3D,QAAQD,EAAQ,sBAAsBC,EAAG,WAAW,aAAa;AAAA,EACjE,SAASD,EAAQ,sBAAsBC,EAAG,WAAW,aAAa;AAAA,EAClE,QAAQD,EAAQ,sBAAsBC,EAAG,WAAW,aAAa;AAAA,EACjE,QAAQD,EAAQ,sBAAsBC,EAAG,WAAW,aAAa;AAAA,EACjE,SAASD,EAAQ,sBAAsBC,EAAG,WAAW,cAAc;AAAA,EACnE,WAAWD,EAAQ,sBAAsBC,EAAG,WAAW,gBAAgB;AAAA,EACvE,MAAMD,EAAQ,sBAAsBC,EAAG,WAAW,WAAW;AAAA,EAC7D,OAAOD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C,EAAE,WAAW,KAAA,GAAQ,EAAE,MAAM,2BAA2B;AAAA,IAAA;AAAA,IAE3D,UAAU,EAAE,SAAST,GAAeS,EAAK,OAAO,GAAG,SAAS,GAAC;AAAA,IAC7D,SAASA,EAAK,WAAW,CAAA;AAAA,IACzB,MAAMC,GAAA;AAAA;AAAA,IAGN,2CAA2B,IAAA;AAAA,IAC3B,SAAS,CAAA;AAAA,IACT,aAAa,CAAA;AAAA,IACb,UAAU,CAAA;AAAA,IACV,MAAM,CAAA;AAAA,IACN,kCAAkB,IAAA;AAAA,IAClB,aAAa,CAAA;AAAA,EAAC;AAElB;AAGA,SAASA,KAA0B;AACjC,SAAO;AAAA,IACLnI,EAAG,QAAQ;AAAA,MACT;AAAA,MACAA,EAAG,QAAQ;AAAA,QACT;AAAA,UACEA,EAAG,QAAQ;AAAA,YACT;AAAA,YACA;AAAA,YACA;AAAA,YACAA,EAAG,QAAQ;AAAA,cACTA,EAAG,QAAQ;AAAA,gBACTA,EAAG,QAAQ,iBAAiB,UAAU;AAAA,gBACtC;AAAA,cAAA;AAAA,cAEF;AAAA,cACA,CAACA,EAAG,QAAQ,iBAAiB,UAAU,CAAC;AAAA,YAAA;AAAA,UAC1C;AAAA,QACF;AAAA,QAEFA,EAAG,UAAU;AAAA,MAAA;AAAA,IACf;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"context-Cu4eE5cx.js","sources":["../src/helpers/getOnlyModeSuffix.ts","../src/helpers/toIdentifier.ts","../src/generate/tscodegen.ts","../src/generate/generateServers.ts","../src/context.ts"],"sourcesContent":["import { OnlyMode } from \"../context\";\n\nconst onlyModeSuffixes: Record<OnlyMode, string> = {\n readOnly: \"Read\",\n writeOnly: \"Write\",\n};\n\nexport function getOnlyModeSuffix(onlyMode?: OnlyMode) {\n if (!onlyMode) return \"\";\n return onlyModeSuffixes[onlyMode];\n}\n","import _ from \"lodash\";\nimport { OnlyMode } from \"../context\";\nimport { isValidIdentifier } from \"../generate/tscodegen\";\nimport { getOnlyModeSuffix } from \"./getOnlyModeSuffix\";\n\nexport function toIdentifier(s: string, upper = false, onlyMode?: OnlyMode) {\n let cc = _.camelCase(s) + getOnlyModeSuffix(onlyMode);\n if (upper) cc = _.upperFirst(cc);\n if (isValidIdentifier(cc)) return cc;\n return \"$\" + cc;\n}\n","import ts from \"typescript\";\nimport { toIdentifier } from \"../helpers/toIdentifier\";\n\nconst factory = ts.factory;\n\nexport const questionToken = factory.createToken(ts.SyntaxKind.QuestionToken);\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) return undefined;\n if (token === true) return questionToken;\n return token;\n}\n\nexport const keywordType = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n void: factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),\n never: factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword),\n null: factory.createLiteralTypeNode(factory.createNull()),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n};\n\ntype KeywordTypeName = keyof typeof keywordType;\n\nexport function createKeywordType(type: KeywordTypeName) {\n return keywordType[type];\n}\n\nexport const modifier = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n};\n\nexport function createLiteral(v: string | boolean | number) {\n switch (typeof v) {\n case \"string\":\n return factory.createStringLiteral(v);\n case \"boolean\":\n return v ? factory.createTrue() : factory.createFalse();\n case \"number\":\n return String(v).charAt(0) === \"-\"\n ? factory.createPrefixUnaryExpression(\n ts.SyntaxKind.MinusToken,\n factory.createNumericLiteral(String(-v)),\n )\n : factory.createNumericLiteral(String(v));\n }\n}\n\nexport function createEnumTypeNode(values: Array<string | boolean | number>) {\n const types = values.map((v) =>\n v === null\n ? keywordType.null\n : factory.createLiteralTypeNode(createLiteral(v)),\n );\n return types.length > 1 ? factory.createUnionTypeNode(types) : types[0];\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n type: ts.TypeNode;\n}) {\n return factory.createTypeAliasDeclaration(\n modifiers,\n name,\n typeParameters,\n type,\n );\n}\n\nexport function createInterfaceAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n inheritedNodeNames,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n type: ts.TypeNode;\n inheritedNodeNames?: (string | ts.Identifier)[];\n}) {\n const heritageClauses = inheritedNodeNames\n ? [\n factory.createHeritageClause(\n ts.SyntaxKind.ExtendsKeyword,\n inheritedNodeNames.map((name) => {\n const extendedInterfaceName =\n typeof name === \"string\" ? name : name.escapedText.toString();\n return factory.createExpressionWithTypeArguments(\n factory.createIdentifier(\n toIdentifier(extendedInterfaceName, true),\n ),\n undefined,\n );\n }),\n ),\n ]\n : [];\n return factory.createInterfaceDeclaration(\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n (type as ts.TypeLiteralNode).members,\n );\n}\n\nexport function toExpression(ex: ts.Expression | string) {\n if (typeof ex === \"string\") return factory.createIdentifier(ex);\n return ex;\n}\n\nexport function createCall(\n expression: ts.Expression | string,\n {\n typeArgs,\n args,\n }: {\n typeArgs?: Array<ts.TypeNode>;\n args?: Array<ts.Expression>;\n } = {},\n) {\n return factory.createCallExpression(toExpression(expression), typeArgs, args);\n}\n\nexport function createMethodCall(\n method: string,\n opts: {\n typeArgs?: Array<ts.TypeNode>;\n args?: Array<ts.Expression>;\n },\n) {\n return createCall(\n factory.createPropertyAccessExpression(factory.createThis(), method),\n opts,\n );\n}\n\nexport function createObjectLiteral(props: [string, string | ts.Expression][]) {\n return factory.createObjectLiteralExpression(\n props.map(([name, identifier]) =>\n createPropertyAssignment(name, toExpression(identifier)),\n ),\n true,\n );\n}\n\nexport function createPropertyAssignment(\n name: string,\n expression: ts.Expression,\n) {\n if (ts.isIdentifier(expression)) {\n if (expression.text === name) {\n return factory.createShorthandPropertyAssignment(name);\n }\n }\n return factory.createPropertyAssignment(propertyName(name), expression);\n}\n\nexport function block(...statements: ts.Statement[]) {\n return factory.createBlock(statements, true);\n}\n\nexport function createArrowFunction(\n parameters: ts.ParameterDeclaration[],\n body: ts.ConciseBody,\n {\n modifiers,\n typeParameters,\n type,\n equalsGreaterThanToken,\n }: {\n modifiers?: ts.Modifier[];\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n equalsGreaterThanToken?: ts.EqualsGreaterThanToken;\n } = {},\n) {\n return factory.createArrowFunction(\n modifiers,\n typeParameters,\n parameters,\n type,\n equalsGreaterThanToken,\n body,\n );\n}\n\nexport function createFunctionDeclaration(\n name: string | ts.Identifier | undefined,\n {\n modifiers,\n asteriskToken,\n typeParameters,\n type,\n }: {\n modifiers?: ts.Modifier[];\n asteriskToken?: ts.AsteriskToken;\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n },\n parameters: ts.ParameterDeclaration[],\n body?: ts.Block,\n): ts.FunctionDeclaration {\n return factory.createFunctionDeclaration(\n modifiers,\n asteriskToken,\n name,\n typeParameters,\n parameters,\n type,\n body,\n );\n}\n\nexport function createClassDeclaration({\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n members,\n}: {\n modifiers?: Array<ts.Modifier>;\n name?: string | ts.Identifier;\n typeParameters?: Array<ts.TypeParameterDeclaration>;\n heritageClauses?: Array<ts.HeritageClause>;\n members: Array<ts.ClassElement>;\n}) {\n return factory.createClassDeclaration(\n modifiers,\n name,\n typeParameters,\n heritageClauses,\n members,\n );\n}\n\nexport function createConstructor({\n modifiers,\n parameters,\n body,\n}: {\n modifiers?: Array<ts.Modifier>;\n parameters: Array<ts.ParameterDeclaration>;\n body?: ts.Block;\n}) {\n return factory.createConstructorDeclaration(modifiers, parameters, body);\n}\n\nexport function createMethod(\n name:\n | string\n | ts.Identifier\n | ts.StringLiteral\n | ts.NumericLiteral\n | ts.ComputedPropertyName,\n {\n modifiers,\n asteriskToken,\n questionToken,\n typeParameters,\n type,\n }: {\n modifiers?: ts.Modifier[];\n asteriskToken?: ts.AsteriskToken;\n questionToken?: ts.QuestionToken | boolean;\n typeParameters?: ts.TypeParameterDeclaration[];\n type?: ts.TypeNode;\n } = {},\n parameters: ts.ParameterDeclaration[] = [],\n body?: ts.Block,\n): ts.MethodDeclaration {\n return factory.createMethodDeclaration(\n modifiers,\n asteriskToken,\n name,\n createQuestionToken(questionToken),\n typeParameters,\n parameters,\n type,\n body,\n );\n}\n\nexport function createParameter(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n modifiers?: Array<ts.Modifier>;\n dotDotDotToken?: ts.DotDotDotToken;\n questionToken?: ts.QuestionToken | boolean;\n type?: ts.TypeNode;\n initializer?: ts.Expression;\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(\n modifiers,\n dotDotDotToken,\n name,\n createQuestionToken(questionToken),\n type,\n initializer,\n );\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === \"string\") {\n return isValidIdentifier(name)\n ? factory.createIdentifier(name)\n : factory.createStringLiteral(name);\n }\n return name;\n}\n\nexport function createPropertySignature({\n modifiers,\n name,\n questionToken,\n type,\n}: {\n modifiers?: Array<ts.Modifier>;\n name: ts.PropertyName | string;\n questionToken?: ts.QuestionToken | boolean;\n type?: ts.TypeNode;\n}) {\n return factory.createPropertySignature(\n modifiers,\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n );\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = \"key\",\n indexType = keywordType.string,\n }: {\n indexName?: string;\n indexType?: ts.TypeNode;\n modifiers?: Array<ts.Modifier>;\n } = {},\n) {\n return factory.createIndexSignature(\n modifiers,\n [createParameter(indexName, { type: indexType })],\n type,\n );\n}\n\nexport function createObjectBinding(\n elements: Array<{\n name: string | ts.BindingName;\n dotDotDotToken?: ts.DotDotDotToken;\n propertyName?: string | ts.PropertyName;\n initializer?: ts.Expression;\n }>,\n) {\n return factory.createObjectBindingPattern(\n elements.map(({ dotDotDotToken, propertyName, name, initializer }) =>\n factory.createBindingElement(\n dotDotDotToken,\n propertyName,\n name,\n initializer,\n ),\n ),\n );\n}\n\nexport function createTemplateString(\n head: string,\n spans: Array<{ literal: string; expression: ts.Expression }>,\n) {\n if (!spans.length) return factory.createStringLiteral(head);\n return factory.createTemplateExpression(\n factory.createTemplateHead(head),\n spans.map(({ expression, literal }, i) =>\n factory.createTemplateSpan(\n expression,\n i === spans.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal),\n ),\n ),\n );\n}\n\nexport function findNode<T extends ts.Node>(\n nodes: ts.NodeArray<ts.Node>,\n kind: T extends { kind: infer K } ? K : never,\n test?: (node: T) => boolean | undefined,\n): T {\n const node = nodes.find(\n (s) => s.kind === kind && (!test || test(s as T)),\n ) as T;\n if (!node) throw new Error(`Node not found: ${kind}`);\n return node;\n}\n\nexport function getName(name: ts.Node) {\n if (ts.isIdentifier(name)) {\n return name.escapedText;\n }\n if (ts.isLiteralExpression(name)) {\n return name.text;\n }\n return \"\";\n}\n\nexport function getFirstDeclarationName(n: ts.VariableStatement) {\n const name = ts.getNameOfDeclaration(n.declarationList.declarations[0]);\n return name ? getName(name) : \"\";\n}\n\nexport function findFirstVariableDeclaration(\n nodes: ts.NodeArray<ts.Node>,\n name: string,\n) {\n const statement = findNode<ts.VariableStatement>(\n nodes,\n ts.SyntaxKind.VariableStatement,\n (n) => getFirstDeclarationName(n) === name,\n );\n const [first] = statement.declarationList.declarations;\n if (!first) throw new Error(`Missing ${name} declaration`);\n return first;\n}\n\nexport function changePropertyValue(\n o: ts.ObjectLiteralExpression,\n property: string,\n value: ts.Expression,\n) {\n const p = o.properties.find(\n (p) => ts.isPropertyAssignment(p) && getName(p.name) === property,\n );\n if (p && ts.isPropertyAssignment(p)) {\n // p.initializer is readonly, this might break in a future TS version, but works fine for now.\n Object.assign(p, { initializer: value });\n } else {\n throw new Error(`No such property: ${property}`);\n }\n}\n\ntype Visitor = (\n node: ts.Node,\n context: ts.TransformationContext,\n) => void | ts.Node;\n\nfunction createTransformer(visitor: Visitor) {\n return <T extends ts.Node>(context: ts.TransformationContext) =>\n (rootNode: T) => {\n function visit(node: ts.Node): ts.Node {\n const result = visitor(node, context);\n\n if (result) {\n return result;\n }\n\n return ts.visitEachChild(node, visit, context);\n }\n\n return ts.visitNode(rootNode, visit);\n };\n}\n\nexport function transform<T extends ts.Node>(\n source: T,\n ...visitors: Visitor[]\n) {\n const result = ts.transform(source, visitors.map(createTransformer));\n\n return result.transformed[0] as T;\n}\n\nexport function appendNodes<T extends ts.Node>(\n array: ts.NodeArray<T>,\n ...nodes: T[]\n) {\n return factory.createNodeArray([...array, ...nodes]);\n}\n\nexport function addComment<T extends ts.Node>(node: T, comment?: string) {\n if (!comment) return node;\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `*\\n * ${comment.replace(/\\n/g, \"\\n * \")}\\n `,\n true,\n );\n}\n\nconst printer = ts.createPrinter({\n newLine: ts.NewLineKind.LineFeed,\n});\n\nexport function printNode(node: ts.Node) {\n const file = ts.createSourceFile(\n \"someFileName.ts\",\n \"\",\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS,\n );\n return printer.printNode(ts.EmitHint.Unspecified, node, file);\n}\n\nexport function printNodes(nodes: ts.Node[]) {\n const file = ts.createSourceFile(\n \"someFileName.ts\",\n \"\",\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS,\n );\n return nodes\n .map((node) => printer.printNode(ts.EmitHint.Unspecified, node, file))\n .join(\"\\n\");\n}\n\nexport function printFile(sourceFile: ts.SourceFile) {\n return printer.printFile(sourceFile);\n}\n\nexport function isValidIdentifier(str: string) {\n if (!str.length || str.trim() !== str) return false;\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest);\n return (\n !!node &&\n node.kind === ts.SyntaxKind.Identifier &&\n ts.identifierToKeywordKind(node) === undefined\n );\n}\n\nexport function updateVariableDeclaration(\n node: ts.VariableDeclaration,\n updates: Partial<ts.VariableDeclaration>,\n) {\n return ts.factory.updateVariableDeclaration(\n node,\n updates.name || node.name,\n updates.exclamationToken || node.exclamationToken,\n updates.type || node.type,\n updates.initializer || node.initializer,\n );\n}\n\nexport function updateFunctionDeclaration(\n node: ts.FunctionDeclaration,\n updates: Partial<ts.FunctionDeclaration>,\n) {\n return ts.factory.updateFunctionDeclaration(\n node,\n updates.modifiers || node.modifiers,\n updates.asteriskToken || node.asteriskToken,\n updates.name || node.name,\n updates.typeParameters || node.typeParameters,\n updates.parameters || node.parameters,\n updates.type || node.type,\n updates.body || node.body,\n );\n}\n","import _ from \"lodash\";\nimport * as cg from \"./tscodegen\";\nimport ts from \"typescript\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport { ServerObject } from \"../helpers/openApi3-x\";\n\nconst factory = ts.factory;\n\nfunction createTemplate(url: string) {\n const tokens = url.split(/{([\\s\\S]+?)}/g);\n const chunks = _.chunk(tokens.slice(1), 2);\n return cg.createTemplateString(\n tokens[0],\n chunks.map(([expression, literal]) => ({\n expression: factory.createIdentifier(expression),\n literal,\n })),\n );\n}\n\nfunction createServerFunction(\n template: string,\n vars: Record<string, OpenAPIV3.ServerVariableObject>,\n) {\n const params = [\n cg.createParameter(\n cg.createObjectBinding(\n Object.entries(vars || {}).map(([name, value]) => {\n return {\n name,\n initializer: cg.createLiteral(value.default),\n };\n }),\n ),\n {\n type: factory.createTypeLiteralNode(\n Object.entries(vars || {}).map(([name, value]) => {\n return cg.createPropertySignature({\n name,\n type: value.enum\n ? cg.createEnumTypeNode(value.enum)\n : factory.createUnionTypeNode([\n cg.keywordType.string,\n cg.keywordType.number,\n cg.keywordType.boolean,\n ]),\n });\n }),\n ),\n },\n ),\n ];\n\n return cg.createArrowFunction(params, createTemplate(template));\n}\n\nfunction generateServerExpression(server: ServerObject) {\n return server.variables\n ? createServerFunction(server.url, server.variables)\n : factory.createStringLiteral(server.url);\n}\n\nfunction defaultUrl(server?: ServerObject) {\n if (!server) return \"/\";\n const { url, variables } = server;\n if (!variables) return url;\n return url.replace(/\\{(.+?)\\}/g, (m, name) =>\n variables[name] ? String(variables[name].default) : m,\n );\n}\n\nexport function defaultBaseUrl(servers?: ServerObject[]) {\n return defaultUrl(servers?.[0]);\n}\n\nfunction serverName(server: ServerObject, index: number) {\n return server.description\n ? _.camelCase(server.description.replace(/\\W+/, \" \"))\n : `server${index + 1}`;\n}\n\nexport function generateServers(servers: ServerObject[]) {\n return cg.createObjectLiteral(\n servers.map((server, i) => [\n serverName(server, i),\n generateServerExpression(server),\n ]),\n );\n}\n\nexport function createServersStatement(servers: ServerObject[]) {\n return ts.factory.createVariableStatement(\n [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n ts.factory.createVariableDeclarationList(\n [\n ts.factory.createVariableDeclaration(\n \"servers\",\n undefined,\n undefined,\n generateServers(servers),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n );\n}\n","import ts, {\n InterfaceDeclaration,\n Statement,\n TypeAliasDeclaration,\n TypeReferenceNode,\n} from \"typescript\";\nimport type { OazapftsOptions } from \"./\";\nimport type {\n Document,\n SchemaObject,\n ServerObject,\n} from \"./helpers/openApi3-x\";\nimport { defaultBaseUrl } from \"./generate/generateServers\";\nimport _ from \"lodash\";\nimport { CustomHeaders } from \"@oazapfts/runtime\";\n\n// ─── Data types for template parts ──────────────────────────────────────────\n\nexport type ImportSpecifier = {\n name: string;\n as?: string;\n};\nexport type DefaultImport = [string, { from: string }];\nexport type NamespaceImport = [{ namespace: string }, { from: string }];\nexport type ImportsWithoutDefault = [\n (ImportSpecifier | string)[],\n { from: string },\n];\nexport type ImportWithDefault = [\n string,\n (ImportSpecifier | string)[],\n { from: string },\n];\n\nexport type Import =\n | string\n | ImportsWithoutDefault\n | DefaultImport\n | ImportWithDefault\n | NamespaceImport;\n\nexport type OnlyMode = \"readOnly\" | \"writeOnly\";\nexport type OnlyModes = Record<OnlyMode, boolean>;\n\nexport type ReadonlyDeep<T> = {\n readonly [P in keyof T]: ReadonlyDeep<T[P]>;\n};\n\nexport type Defaults = {\n baseUrl?: string;\n headers?: CustomHeaders;\n FormData?: ts.ClassExpression | ts.Identifier;\n fetch?: ts.FunctionExpression | ts.ArrowFunction | ts.Identifier;\n};\n\nexport type OazapftsContext = {\n readonly opts: ReadonlyDeep<OazapftsOptions>;\n readonly spec: Document;\n\n /** Banner comment at the top of the file (the text content, not including comment markers) */\n banner: string;\n /** Import declarations (AST nodes) */\n imports: Import[];\n /** Runtime defaults (baseUrl, etc.) - will be generated as `export const defaults = { ... }` */\n defaults: Defaults;\n /** Server definitions - will be generated as `export const servers = { ... }` */\n servers: ServerObject[];\n /** Initialization statements (e.g., `const oazapfts = Oazapfts.runtime(defaults)`) */\n init: Statement[];\n\n // see `preprocessComponents` for the definition of a discriminating schema\n discriminatingSchemas: Set<SchemaObject>;\n\n aliases: (TypeAliasDeclaration | InterfaceDeclaration)[];\n\n enumAliases: Statement[];\n enumRefs: Record<string, { values: string; type: TypeReferenceNode }>;\n\n // Collect the types of all referenced schemas so we can export them later\n // Referenced schemas can be pointing at the following versions:\n // - \"base\": The regular type/interface e.g. ExampleSchema\n // - \"readOnly\": The readOnly version e.g. ExampleSchemaRead\n // - \"writeOnly\": The writeOnly version e.g. ExampleSchemaWrite\n refs: Record<\n string,\n {\n base: TypeReferenceNode;\n readOnly?: TypeReferenceNode;\n writeOnly?: TypeReferenceNode;\n }\n >;\n\n // Maps a referenced schema to its readOnly/writeOnly status\n // This field should be used exclusively within the `checkSchemaOnlyMode` method\n refsOnlyMode: Map<string, OnlyModes>;\n\n // Keep track of already used type aliases\n typeAliases: Record<string, number>;\n};\n\nexport function createContext(\n inputSpec: Document,\n opts: OazapftsContext[\"opts\"] = {},\n): OazapftsContext {\n const spec = _.cloneDeep(inputSpec);\n\n return {\n opts,\n spec,\n\n // Template parts\n banner: `DO NOT MODIFY - This file has been generated using oazapfts.\nSee https://www.npmjs.com/package/oazapfts`,\n imports: [\n [{ namespace: \"Oazapfts\" }, { from: \"@oazapfts/runtime\" }],\n [{ namespace: \"QS\" }, { from: \"@oazapfts/runtime/query\" }],\n ],\n defaults: { baseUrl: defaultBaseUrl(spec.servers), headers: {} },\n servers: spec.servers || [],\n init: createInit(),\n\n // Internal state\n discriminatingSchemas: new Set(),\n aliases: [],\n enumAliases: [],\n enumRefs: {},\n refs: {},\n refsOnlyMode: new Map(),\n typeAliases: {},\n };\n}\n\n/** Creates: const oazapfts = Oazapfts.runtime(defaults); */\nfunction createInit(): Statement[] {\n return [\n ts.factory.createVariableStatement(\n undefined,\n ts.factory.createVariableDeclarationList(\n [\n ts.factory.createVariableDeclaration(\n \"oazapfts\",\n undefined,\n undefined,\n ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(\n ts.factory.createIdentifier(\"Oazapfts\"),\n \"runtime\",\n ),\n undefined,\n [ts.factory.createIdentifier(\"defaults\")],\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n ];\n}\n"],"names":["onlyModeSuffixes","getOnlyModeSuffix","onlyMode","toIdentifier","s","upper","cc","_","isValidIdentifier","factory","ts","questionToken","createQuestionToken","token","keywordType","createKeywordType","type","modifier","createLiteral","v","createEnumTypeNode","values","types","createTypeAliasDeclaration","modifiers","name","typeParameters","createInterfaceAliasDeclaration","inheritedNodeNames","heritageClauses","extendedInterfaceName","toExpression","ex","createCall","expression","typeArgs","args","createMethodCall","method","opts","createObjectLiteral","props","identifier","createPropertyAssignment","propertyName","block","statements","createArrowFunction","parameters","body","equalsGreaterThanToken","createFunctionDeclaration","asteriskToken","createClassDeclaration","members","createConstructor","createMethod","createParameter","dotDotDotToken","initializer","createPropertySignature","createIndexSignature","indexName","indexType","createObjectBinding","elements","createTemplateString","head","spans","literal","i","findNode","nodes","kind","test","node","getName","getFirstDeclarationName","n","findFirstVariableDeclaration","statement","first","changePropertyValue","o","property","value","p","createTransformer","visitor","context","rootNode","visit","result","transform","source","visitors","appendNodes","array","addComment","comment","printer","printNode","file","printNodes","printFile","sourceFile","str","updateVariableDeclaration","updates","updateFunctionDeclaration","createTemplate","url","tokens","chunks","cg.createTemplateString","createServerFunction","template","vars","params","cg.createParameter","cg.createObjectBinding","cg.createLiteral","cg.createPropertySignature","cg.createEnumTypeNode","cg.keywordType","cg.createArrowFunction","generateServerExpression","server","defaultUrl","variables","m","defaultBaseUrl","servers","serverName","index","generateServers","cg.createObjectLiteral","createServersStatement","createContext","inputSpec","spec","createInit"],"mappings":";;AAEA,MAAMA,IAA6C;AAAA,EACjD,UAAU;AAAA,EACV,WAAW;AACb;AAEO,SAASC,EAAkBC,GAAqB;AACrD,SAAKA,IACEF,EAAiBE,CAAQ,IADV;AAExB;ACLO,SAASC,EAAaC,GAAWC,IAAQ,IAAOH,GAAqB;AAC1E,MAAII,IAAKC,EAAE,UAAUH,CAAC,IAAIH,EAAkBC,CAAQ;AAEpD,SADIG,MAAOC,IAAKC,EAAE,WAAWD,CAAE,IAC3BE,EAAkBF,CAAE,IAAUA,IAC3B,MAAMA;AACf;ACPA,MAAMG,IAAUC,EAAG,SAENC,IAAgBF,EAAQ,YAAYC,EAAG,WAAW,aAAa;AAErE,SAASE,EAAoBC,GAAoC;AACtE,MAAKA;AACL,WAAIA,MAAU,KA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A,UAC1C;AAAA,QACF;AAAA,QAEFA,EAAG,UAAU;AAAA,MAAA;AAAA,IACf;AAAA,EACF;AAEJ;"}
|
package/dist/context.d.ts
CHANGED
|
@@ -41,6 +41,10 @@ declare type Document_2 = OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
|
41
41
|
|
|
42
42
|
declare type Document_2_2 = OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
43
43
|
|
|
44
|
+
declare type EnumStyle = (typeof enumStyleOptions)[number];
|
|
45
|
+
|
|
46
|
+
declare const enumStyleOptions: readonly ["union", "enum", "as-const"];
|
|
47
|
+
|
|
44
48
|
declare type HttpMethod = (typeof HttpMethods)[number];
|
|
45
49
|
|
|
46
50
|
declare const HttpMethods: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
@@ -164,11 +168,25 @@ declare type OazapftsOptions = {
|
|
|
164
168
|
exclude?: string[];
|
|
165
169
|
optimistic?: boolean;
|
|
166
170
|
unionUndefined?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Use `enumStyle: "enum"` instead.
|
|
173
|
+
*/
|
|
167
174
|
useEnumType?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Controls how enums are generated in TypeScript.
|
|
177
|
+
* Takes precedence over `useEnumType` if both are specified.
|
|
178
|
+
*/
|
|
179
|
+
enumStyle?: EnumStyle;
|
|
168
180
|
mergeReadWriteOnly?: boolean;
|
|
169
181
|
useUnknown?: boolean;
|
|
170
182
|
argumentStyle?: ArgumentStyle;
|
|
171
183
|
allSchemas?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* When true, skip generating deprecated legacy method aliases for backward
|
|
186
|
+
* compatibility. Only the primary normalized operationId-based names will
|
|
187
|
+
* be generated.
|
|
188
|
+
*/
|
|
189
|
+
futureStripLegacyMethods?: boolean;
|
|
172
190
|
/**
|
|
173
191
|
* Plugins to apply during code generation.
|
|
174
192
|
* Each plugin receives hooks and can tap into generation steps.
|
package/dist/context.js
CHANGED