@acrool/rtk-query-codegen-openapi 0.0.2-test.2 → 0.0.2-test.4
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 +6 -0
- package/lib/bin/cli.mjs +1 -1
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +21 -14
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +21 -14
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -6
- package/src/bin/cli.ts +1 -1
- package/src/generate.ts +28 -14
package/README.md
CHANGED
|
@@ -18,3 +18,9 @@ This is a utility library meant to be used with [RTK Query](https://redux-toolki
|
|
|
18
18
|
### Documentation
|
|
19
19
|
|
|
20
20
|
[View the RTK Query Code Generation docs](https://redux-toolkit.js.org/rtk-query/usage/code-generation)
|
|
21
|
+
|
|
22
|
+
### Test
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
yarn build && npx acrool-rtk-query-codegen-openapi ./rtk-query-codegen.config.ts
|
|
26
|
+
```
|
package/lib/bin/cli.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{fileURLToPath as l}from"node:url";var p=()=>l(import.meta.url);var c=p();import{generateEndpoints as m,parseConfig as f}from"@rtk-query
|
|
2
|
+
import{fileURLToPath as l}from"node:url";var p=()=>l(import.meta.url);var c=p();import{generateEndpoints as m,parseConfig as f}from"@acrool/rtk-query-codegen-openapi";import r from"commander";import{createRequire as u}from"node:module";import{dirname as g,resolve as d}from"node:path";var e=u(c),o=!1;try{e.resolve("esbuild")&&e.resolve("esbuild-runner")&&e("esbuild-runner/register"),o=!0}catch{}try{o||(e.resolve("typescript")&&e.resolve("ts-node")&&e("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),o=!0)}catch{}var h=e("../../package.json");r.version(h.version).usage("</path/to/config.js>").parse(process.argv);var t=r.args[0];r.args.length===0||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(t)?r.help():(/\.[mc]?tsx?$/.test(t)&&!o&&(console.error("Encountered a TypeScript configfile, but neither esbuild-runner nor ts-node are installed."),process.exit(1)),v(d(process.cwd(),t)));async function v(s){process.chdir(g(s));let n=e(s);for(let i of f(n.default??n))try{console.log(`Generating ${i.outputFile}`),await m(i),console.log("Done")}catch(a){console.error(a),process.exit(1)}}
|
|
3
3
|
//# sourceMappingURL=cli.mjs.map
|
package/lib/bin/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../node_modules/tsup/assets/esm_shims.js","../../src/bin/cli.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","#!/usr/bin/env node\n\nimport { generateEndpoints, parseConfig } from '@rtk-query
|
|
1
|
+
{"version":3,"sources":["../../node_modules/tsup/assets/esm_shims.js","../../src/bin/cli.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","#!/usr/bin/env node\n\nimport { generateEndpoints, parseConfig } from '@acrool/rtk-query-codegen-openapi';\nimport program from 'commander';\nimport { createRequire } from 'node:module';\nimport { dirname, resolve } from 'node:path';\n\nconst require = createRequire(__filename);\n\nlet ts = false;\ntry {\n if (require.resolve('esbuild') && require.resolve('esbuild-runner')) {\n require('esbuild-runner/register');\n }\n ts = true;\n} catch {}\n\ntry {\n if (!ts) {\n if (require.resolve('typescript') && require.resolve('ts-node')) {\n (require('ts-node') as typeof import('ts-node')).register({\n transpileOnly: true,\n compilerOptions: {\n target: 'es6',\n module: 'commonjs',\n },\n });\n }\n\n ts = true;\n }\n} catch {}\n\n// tslint:disable-next-line\nconst meta = require('../../package.json');\n\nprogram.version(meta.version).usage('</path/to/config.js>').parse(process.argv);\n\nconst configFile = program.args[0];\n\nif (program.args.length === 0 || !/\\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(configFile)) {\n program.help();\n} else {\n if (/\\.[mc]?tsx?$/.test(configFile) && !ts) {\n console.error('Encountered a TypeScript configfile, but neither esbuild-runner nor ts-node are installed.');\n process.exit(1);\n }\n run(resolve(process.cwd(), configFile));\n}\n\nasync function run(configFile: string) {\n process.chdir(dirname(configFile));\n\n const unparsedConfig = require(configFile);\n\n for (const config of parseConfig(unparsedConfig.default ?? unparsedConfig)) {\n try {\n console.log(`Generating ${config.outputFile}`);\n await generateEndpoints(config);\n console.log(`Done`);\n } catch (err) {\n console.error(err);\n process.exit(1);\n }\n }\n}\n"],"mappings":";AAEA,OAAS,iBAAAA,MAAqB,WAE9B,IAAMC,EAAc,IAAMD,EAAc,YAAY,GAAG,EAIhD,IAAME,EAA6BC,EAAY,ECNtD,OAAS,qBAAAC,EAAmB,eAAAC,MAAmB,oCAC/C,OAAOC,MAAa,YACpB,OAAS,iBAAAC,MAAqB,cAC9B,OAAS,WAAAC,EAAS,WAAAC,MAAe,YAEjC,IAAMC,EAAUH,EAAcI,CAAU,EAEpCC,EAAK,GACT,GAAI,CACEF,EAAQ,QAAQ,SAAS,GAAKA,EAAQ,QAAQ,gBAAgB,GAChEA,EAAQ,yBAAyB,EAEnCE,EAAK,EACP,MAAQ,CAAC,CAET,GAAI,CACGA,IACCF,EAAQ,QAAQ,YAAY,GAAKA,EAAQ,QAAQ,SAAS,GAC3DA,EAAQ,SAAS,EAA+B,SAAS,CACxD,cAAe,GACf,gBAAiB,CACf,OAAQ,MACR,OAAQ,UACV,CACF,CAAC,EAGHE,EAAK,GAET,MAAQ,CAAC,CAGT,IAAMC,EAAOH,EAAQ,oBAAoB,EAEzCJ,EAAQ,QAAQO,EAAK,OAAO,EAAE,MAAM,sBAAsB,EAAE,MAAM,QAAQ,IAAI,EAE9E,IAAMC,EAAaR,EAAQ,KAAK,CAAC,EAE7BA,EAAQ,KAAK,SAAW,GAAK,CAAC,gCAAgC,KAAKQ,CAAU,EAC/ER,EAAQ,KAAK,GAET,eAAe,KAAKQ,CAAU,GAAK,CAACF,IACtC,QAAQ,MAAM,4FAA4F,EAC1G,QAAQ,KAAK,CAAC,GAEhBG,EAAIN,EAAQ,QAAQ,IAAI,EAAGK,CAAU,CAAC,GAGxC,eAAeC,EAAID,EAAoB,CACrC,QAAQ,MAAMN,EAAQM,CAAU,CAAC,EAEjC,IAAME,EAAiBN,EAAQI,CAAU,EAEzC,QAAWG,KAAUZ,EAAYW,EAAe,SAAWA,CAAc,EACvE,GAAI,CACF,QAAQ,IAAI,cAAcC,EAAO,UAAU,EAAE,EAC7C,MAAMb,EAAkBa,CAAM,EAC9B,QAAQ,IAAI,MAAM,CACpB,OAASC,EAAK,CACZ,QAAQ,MAAMA,CAAG,EACjB,QAAQ,KAAK,CAAC,CAChB,CAEJ","names":["fileURLToPath","getFilename","__filename","getFilename","generateEndpoints","parseConfig","program","createRequire","dirname","resolve","require","__filename","ts","meta","configFile","run","unparsedConfig","config","err"]}
|
package/lib/index.js
CHANGED
|
@@ -497,6 +497,7 @@ async function generateApi(spec, {
|
|
|
497
497
|
factory.createSourceFile(
|
|
498
498
|
[
|
|
499
499
|
generateImportNode(apiFile, { [apiImport]: "api" }),
|
|
500
|
+
generateImportNode("@acrool/react-fetcher", { IRestFulEndpointsQueryReturn: "IRestFulEndpointsQueryReturn" }),
|
|
500
501
|
...tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : [],
|
|
501
502
|
generateCreateApiCall({
|
|
502
503
|
tag,
|
|
@@ -597,9 +598,7 @@ async function generateApi(spec, {
|
|
|
597
598
|
);
|
|
598
599
|
const operationParameters = apiGen.resolveArray(operation.parameters);
|
|
599
600
|
const pathItemParameters = apiGen.resolveArray(pathItem.parameters).filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));
|
|
600
|
-
const parameters = (0, import_generate3.supportDeepObjects)([...pathItemParameters, ...operationParameters]).filter(
|
|
601
|
-
argumentMatches(overrides?.parameterFilter)
|
|
602
|
-
);
|
|
601
|
+
const parameters = (0, import_generate3.supportDeepObjects)([...pathItemParameters, ...operationParameters]).filter(argumentMatches(overrides?.parameterFilter)).filter((param) => param.in !== "header");
|
|
603
602
|
const allNames = parameters.map((p) => p.name);
|
|
604
603
|
const queryArg = {};
|
|
605
604
|
function generateName(name, potentialPrefix) {
|
|
@@ -687,7 +686,10 @@ async function generateApi(spec, {
|
|
|
687
686
|
operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,
|
|
688
687
|
type: isQuery2 ? "query" : "mutation",
|
|
689
688
|
Response: ResponseTypeName,
|
|
690
|
-
QueryArg
|
|
689
|
+
QueryArg: factory.createTypeReferenceNode(
|
|
690
|
+
factory.createIdentifier("IRestFulEndpointsQueryReturn"),
|
|
691
|
+
[QueryArg]
|
|
692
|
+
),
|
|
691
693
|
queryFn: generateQueryFn({
|
|
692
694
|
operationDefinition,
|
|
693
695
|
queryArg,
|
|
@@ -711,13 +713,14 @@ async function generateApi(spec, {
|
|
|
711
713
|
const { path: path4, verb } = operationDefinition;
|
|
712
714
|
const bodyParameter = Object.values(queryArg).find((def) => def.origin === "body");
|
|
713
715
|
const rootObject = factory.createIdentifier("queryArg");
|
|
716
|
+
const variablesObject = factory.createPropertyAccessExpression(rootObject, factory.createIdentifier("variables"));
|
|
714
717
|
function pickParams(paramIn) {
|
|
715
718
|
return Object.values(queryArg).filter((def) => def.origin === "param" && def.param.in === paramIn);
|
|
716
719
|
}
|
|
717
720
|
function createObjectLiteralProperty(parameters, propertyName) {
|
|
718
721
|
if (parameters.length === 0) return void 0;
|
|
719
722
|
const properties = parameters.map((param) => {
|
|
720
|
-
const value = isFlatArg ?
|
|
723
|
+
const value = isFlatArg ? variablesObject : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(param.name));
|
|
721
724
|
const encodedValue = encodeQueryParams2 && param.param?.in === "query" ? factory.createConditionalExpression(
|
|
722
725
|
value,
|
|
723
726
|
void 0,
|
|
@@ -737,7 +740,7 @@ async function generateApi(spec, {
|
|
|
737
740
|
return factory.createArrowFunction(
|
|
738
741
|
void 0,
|
|
739
742
|
void 0,
|
|
740
|
-
|
|
743
|
+
[factory.createParameterDeclaration(void 0, void 0, rootObject, void 0, void 0, void 0)],
|
|
741
744
|
void 0,
|
|
742
745
|
factory.createToken(import_typescript4.default.SyntaxKind.EqualsGreaterThanToken),
|
|
743
746
|
factory.createParenthesizedExpression(
|
|
@@ -745,7 +748,7 @@ async function generateApi(spec, {
|
|
|
745
748
|
[
|
|
746
749
|
factory.createPropertyAssignment(
|
|
747
750
|
factory.createIdentifier("url"),
|
|
748
|
-
generatePathExpression(path4, pickParams("path"),
|
|
751
|
+
generatePathExpression(path4, pickParams("path"), variablesObject, isFlatArg, encodePathParams2)
|
|
749
752
|
),
|
|
750
753
|
isQuery2 && verb.toUpperCase() === "GET" ? void 0 : factory.createPropertyAssignment(
|
|
751
754
|
factory.createIdentifier("method"),
|
|
@@ -753,11 +756,18 @@ async function generateApi(spec, {
|
|
|
753
756
|
),
|
|
754
757
|
bodyParameter === void 0 ? void 0 : factory.createPropertyAssignment(
|
|
755
758
|
factory.createIdentifier("body"),
|
|
756
|
-
isFlatArg ?
|
|
759
|
+
isFlatArg ? variablesObject : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(bodyParameter.name))
|
|
757
760
|
),
|
|
758
761
|
createObjectLiteralProperty(pickParams("cookie"), "cookies"),
|
|
759
|
-
createObjectLiteralProperty(pickParams("
|
|
760
|
-
|
|
762
|
+
createObjectLiteralProperty(pickParams("query"), "params"),
|
|
763
|
+
factory.createPropertyAssignment(
|
|
764
|
+
factory.createIdentifier("fetchOptions"),
|
|
765
|
+
factory.createPropertyAccessChain(
|
|
766
|
+
rootObject,
|
|
767
|
+
factory.createToken(import_typescript4.default.SyntaxKind.QuestionDotToken),
|
|
768
|
+
factory.createIdentifier("fetchOptions")
|
|
769
|
+
)
|
|
770
|
+
)
|
|
761
771
|
].filter(removeUndefined),
|
|
762
772
|
false
|
|
763
773
|
)
|
|
@@ -771,9 +781,6 @@ async function generateApi(spec, {
|
|
|
771
781
|
return {};
|
|
772
782
|
}
|
|
773
783
|
}
|
|
774
|
-
function accessProperty(rootObject, propertyName) {
|
|
775
|
-
return (0, import_generate3.isValidIdentifier)(propertyName) ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName)) : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));
|
|
776
|
-
}
|
|
777
784
|
function generatePathExpression(path4, pathParameters, rootObject, isFlatArg, encodePathParams) {
|
|
778
785
|
const expressions = [];
|
|
779
786
|
const head = path4.replace(/\{(.*?)}(.*?)(?=\{|$)/g, (_, expression, literal) => {
|
|
@@ -787,7 +794,7 @@ function generatePathExpression(path4, pathParameters, rootObject, isFlatArg, en
|
|
|
787
794
|
return expressions.length ? factory.createTemplateExpression(
|
|
788
795
|
factory.createTemplateHead(head),
|
|
789
796
|
expressions.map(([prop, literal], index) => {
|
|
790
|
-
const value = isFlatArg ? rootObject :
|
|
797
|
+
const value = isFlatArg ? rootObject : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(prop));
|
|
791
798
|
const encodedValue = encodePathParams ? factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [
|
|
792
799
|
factory.createCallExpression(factory.createIdentifier("String"), void 0, [value])
|
|
793
800
|
]) : value;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/generate.ts","../src/utils/factory.ts","../src/codegen.ts","../src/generators/react-hooks.ts","../src/utils/capitalize.ts","../src/types.ts","../src/utils/getOperationDefinitions.ts","../src/utils/getV3Doc.ts","../src/utils/isQuery.ts","../src/utils/isValidUrl.ts","../src/utils/prettier.ts","../src/utils/removeUndefined.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { generateApi } from './generate';\nimport type { CommonOptions, ConfigFile, GenerationOptions, OutputFileOptions } from './types';\nimport { isValidUrl, prettify } from './utils';\nexport type { ConfigFile } from './types';\n\nconst require = createRequire(__filename);\n\nexport async function generateEndpoints(options: GenerationOptions): Promise<string | void> {\n const schemaLocation = options.schemaFile;\n\n const schemaAbsPath = isValidUrl(options.schemaFile)\n ? options.schemaFile\n : path.resolve(process.cwd(), schemaLocation);\n\n const sourceCode = await enforceOazapftsTsVersion(async () => {\n return generateApi(schemaAbsPath, options);\n });\n const { outputFile, prettierConfigFile } = options;\n if (outputFile) {\n fs.writeFileSync(\n path.resolve(process.cwd(), outputFile),\n await prettify(outputFile, sourceCode, prettierConfigFile)\n );\n } else {\n return await prettify(null, sourceCode, prettierConfigFile);\n }\n}\n\nexport function parseConfig(fullConfig: ConfigFile) {\n const outFiles: (CommonOptions & OutputFileOptions)[] = [];\n\n if ('outputFiles' in fullConfig) {\n const { outputFiles, ...commonConfig } = fullConfig;\n for (const [outputFile, specificConfig] of Object.entries(outputFiles)) {\n outFiles.push({\n ...commonConfig,\n ...specificConfig,\n outputFile,\n });\n }\n } else {\n outFiles.push(fullConfig);\n }\n return outFiles;\n}\n\n/**\n * Enforces `oazapfts` to use the same TypeScript version as this module itself uses.\n * That should prevent enums from running out of sync if both libraries use different TS versions.\n */\nfunction enforceOazapftsTsVersion<T>(cb: () => T): T {\n const ozTsPath = require.resolve('typescript', { paths: [require.resolve('oazapfts')] });\n const tsPath = require.resolve('typescript');\n const originalEntry = require.cache[ozTsPath];\n try {\n require.cache[ozTsPath] = require.cache[tsPath];\n return cb();\n } finally {\n if (originalEntry) {\n require.cache[ozTsPath] = originalEntry;\n } else {\n delete require.cache[ozTsPath];\n }\n }\n}\n","import camelCase from 'lodash.camelcase';\nimport path from 'node:path';\nimport ApiGenerator, {\n getOperationName as _getOperationName,\n getReferenceName,\n isReference,\n supportDeepObjects,\n createPropertyAssignment,\n createQuestionToken,\n isValidIdentifier,\n keywordType,\n} from 'oazapfts/generate';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport ts from 'typescript';\nimport type { ObjectPropertyDefinitions } from './codegen';\nimport { generateCreateApiCall, generateEndpointDefinition, generateImportNode, generateTagTypes } from './codegen';\nimport { generateReactHooks } from './generators/react-hooks';\nimport type {\n EndpointMatcher,\n EndpointOverrides,\n GenerationOptions,\n OperationDefinition,\n ParameterDefinition,\n ParameterMatcher,\n TextMatcher,\n} from './types';\nimport { capitalize, getOperationDefinitions, getV3Doc, removeUndefined, isQuery as testIsQuery } from './utils';\nimport { factory } from './utils/factory';\n\nconst generatedApiName = 'injectedRtkApi';\nconst v3DocCache: Record<string, OpenAPIV3.Document> = {};\n\nfunction defaultIsDataResponse(code: string, includeDefault: boolean) {\n if (includeDefault && code === 'default') {\n return true;\n }\n const parsedCode = Number(code);\n return !Number.isNaN(parsedCode) && parsedCode >= 200 && parsedCode < 300;\n}\n\nfunction getOperationName({ verb, path, operation }: Pick<OperationDefinition, 'verb' | 'path' | 'operation'>) {\n return _getOperationName(verb, path, operation.operationId);\n}\n\nfunction getTags({ verb, pathItem }: Pick<OperationDefinition, 'verb' | 'pathItem'>): string[] {\n return verb ? pathItem[verb]?.tags || [] : [];\n}\n\nfunction patternMatches(pattern?: TextMatcher) {\n const filters = Array.isArray(pattern) ? pattern : [pattern];\n return function matcher(operationName: string) {\n if (!pattern) return true;\n return filters.some((filter) =>\n typeof filter === 'string' ? filter === operationName : filter?.test(operationName)\n );\n };\n}\n\nfunction operationMatches(pattern?: EndpointMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(operationDefinition: OperationDefinition) {\n if (!pattern) return true;\n const operationName = getOperationName(operationDefinition);\n return checkMatch(operationName, operationDefinition);\n };\n}\n\nfunction argumentMatches(pattern?: ParameterMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(argumentDefinition: ParameterDefinition) {\n if (!pattern || argumentDefinition.in === 'path') return true;\n const argumentName = argumentDefinition.name;\n return checkMatch(argumentName, argumentDefinition);\n };\n}\n\nfunction withQueryComment<T extends ts.Node>(node: T, def: QueryArgDefinition, hasTrailingNewLine: boolean): T {\n const comment = def.origin === 'param' ? def.param.description : def.body.description;\n if (comment) {\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${comment} `,\n hasTrailingNewLine\n );\n }\n return node;\n}\n\nexport function getOverrides(\n operation: OperationDefinition,\n endpointOverrides?: EndpointOverrides[]\n): EndpointOverrides | undefined {\n return endpointOverrides?.find((override) => operationMatches(override.pattern)(operation));\n}\n\nexport async function generateApi(\n spec: string,\n {\n apiFile,\n apiImport = 'api',\n exportName = 'enhancedApi',\n argSuffix = 'ApiArg',\n responseSuffix = 'ApiResponse',\n operationNameSuffix = '',\n hooks = false,\n tag = false,\n outputFile,\n isDataResponse = defaultIsDataResponse,\n filterEndpoints,\n endpointOverrides,\n unionUndefined,\n encodePathParams = false,\n encodeQueryParams = false,\n flattenArg = false,\n includeDefault = false,\n useEnumType = false,\n mergeReadWriteOnly = false,\n httpResolverOptions,\n }: GenerationOptions\n) {\n const v3Doc = (v3DocCache[spec] ??= await getV3Doc(spec, httpResolverOptions));\n\n const apiGen = new ApiGenerator(v3Doc, {\n unionUndefined,\n useEnumType,\n mergeReadWriteOnly,\n });\n\n // temporary workaround for https://github.com/oazapfts/oazapfts/issues/491\n if (apiGen.spec.components?.schemas) {\n apiGen.preprocessComponents(apiGen.spec.components.schemas);\n }\n\n const operationDefinitions = getOperationDefinitions(v3Doc).filter(operationMatches(filterEndpoints));\n\n const resultFile = ts.createSourceFile(\n 'someFileName.ts',\n '',\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS\n );\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n const interfaces: Record<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration> = {};\n function registerInterface(declaration: ts.InterfaceDeclaration | ts.TypeAliasDeclaration) {\n const name = declaration.name.escapedText.toString();\n if (name in interfaces) {\n throw new Error(`interface/type alias ${name} already registered`);\n }\n interfaces[name] = declaration;\n return declaration;\n }\n\n if (outputFile) {\n outputFile = path.resolve(process.cwd(), outputFile);\n if (apiFile.startsWith('.')) {\n apiFile = path.relative(path.dirname(outputFile), apiFile);\n apiFile = apiFile.replace(/\\\\/g, '/');\n if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;\n }\n }\n apiFile = apiFile.replace(/\\.[jt]sx?$/, '');\n\n return printer.printNode(\n ts.EmitHint.Unspecified,\n factory.createSourceFile(\n [\n generateImportNode(apiFile, { [apiImport]: 'api' }),\n ...(tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : []),\n generateCreateApiCall({\n tag,\n endpointDefinitions: factory.createObjectLiteralExpression(\n operationDefinitions.map((operationDefinition) =>\n generateEndpoint({\n operationDefinition,\n overrides: getOverrides(operationDefinition, endpointOverrides),\n })\n ),\n true\n ),\n }),\n factory.createExportDeclaration(\n undefined,\n false,\n factory.createNamedExports([\n factory.createExportSpecifier(\n factory.createIdentifier(generatedApiName),\n factory.createIdentifier(exportName)\n ),\n ]),\n undefined\n ),\n ...Object.values(interfaces),\n ...apiGen.aliases,\n ...apiGen.enumAliases,\n ...(hooks\n ? [\n generateReactHooks({\n exportName: generatedApiName,\n operationDefinitions,\n endpointOverrides,\n config: hooks,\n }),\n ]\n : []),\n ],\n factory.createToken(ts.SyntaxKind.EndOfFileToken),\n ts.NodeFlags.None\n ),\n resultFile\n );\n\n function extractAllTagTypes({ operationDefinitions }: { operationDefinitions: OperationDefinition[] }) {\n const allTagTypes = new Set<string>();\n\n for (const operationDefinition of operationDefinitions) {\n const { verb, pathItem } = operationDefinition;\n for (const tag of getTags({ verb, pathItem })) {\n allTagTypes.add(tag);\n }\n }\n return [...allTagTypes];\n }\n\n function generateEndpoint({\n operationDefinition,\n overrides,\n }: {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n }) {\n const {\n verb,\n path,\n pathItem,\n operation,\n operation: { responses, requestBody },\n } = operationDefinition;\n const operationName = getOperationName({ verb, path, operation });\n const tags = tag ? getTags({ verb, pathItem }) : [];\n const isQuery = testIsQuery(verb, overrides);\n\n const returnsJson = apiGen.getResponseType(responses) === 'json';\n let ResponseType: ts.TypeNode = factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n if (returnsJson) {\n const returnTypes = Object.entries(responses || {})\n .map(\n ([code, response]) =>\n [\n code,\n apiGen.resolve(response),\n apiGen.getTypeFromResponse(response, 'readOnly') ||\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n ] as const\n )\n .filter(([status, response]) =>\n isDataResponse(status, includeDefault, apiGen.resolve(response), responses || {})\n )\n .filter(([_1, _2, type]) => type !== keywordType.void)\n .map(([code, response, type]) =>\n ts.addSyntheticLeadingComment(\n { ...type },\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* status ${code} ${response.description} `,\n false\n )\n );\n if (returnTypes.length > 0) {\n ResponseType = factory.createUnionTypeNode(returnTypes);\n }\n }\n\n const ResponseTypeName = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + responseSuffix),\n undefined,\n ResponseType\n )\n ).name\n );\n\n const operationParameters = apiGen.resolveArray(operation.parameters);\n const pathItemParameters = apiGen\n .resolveArray(pathItem.parameters)\n .filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));\n\n const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters]).filter(\n argumentMatches(overrides?.parameterFilter)\n );\n\n const allNames = parameters.map((p) => p.name);\n const queryArg: QueryArgDefinitions = {};\n function generateName(name: string, potentialPrefix: string) {\n const isPureSnakeCase = /^[a-zA-Z][a-zA-Z0-9_]*$/.test(name);\n // prefix with `query`, `path` or `body` if there are multiple paramters with the same name\n const hasNamingConflict = allNames.filter((n) => n === name).length > 1;\n if (hasNamingConflict) {\n name = `${potentialPrefix}_${name}`;\n }\n // convert to camelCase if the name is pure snake_case and there are no naming conflicts\n const camelCaseName = camelCase(name);\n if (isPureSnakeCase && !allNames.includes(camelCaseName)) {\n name = camelCaseName;\n }\n // if there are still any naming conflicts, prepend with underscore\n while (name in queryArg) {\n name = `_${name}`;\n }\n return name;\n }\n\n for (const param of parameters) {\n const name = generateName(param.name, param.in);\n queryArg[name] = {\n origin: 'param',\n name,\n originalName: param.name,\n type: apiGen.getTypeFromSchema(isReference(param) ? param : param.schema, undefined, 'writeOnly'),\n required: param.required,\n param,\n };\n }\n\n if (requestBody) {\n const body = apiGen.resolve(requestBody);\n const schema = apiGen.getSchemaFromContent(body.content);\n const type = apiGen.getTypeFromSchema(schema);\n const schemaName = camelCase(\n (type as any).name ||\n getReferenceName(schema) ||\n (typeof schema === 'object' && 'title' in schema && schema.title) ||\n 'body'\n );\n const name = generateName(schemaName in queryArg ? 'body' : schemaName, 'body');\n\n queryArg[name] = {\n origin: 'body',\n name,\n originalName: schemaName,\n type: apiGen.getTypeFromSchema(schema, undefined, 'writeOnly'),\n required: true,\n body,\n };\n }\n\n const propertyName = (name: string | ts.PropertyName): ts.PropertyName => {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);\n }\n return name;\n };\n\n const queryArgValues = Object.values(queryArg);\n\n const isFlatArg = flattenArg && queryArgValues.length === 1;\n const QueryArg = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + argSuffix),\n undefined,\n queryArgValues.length > 0\n ? isFlatArg\n ? withQueryComment(\n factory.createUnionTypeNode([\n queryArgValues[0].type,\n ...(!queryArgValues[0].required\n ? [factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)]\n : []),\n ]),\n queryArgValues[0],\n false\n )\n : factory.createTypeLiteralNode(\n queryArgValues.map((def) =>\n withQueryComment(\n factory.createPropertySignature(\n undefined,\n propertyName(def.name),\n createQuestionToken(!def.required),\n def.type\n ),\n def,\n true\n )\n )\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)\n )\n ).name\n );\n\n return generateEndpointDefinition({\n operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,\n type: isQuery ? 'query' : 'mutation',\n Response: ResponseTypeName,\n QueryArg,\n queryFn: generateQueryFn({\n operationDefinition,\n queryArg,\n isQuery,\n isFlatArg,\n encodePathParams,\n encodeQueryParams,\n }),\n extraEndpointsProps: isQuery\n ? generateQueryEndpointProps({ operationDefinition })\n : generateMutationEndpointProps({ operationDefinition }),\n tags,\n });\n }\n\n function generateQueryFn({\n operationDefinition,\n queryArg,\n isFlatArg,\n isQuery,\n encodePathParams,\n encodeQueryParams,\n }: {\n operationDefinition: OperationDefinition;\n queryArg: QueryArgDefinitions;\n isFlatArg: boolean;\n isQuery: boolean;\n encodePathParams: boolean;\n encodeQueryParams: boolean;\n }) {\n const { path, verb } = operationDefinition;\n\n const bodyParameter = Object.values(queryArg).find((def) => def.origin === 'body');\n\n const rootObject = factory.createIdentifier('queryArg');\n\n function pickParams(paramIn: string) {\n return Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === paramIn);\n }\n\n function createObjectLiteralProperty(parameters: QueryArgDefinition[], propertyName: string) {\n if (parameters.length === 0) return undefined;\n\n const properties = parameters.map((param) => {\n const value = isFlatArg ? rootObject : accessProperty(rootObject, param.name);\n\n const encodedValue =\n encodeQueryParams && param.param?.in === 'query'\n ? factory.createConditionalExpression(\n value,\n undefined,\n factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ]),\n undefined,\n factory.createIdentifier('undefined')\n )\n : value;\n\n return createPropertyAssignment(param.originalName, encodedValue);\n });\n\n return factory.createPropertyAssignment(\n factory.createIdentifier(propertyName),\n factory.createObjectLiteralExpression(properties, true)\n );\n }\n\n return factory.createArrowFunction(\n undefined,\n undefined,\n Object.keys(queryArg).length\n ? [factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)]\n : [],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(\n factory.createObjectLiteralExpression(\n [\n factory.createPropertyAssignment(\n factory.createIdentifier('url'),\n generatePathExpression(path, pickParams('path'), rootObject, isFlatArg, encodePathParams)\n ),\n isQuery && verb.toUpperCase() === 'GET'\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('method'),\n factory.createStringLiteral(verb.toUpperCase())\n ),\n bodyParameter === undefined\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('body'),\n isFlatArg\n ? rootObject\n : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(bodyParameter.name))\n ),\n createObjectLiteralProperty(pickParams('cookie'), 'cookies'),\n createObjectLiteralProperty(pickParams('header'), 'headers'),\n createObjectLiteralProperty(pickParams('query'), 'params'),\n ].filter(removeUndefined),\n false\n )\n )\n );\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateQueryEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateMutationEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n}\n\nfunction accessProperty(rootObject: ts.Identifier, propertyName: string) {\n return isValidIdentifier(propertyName)\n ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName))\n : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));\n}\n\nfunction generatePathExpression(\n path: string,\n pathParameters: QueryArgDefinition[],\n rootObject: ts.Identifier,\n isFlatArg: boolean,\n encodePathParams: boolean\n) {\n const expressions: Array<[string, string]> = [];\n\n const head = path.replace(/\\{(.*?)}(.*?)(?=\\{|$)/g, (_, expression, literal) => {\n const param = pathParameters.find((p) => p.originalName === expression);\n if (!param) {\n throw new Error(`path parameter ${expression} does not seem to be defined in '${path}'!`);\n }\n expressions.push([param.name, literal]);\n return '';\n });\n\n return expressions.length\n ? factory.createTemplateExpression(\n factory.createTemplateHead(head),\n expressions.map(([prop, literal], index) => {\n const value = isFlatArg ? rootObject : accessProperty(rootObject, prop);\n const encodedValue = encodePathParams\n ? factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ])\n : value;\n return factory.createTemplateSpan(\n encodedValue,\n index === expressions.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal)\n );\n })\n )\n : factory.createNoSubstitutionTemplateLiteral(head);\n}\n\ntype QueryArgDefinition = {\n name: string;\n originalName: string;\n type: ts.TypeNode;\n required?: boolean;\n param?: OpenAPIV3.ParameterObject;\n} & (\n | {\n origin: 'param';\n param: OpenAPIV3.ParameterObject;\n }\n | {\n origin: 'body';\n body: OpenAPIV3.RequestBodyObject;\n }\n);\ntype QueryArgDefinitions = Record<string, QueryArgDefinition>;\n","import ts from 'typescript';\nimport semver from 'semver';\n\nconst originalFactory = ts.factory;\n\nfunction createImportSpecifier(propertyName: ts.Identifier | undefined, name: ts.Identifier): ts.ImportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createImportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createImportSpecifier(propertyName, name);\n}\n\nfunction createExportSpecifier(\n propertyName: string | ts.Identifier | undefined,\n name: string | ts.Identifier\n): ts.ExportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createExportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createExportSpecifier(propertyName, name);\n}\n\nexport const factory = {\n ...originalFactory,\n createImportSpecifier,\n createExportSpecifier,\n};\n","import { factory } from './utils/factory';\nimport ts from 'typescript';\n\nconst defaultEndpointBuilder = factory.createIdentifier('build');\n\nexport type ObjectPropertyDefinitions = Record<string, ts.Expression | undefined>;\nexport function generateObjectProperties(obj: ObjectPropertyDefinitions) {\n return Object.entries(obj)\n .filter(([_, v]) => v)\n .map(([k, v]) => factory.createPropertyAssignment(factory.createIdentifier(k), v as ts.Expression));\n}\n\nexport function generateImportNode(pkg: string, namedImports: Record<string, string>, defaultImportName?: string) {\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n defaultImportName !== undefined ? factory.createIdentifier(defaultImportName) : undefined,\n factory.createNamedImports(\n Object.entries(namedImports).map(([propertyName, name]) =>\n factory.createImportSpecifier(\n name === propertyName ? undefined : factory.createIdentifier(propertyName),\n factory.createIdentifier(name)\n )\n )\n )\n ),\n factory.createStringLiteral(pkg)\n );\n}\n\nexport function generateCreateApiCall({\n endpointBuilder = defaultEndpointBuilder,\n endpointDefinitions,\n tag,\n}: {\n endpointBuilder?: ts.Identifier;\n endpointDefinitions: ts.ObjectLiteralExpression;\n tag: boolean;\n}) {\n const injectEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n generateObjectProperties({\n endpoints: factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, endpointBuilder, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(endpointDefinitions)\n ),\n overrideExisting: factory.createFalse(),\n }),\n true\n );\n if (tag) {\n const enhanceEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n [factory.createShorthandPropertyAssignment(factory.createIdentifier('addTagTypes'), undefined)],\n true\n );\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('enhanceEndpoints')\n ),\n undefined,\n [enhanceEndpointsObjectLiteralExpression]\n ),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n }\n\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n\nexport function generateEndpointDefinition({\n operationName,\n type,\n Response,\n QueryArg,\n queryFn,\n endpointBuilder = defaultEndpointBuilder,\n extraEndpointsProps,\n tags,\n}: {\n operationName: string;\n type: 'query' | 'mutation';\n Response: ts.TypeReferenceNode;\n QueryArg: ts.TypeReferenceNode;\n queryFn: ts.Expression;\n endpointBuilder?: ts.Identifier;\n extraEndpointsProps: ObjectPropertyDefinitions;\n tags: string[];\n}) {\n const objectProperties = generateObjectProperties({ query: queryFn, ...extraEndpointsProps });\n if (tags.length > 0) {\n objectProperties.push(\n factory.createPropertyAssignment(\n factory.createIdentifier(type === 'query' ? 'providesTags' : 'invalidatesTags'),\n factory.createArrayLiteralExpression(tags.map((tag) => factory.createStringLiteral(tag), false))\n )\n );\n }\n return factory.createPropertyAssignment(\n factory.createIdentifier(operationName),\n\n factory.createCallExpression(\n factory.createPropertyAccessExpression(endpointBuilder, factory.createIdentifier(type)),\n [Response, QueryArg],\n [factory.createObjectLiteralExpression(objectProperties, true)]\n )\n );\n}\n\nexport function generateTagTypes({ addTagTypes }: { addTagTypes: string[] }) {\n return factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('addTagTypes'),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createArrayLiteralExpression(\n addTagTypes.map((tagType) => factory.createStringLiteral(tagType)),\n true\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined)\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n","import ts from 'typescript';\nimport { getOperationName } from 'oazapfts/generate';\nimport { capitalize, isQuery } from '../utils';\nimport type { OperationDefinition, EndpointOverrides, ConfigFile } from '../types';\nimport { getOverrides } from '../generate';\nimport { factory } from '../utils/factory';\n\ntype HooksConfigOptions = NonNullable<ConfigFile['hooks']>;\n\ntype GetReactHookNameParams = {\n operationDefinition: OperationDefinition;\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\n\ntype CreateBindingParams = {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n isLazy?: boolean;\n};\n\nconst createBinding = ({\n operationDefinition: { verb, path, operation },\n overrides,\n isLazy = false,\n}: CreateBindingParams) =>\n factory.createBindingElement(\n undefined,\n undefined,\n factory.createIdentifier(\n `use${isLazy ? 'Lazy' : ''}${capitalize(getOperationName(verb, path, operation.operationId))}${\n isQuery(verb, overrides) ? 'Query' : 'Mutation'\n }`\n ),\n undefined\n );\n\nconst getReactHookName = ({ operationDefinition, endpointOverrides, config }: GetReactHookNameParams) => {\n const overrides = getOverrides(operationDefinition, endpointOverrides);\n\n const baseParams = {\n operationDefinition,\n overrides,\n };\n\n const _isQuery = isQuery(operationDefinition.verb, overrides);\n\n // If `config` is true, just generate everything\n if (typeof config === 'boolean') {\n return createBinding(baseParams);\n }\n\n // `config` is an object and we need to check for the configuration of each property\n if (_isQuery) {\n return [\n ...(config.queries ? [createBinding(baseParams)] : []),\n ...(config.lazyQueries ? [createBinding({ ...baseParams, isLazy: true })] : []),\n ];\n }\n\n return config.mutations ? createBinding(baseParams) : [];\n};\n\ntype GenerateReactHooksParams = {\n exportName: string;\n operationDefinitions: OperationDefinition[];\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\nexport const generateReactHooks = ({\n exportName,\n operationDefinitions,\n endpointOverrides,\n config,\n}: GenerateReactHooksParams) =>\n factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createObjectBindingPattern(\n operationDefinitions\n .map((operationDefinition) => getReactHookName({ operationDefinition, endpointOverrides, config }))\n .flat()\n ),\n undefined,\n undefined,\n factory.createIdentifier(exportName)\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n","export function capitalize(str: string) {\n return str.replace(str[0], str[0].toUpperCase());\n}\n","import type SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nexport type OperationDefinition = {\n path: string;\n verb: (typeof operationKeys)[number];\n pathItem: OpenAPIV3.PathItemObject;\n operation: OpenAPIV3.OperationObject;\n};\n\nexport type ParameterDefinition = OpenAPIV3.ParameterObject;\n\ntype Require<T, K extends keyof T> = { [k in K]-?: NonNullable<T[k]> } & Omit<T, K>;\ntype Optional<T, K extends keyof T> = { [k in K]?: NonNullable<T[k]> } & Omit<T, K>;\ntype Id<T> = { [K in keyof T]: T[K] } & {};\ntype AtLeastOneKey<T> = {\n [K in keyof T]-?: Pick<T, K> & Partial<T>;\n}[keyof T];\n\nexport const operationKeys = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;\n\nexport type GenerationOptions = Id<\n CommonOptions &\n Optional<OutputFileOptions, 'outputFile'> & {\n isDataResponse?(\n code: string,\n includeDefault: boolean,\n response: OpenAPIV3.ResponseObject,\n allResponses: OpenAPIV3.ResponsesObject\n ): boolean;\n }\n>;\n\nexport interface CommonOptions {\n apiFile: string;\n /**\n * filename or url\n */\n schemaFile: string;\n /**\n * defaults to \"api\"\n */\n apiImport?: string;\n /**\n * defaults to \"enhancedApi\"\n */\n exportName?: string;\n /**\n * defaults to \"ApiArg\"\n */\n argSuffix?: string;\n /**\n * defaults to \"ApiResponse\"\n */\n responseSuffix?: string;\n /**\n * defaults to empty\n */\n operationNameSuffix?: string;\n /**\n * defaults to `false`\n * `true` will generate hooks for queries and mutations, but no lazyQueries\n */\n hooks?: boolean | { queries: boolean; lazyQueries: boolean; mutations: boolean };\n /**\n * defaults to false\n * `true` will generate a union type for `undefined` properties like: `{ id?: string | undefined }` instead of `{ id?: string }`\n */\n unionUndefined?: boolean;\n /**\n * defaults to false\n * `true` will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition\n * @see https://redux-toolkit.js.org/rtk-query/usage/code-generation for more information\n */\n tag?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated path parameters\n */\n encodePathParams?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated query parameters\n */\n encodeQueryParams?: boolean;\n /**\n * defaults to false\n * `true` will \"flatten\" the arg so that you can do things like `useGetEntityById(1)` instead of `useGetEntityById({ entityId: 1 })`\n */\n flattenArg?: boolean;\n /**\n * default to false\n * If set to `true`, the default response type will be included in the generated code for all endpoints.\n * @see https://swagger.io/docs/specification/describing-responses/#default\n */\n includeDefault?: boolean;\n /**\n * default to false\n * `true` will not generate separate types for read-only and write-only properties.\n */\n mergeReadWriteOnly?: boolean;\n /**\n *\n * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.\n */\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions;\n\n /**\n * defaults to undefined\n * If present the given file will be used as prettier config when formatting the generated code. If undefined the default prettier config\n * resolution mechanism will be used.\n */\n prettierConfigFile?: string;\n}\n\nexport type TextMatcher = string | RegExp | (string | RegExp)[];\n\nexport type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;\n\nexport type EndpointMatcher = TextMatcher | EndpointMatcherFunction;\n\nexport type ParameterMatcherFunction = (parameterName: string, parameterDefinition: ParameterDefinition) => boolean;\n\nexport type ParameterMatcher = TextMatcher | ParameterMatcherFunction;\n\nexport interface OutputFileOptions extends Partial<CommonOptions> {\n outputFile: string;\n filterEndpoints?: EndpointMatcher;\n endpointOverrides?: EndpointOverrides[];\n /**\n * defaults to false\n * If passed as true it will generate TS enums instead of union of strings\n */\n useEnumType?: boolean;\n}\n\nexport type EndpointOverrides = {\n pattern: EndpointMatcher;\n} & AtLeastOneKey<{\n type: 'mutation' | 'query';\n parameterFilter: ParameterMatcher;\n}>;\n\nexport type ConfigFile =\n | Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>>\n | Id<\n Omit<CommonOptions, 'outputFile'> & {\n outputFiles: { [outputFile: string]: Omit<OutputFileOptions, 'outputFile'> };\n }\n >;\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { OperationDefinition } from '../types';\nimport { operationKeys } from '../types';\n\nexport function getOperationDefinitions(v3Doc: OpenAPIV3.Document): OperationDefinition[] {\n return Object.entries(v3Doc.paths).flatMap(([path, pathItem]) =>\n !pathItem\n ? []\n : Object.entries(pathItem)\n .filter((arg): arg is [(typeof operationKeys)[number], OpenAPIV3.OperationObject] =>\n operationKeys.includes(arg[0] as any)\n )\n .map(([verb, operation]) => ({\n path,\n verb,\n pathItem,\n operation,\n }))\n );\n}\n","import SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n// @ts-ignore\nimport converter from 'swagger2openapi';\n\nexport async function getV3Doc(\n spec: string,\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions\n): Promise<OpenAPIV3.Document> {\n const doc = await SwaggerParser.bundle(spec, {\n resolve: {\n http: httpResolverOptions,\n },\n });\n\n const isOpenApiV3 = 'openapi' in doc && doc.openapi.startsWith('3');\n\n if (isOpenApiV3) {\n return doc as OpenAPIV3.Document;\n } else {\n const result = await converter.convertObj(doc, {});\n return result.openapi as OpenAPIV3.Document;\n }\n}\n","import type { EndpointOverrides, operationKeys } from '../types';\n\nexport function isQuery(verb: (typeof operationKeys)[number], overrides: EndpointOverrides | undefined) {\n if (overrides?.type) {\n return overrides.type === 'query';\n }\n return verb === 'get';\n}\n","export function isValidUrl(string: string) {\n try {\n new URL(string);\n } catch (_) {\n return false;\n }\n\n return true;\n}\n","import path from 'node:path';\nimport prettier from 'prettier';\nimport type { BuiltInParserName } from 'prettier';\n\nconst EXTENSION_TO_PARSER: Record<string, BuiltInParserName> = {\n ts: 'typescript',\n tsx: 'typescript',\n js: 'babel',\n jsx: 'babel',\n 'js.flow': 'flow',\n flow: 'flow',\n gql: 'graphql',\n graphql: 'graphql',\n css: 'scss',\n scss: 'scss',\n less: 'scss',\n stylus: 'scss',\n markdown: 'markdown',\n md: 'markdown',\n json: 'json',\n};\n\nexport async function prettify(filePath: string | null, content: string, prettierConfigFile?: string): Promise<string> {\n let config = null;\n let parser = 'typescript';\n\n if (filePath) {\n const fileExtension = path.extname(filePath).slice(1);\n parser = EXTENSION_TO_PARSER[fileExtension];\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n editorconfig: !prettierConfigFile,\n config: prettierConfigFile,\n });\n } else if (prettierConfigFile) {\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n config: prettierConfigFile,\n });\n }\n\n return prettier.format(content, {\n parser,\n ...config,\n });\n}\n","export function removeUndefined<T>(t: T | undefined): t is T {\n return typeof t !== 'undefined';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,yBAA8B;AAC9B,IAAAA,oBAAiB;;;ACFjB,oBAAsB;AACtB,IAAAC,oBAAiB;AACjB,IAAAC,mBASO;AA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cAAc;AAE9C,QAAM,aAAa,MAAM,yBAAyB,YAAY;AAC5D,WAAO,YAAY,eAAe,OAAO;AAAA,EAC3C,CAAC;AACD,QAAM,EAAE,YAAY,mBAAmB,IAAI;AAC3C,MAAI,YAAY;AACd,mBAAAC,QAAG;AAAA,MACD,kBAAAD,QAAK,QAAQ,QAAQ,IAAI,GAAG,UAAU;AAAA,MACtC,MAAM,SAAS,YAAY,YAAY,kBAAkB;AAAA,IAC3D;AAAA,EACF,OAAO;AACL,WAAO,MAAM,SAAS,MAAM,YAAY,kBAAkB;AAAA,EAC5D;AACF;AAEO,SAAS,YAAY,YAAwB;AAClD,QAAM,WAAkD,CAAC;AAEzD,MAAI,iBAAiB,YAAY;AAC/B,UAAM,EAAE,aAAa,GAAG,aAAa,IAAI;AACzC,eAAW,CAAC,YAAY,cAAc,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,eAAS,KAAK;AAAA,QACZ,GAAG;AAAA,QACH,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,OAAO;AACL,aAAS,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;AAMA,SAAS,yBAA4B,IAAgB;AACnD,QAAM,WAAWD,SAAQ,QAAQ,cAAc,EAAE,OAAO,CAACA,SAAQ,QAAQ,UAAU,CAAC,EAAE,CAAC;AACvF,QAAM,SAASA,SAAQ,QAAQ,YAAY;AAC3C,QAAM,gBAAgBA,SAAQ,MAAM,QAAQ;AAC5C,MAAI;AACF,IAAAA,SAAQ,MAAM,QAAQ,IAAIA,SAAQ,MAAM,MAAM;AAC9C,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,QAAI,eAAe;AACjB,MAAAA,SAAQ,MAAM,QAAQ,IAAI;AAAA,IAC5B,OAAO;AACL,aAAOA,SAAQ,MAAM,QAAQ;AAAA,IAC/B;AAAA,EACF;AACF;","names":["import_node_path","import_node_path","import_generate","import_typescript","ts","semver","import_typescript","ts","import_typescript","path","SwaggerParser","converter","path","prettier","path","ts","getOperationName","path","_getOperationName","ts","ApiGenerator","operationDefinitions","tag","isQuery","camelCase","encodePathParams","encodeQueryParams","require","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/generate.ts","../src/utils/factory.ts","../src/codegen.ts","../src/generators/react-hooks.ts","../src/utils/capitalize.ts","../src/types.ts","../src/utils/getOperationDefinitions.ts","../src/utils/getV3Doc.ts","../src/utils/isQuery.ts","../src/utils/isValidUrl.ts","../src/utils/prettier.ts","../src/utils/removeUndefined.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { generateApi } from './generate';\nimport type { CommonOptions, ConfigFile, GenerationOptions, OutputFileOptions } from './types';\nimport { isValidUrl, prettify } from './utils';\nexport type { ConfigFile } from './types';\n\nconst require = createRequire(__filename);\n\nexport async function generateEndpoints(options: GenerationOptions): Promise<string | void> {\n const schemaLocation = options.schemaFile;\n\n const schemaAbsPath = isValidUrl(options.schemaFile)\n ? options.schemaFile\n : path.resolve(process.cwd(), schemaLocation);\n\n const sourceCode = await enforceOazapftsTsVersion(async () => {\n return generateApi(schemaAbsPath, options);\n });\n const { outputFile, prettierConfigFile } = options;\n if (outputFile) {\n fs.writeFileSync(\n path.resolve(process.cwd(), outputFile),\n await prettify(outputFile, sourceCode, prettierConfigFile)\n );\n } else {\n return await prettify(null, sourceCode, prettierConfigFile);\n }\n}\n\nexport function parseConfig(fullConfig: ConfigFile) {\n const outFiles: (CommonOptions & OutputFileOptions)[] = [];\n\n if ('outputFiles' in fullConfig) {\n const { outputFiles, ...commonConfig } = fullConfig;\n for (const [outputFile, specificConfig] of Object.entries(outputFiles)) {\n outFiles.push({\n ...commonConfig,\n ...specificConfig,\n outputFile,\n });\n }\n } else {\n outFiles.push(fullConfig);\n }\n return outFiles;\n}\n\n/**\n * Enforces `oazapfts` to use the same TypeScript version as this module itself uses.\n * That should prevent enums from running out of sync if both libraries use different TS versions.\n */\nfunction enforceOazapftsTsVersion<T>(cb: () => T): T {\n const ozTsPath = require.resolve('typescript', { paths: [require.resolve('oazapfts')] });\n const tsPath = require.resolve('typescript');\n const originalEntry = require.cache[ozTsPath];\n try {\n require.cache[ozTsPath] = require.cache[tsPath];\n return cb();\n } finally {\n if (originalEntry) {\n require.cache[ozTsPath] = originalEntry;\n } else {\n delete require.cache[ozTsPath];\n }\n }\n}\n","import camelCase from 'lodash.camelcase';\nimport path from 'node:path';\nimport ApiGenerator, {\n getOperationName as _getOperationName,\n getReferenceName,\n isReference,\n supportDeepObjects,\n createPropertyAssignment,\n createQuestionToken,\n isValidIdentifier,\n keywordType,\n} from 'oazapfts/generate';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport ts from 'typescript';\nimport type { ObjectPropertyDefinitions } from './codegen';\nimport { generateCreateApiCall, generateEndpointDefinition, generateImportNode, generateTagTypes } from './codegen';\nimport { generateReactHooks } from './generators/react-hooks';\nimport type {\n EndpointMatcher,\n EndpointOverrides,\n GenerationOptions,\n OperationDefinition,\n ParameterDefinition,\n ParameterMatcher,\n TextMatcher,\n} from './types';\nimport { capitalize, getOperationDefinitions, getV3Doc, removeUndefined, isQuery as testIsQuery } from './utils';\nimport { factory } from './utils/factory';\n\nconst generatedApiName = 'injectedRtkApi';\nconst v3DocCache: Record<string, OpenAPIV3.Document> = {};\n\nfunction defaultIsDataResponse(code: string, includeDefault: boolean) {\n if (includeDefault && code === 'default') {\n return true;\n }\n const parsedCode = Number(code);\n return !Number.isNaN(parsedCode) && parsedCode >= 200 && parsedCode < 300;\n}\n\nfunction getOperationName({ verb, path, operation }: Pick<OperationDefinition, 'verb' | 'path' | 'operation'>) {\n return _getOperationName(verb, path, operation.operationId);\n}\n\nfunction getTags({ verb, pathItem }: Pick<OperationDefinition, 'verb' | 'pathItem'>): string[] {\n return verb ? pathItem[verb]?.tags || [] : [];\n}\n\nfunction patternMatches(pattern?: TextMatcher) {\n const filters = Array.isArray(pattern) ? pattern : [pattern];\n return function matcher(operationName: string) {\n if (!pattern) return true;\n return filters.some((filter) =>\n typeof filter === 'string' ? filter === operationName : filter?.test(operationName)\n );\n };\n}\n\nfunction operationMatches(pattern?: EndpointMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(operationDefinition: OperationDefinition) {\n if (!pattern) return true;\n const operationName = getOperationName(operationDefinition);\n return checkMatch(operationName, operationDefinition);\n };\n}\n\nfunction argumentMatches(pattern?: ParameterMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(argumentDefinition: ParameterDefinition) {\n if (!pattern || argumentDefinition.in === 'path') return true;\n const argumentName = argumentDefinition.name;\n return checkMatch(argumentName, argumentDefinition);\n };\n}\n\nfunction withQueryComment<T extends ts.Node>(node: T, def: QueryArgDefinition, hasTrailingNewLine: boolean): T {\n const comment = def.origin === 'param' ? def.param.description : def.body.description;\n if (comment) {\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${comment} `,\n hasTrailingNewLine\n );\n }\n return node;\n}\n\nexport function getOverrides(\n operation: OperationDefinition,\n endpointOverrides?: EndpointOverrides[]\n): EndpointOverrides | undefined {\n return endpointOverrides?.find((override) => operationMatches(override.pattern)(operation));\n}\n\nexport async function generateApi(\n spec: string,\n {\n apiFile,\n apiImport = 'api',\n exportName = 'enhancedApi',\n argSuffix = 'ApiArg',\n responseSuffix = 'ApiResponse',\n operationNameSuffix = '',\n hooks = false,\n tag = false,\n outputFile,\n isDataResponse = defaultIsDataResponse,\n filterEndpoints,\n endpointOverrides,\n unionUndefined,\n encodePathParams = false,\n encodeQueryParams = false,\n flattenArg = false,\n includeDefault = false,\n useEnumType = false,\n mergeReadWriteOnly = false,\n httpResolverOptions,\n }: GenerationOptions\n) {\n const v3Doc = (v3DocCache[spec] ??= await getV3Doc(spec, httpResolverOptions));\n\n const apiGen = new ApiGenerator(v3Doc, {\n unionUndefined,\n useEnumType,\n mergeReadWriteOnly,\n });\n\n // temporary workaround for https://github.com/oazapfts/oazapfts/issues/491\n if (apiGen.spec.components?.schemas) {\n apiGen.preprocessComponents(apiGen.spec.components.schemas);\n }\n\n const operationDefinitions = getOperationDefinitions(v3Doc).filter(operationMatches(filterEndpoints));\n\n const resultFile = ts.createSourceFile(\n 'someFileName.ts',\n '',\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS\n );\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n const interfaces: Record<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration> = {};\n function registerInterface(declaration: ts.InterfaceDeclaration | ts.TypeAliasDeclaration) {\n const name = declaration.name.escapedText.toString();\n if (name in interfaces) {\n throw new Error(`interface/type alias ${name} already registered`);\n }\n interfaces[name] = declaration;\n return declaration;\n }\n\n if (outputFile) {\n outputFile = path.resolve(process.cwd(), outputFile);\n if (apiFile.startsWith('.')) {\n apiFile = path.relative(path.dirname(outputFile), apiFile);\n apiFile = apiFile.replace(/\\\\/g, '/');\n if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;\n }\n }\n apiFile = apiFile.replace(/\\.[jt]sx?$/, '');\n\n return printer.printNode(\n ts.EmitHint.Unspecified,\n factory.createSourceFile(\n [\n generateImportNode(apiFile, { [apiImport]: 'api' }),\n generateImportNode('@acrool/react-fetcher', { IRestFulEndpointsQueryReturn: 'IRestFulEndpointsQueryReturn' }),\n ...(tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : []),\n generateCreateApiCall({\n tag,\n endpointDefinitions: factory.createObjectLiteralExpression(\n operationDefinitions.map((operationDefinition) =>\n generateEndpoint({\n operationDefinition,\n overrides: getOverrides(operationDefinition, endpointOverrides),\n })\n ),\n true\n ),\n }),\n factory.createExportDeclaration(\n undefined,\n false,\n factory.createNamedExports([\n factory.createExportSpecifier(\n factory.createIdentifier(generatedApiName),\n factory.createIdentifier(exportName)\n ),\n ]),\n undefined\n ),\n ...Object.values(interfaces),\n ...apiGen.aliases,\n ...apiGen.enumAliases,\n ...(hooks\n ? [\n generateReactHooks({\n exportName: generatedApiName,\n operationDefinitions,\n endpointOverrides,\n config: hooks,\n }),\n ]\n : []),\n ],\n factory.createToken(ts.SyntaxKind.EndOfFileToken),\n ts.NodeFlags.None\n ),\n resultFile\n );\n\n function extractAllTagTypes({ operationDefinitions }: { operationDefinitions: OperationDefinition[] }) {\n const allTagTypes = new Set<string>();\n\n for (const operationDefinition of operationDefinitions) {\n const { verb, pathItem } = operationDefinition;\n for (const tag of getTags({ verb, pathItem })) {\n allTagTypes.add(tag);\n }\n }\n return [...allTagTypes];\n }\n\n function generateEndpoint({\n operationDefinition,\n overrides,\n }: {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n }) {\n const {\n verb,\n path,\n pathItem,\n operation,\n operation: { responses, requestBody },\n } = operationDefinition;\n const operationName = getOperationName({ verb, path, operation });\n const tags = tag ? getTags({ verb, pathItem }) : [];\n const isQuery = testIsQuery(verb, overrides);\n\n const returnsJson = apiGen.getResponseType(responses) === 'json';\n let ResponseType: ts.TypeNode = factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n if (returnsJson) {\n const returnTypes = Object.entries(responses || {})\n .map(\n ([code, response]) =>\n [\n code,\n apiGen.resolve(response),\n apiGen.getTypeFromResponse(response, 'readOnly') ||\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n ] as const\n )\n .filter(([status, response]) =>\n isDataResponse(status, includeDefault, apiGen.resolve(response), responses || {})\n )\n .filter(([_1, _2, type]) => type !== keywordType.void)\n .map(([code, response, type]) =>\n ts.addSyntheticLeadingComment(\n { ...type },\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* status ${code} ${response.description} `,\n false\n )\n );\n if (returnTypes.length > 0) {\n ResponseType = factory.createUnionTypeNode(returnTypes);\n }\n }\n\n const ResponseTypeName = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + responseSuffix),\n undefined,\n ResponseType\n )\n ).name\n );\n\n const operationParameters = apiGen.resolveArray(operation.parameters);\n const pathItemParameters = apiGen\n .resolveArray(pathItem.parameters)\n .filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));\n\n const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters])\n .filter(argumentMatches(overrides?.parameterFilter))\n .filter(param => param.in !== 'header');\n\n const allNames = parameters.map((p) => p.name);\n const queryArg: QueryArgDefinitions = {};\n function generateName(name: string, potentialPrefix: string) {\n const isPureSnakeCase = /^[a-zA-Z][a-zA-Z0-9_]*$/.test(name);\n // prefix with `query`, `path` or `body` if there are multiple paramters with the same name\n const hasNamingConflict = allNames.filter((n) => n === name).length > 1;\n if (hasNamingConflict) {\n name = `${potentialPrefix}_${name}`;\n }\n // convert to camelCase if the name is pure snake_case and there are no naming conflicts\n const camelCaseName = camelCase(name);\n if (isPureSnakeCase && !allNames.includes(camelCaseName)) {\n name = camelCaseName;\n }\n // if there are still any naming conflicts, prepend with underscore\n while (name in queryArg) {\n name = `_${name}`;\n }\n return name;\n }\n\n for (const param of parameters) {\n const name = generateName(param.name, param.in);\n queryArg[name] = {\n origin: 'param',\n name,\n originalName: param.name,\n type: apiGen.getTypeFromSchema(isReference(param) ? param : param.schema, undefined, 'writeOnly'),\n required: param.required,\n param,\n };\n }\n\n if (requestBody) {\n const body = apiGen.resolve(requestBody);\n const schema = apiGen.getSchemaFromContent(body.content);\n const type = apiGen.getTypeFromSchema(schema);\n const schemaName = camelCase(\n (type as any).name ||\n getReferenceName(schema) ||\n (typeof schema === 'object' && 'title' in schema && schema.title) ||\n 'body'\n );\n const name = generateName(schemaName in queryArg ? 'body' : schemaName, 'body');\n\n queryArg[name] = {\n origin: 'body',\n name,\n originalName: schemaName,\n type: apiGen.getTypeFromSchema(schema, undefined, 'writeOnly'),\n required: true,\n body,\n };\n }\n\n const propertyName = (name: string | ts.PropertyName): ts.PropertyName => {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);\n }\n return name;\n };\n\n const queryArgValues = Object.values(queryArg);\n\n const isFlatArg = flattenArg && queryArgValues.length === 1;\n const QueryArg = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + argSuffix),\n undefined,\n queryArgValues.length > 0\n ? isFlatArg\n ? withQueryComment(\n factory.createUnionTypeNode([\n queryArgValues[0].type,\n ...(!queryArgValues[0].required\n ? [factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)]\n : []),\n ]),\n queryArgValues[0],\n false\n )\n : factory.createTypeLiteralNode(\n queryArgValues.map((def) =>\n withQueryComment(\n factory.createPropertySignature(\n undefined,\n propertyName(def.name),\n createQuestionToken(!def.required),\n def.type\n ),\n def,\n true\n )\n )\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)\n )\n ).name\n );\n\n return generateEndpointDefinition({\n operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,\n type: isQuery ? 'query' : 'mutation',\n Response: ResponseTypeName,\n QueryArg: factory.createTypeReferenceNode(\n factory.createIdentifier('IRestFulEndpointsQueryReturn'),\n [QueryArg]\n ),\n queryFn: generateQueryFn({\n operationDefinition,\n queryArg,\n isQuery,\n isFlatArg,\n encodePathParams,\n encodeQueryParams,\n }),\n extraEndpointsProps: isQuery\n ? generateQueryEndpointProps({ operationDefinition })\n : generateMutationEndpointProps({ operationDefinition }),\n tags,\n });\n }\n\n function generateQueryFn({\n operationDefinition,\n queryArg,\n isFlatArg,\n isQuery,\n encodePathParams,\n encodeQueryParams,\n }: {\n operationDefinition: OperationDefinition;\n queryArg: QueryArgDefinitions;\n isFlatArg: boolean;\n isQuery: boolean;\n encodePathParams: boolean;\n encodeQueryParams: boolean;\n }) {\n const { path, verb } = operationDefinition;\n\n const bodyParameter = Object.values(queryArg).find((def) => def.origin === 'body');\n\n const rootObject = factory.createIdentifier('queryArg');\n const variablesObject = factory.createPropertyAccessExpression(rootObject, factory.createIdentifier('variables'));\n\n function pickParams(paramIn: string) {\n return Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === paramIn);\n }\n\n function createObjectLiteralProperty(parameters: QueryArgDefinition[], propertyName: string) {\n if (parameters.length === 0) return undefined;\n\n const properties = parameters.map((param) => {\n const value = isFlatArg \n ? variablesObject \n : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(param.name));\n\n const encodedValue =\n encodeQueryParams && param.param?.in === 'query'\n ? factory.createConditionalExpression(\n value,\n undefined,\n factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ]),\n undefined,\n factory.createIdentifier('undefined')\n )\n : value;\n\n return createPropertyAssignment(param.originalName, encodedValue);\n });\n\n return factory.createPropertyAssignment(\n factory.createIdentifier(propertyName),\n factory.createObjectLiteralExpression(properties, true)\n );\n }\n\n return factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(\n factory.createObjectLiteralExpression(\n [\n factory.createPropertyAssignment(\n factory.createIdentifier('url'),\n generatePathExpression(path, pickParams('path'), variablesObject, isFlatArg, encodePathParams)\n ),\n isQuery && verb.toUpperCase() === 'GET'\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('method'),\n factory.createStringLiteral(verb.toUpperCase())\n ),\n bodyParameter === undefined\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('body'),\n isFlatArg\n ? variablesObject\n : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(bodyParameter.name))\n ),\n createObjectLiteralProperty(pickParams('cookie'), 'cookies'),\n createObjectLiteralProperty(pickParams('query'), 'params'),\n factory.createPropertyAssignment(\n factory.createIdentifier('fetchOptions'),\n factory.createPropertyAccessChain(\n rootObject,\n factory.createToken(ts.SyntaxKind.QuestionDotToken),\n factory.createIdentifier('fetchOptions')\n )\n ),\n ].filter(removeUndefined),\n false\n )\n )\n );\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateQueryEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateMutationEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n}\n\nfunction accessProperty(rootObject: ts.Identifier, propertyName: string) {\n return isValidIdentifier(propertyName)\n ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName))\n : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));\n}\n\nfunction generatePathExpression(\n path: string,\n pathParameters: QueryArgDefinition[],\n rootObject: ts.Identifier | ts.PropertyAccessExpression,\n isFlatArg: boolean,\n encodePathParams: boolean\n) {\n const expressions: Array<[string, string]> = [];\n\n const head = path.replace(/\\{(.*?)}(.*?)(?=\\{|$)/g, (_, expression, literal) => {\n const param = pathParameters.find((p) => p.originalName === expression);\n if (!param) {\n throw new Error(`path parameter ${expression} does not seem to be defined in '${path}'!`);\n }\n expressions.push([param.name, literal]);\n return '';\n });\n\n return expressions.length\n ? factory.createTemplateExpression(\n factory.createTemplateHead(head),\n expressions.map(([prop, literal], index) => {\n const value = isFlatArg \n ? rootObject \n : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(prop));\n const encodedValue = encodePathParams\n ? factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ])\n : value;\n return factory.createTemplateSpan(\n encodedValue,\n index === expressions.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal)\n );\n })\n )\n : factory.createNoSubstitutionTemplateLiteral(head);\n}\n\ntype QueryArgDefinition = {\n name: string;\n originalName: string;\n type: ts.TypeNode;\n required?: boolean;\n param?: OpenAPIV3.ParameterObject;\n} & (\n | {\n origin: 'param';\n param: OpenAPIV3.ParameterObject;\n }\n | {\n origin: 'body';\n body: OpenAPIV3.RequestBodyObject;\n }\n);\ntype QueryArgDefinitions = Record<string, QueryArgDefinition>;\n","import ts from 'typescript';\nimport semver from 'semver';\n\nconst originalFactory = ts.factory;\n\nfunction createImportSpecifier(propertyName: ts.Identifier | undefined, name: ts.Identifier): ts.ImportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createImportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createImportSpecifier(propertyName, name);\n}\n\nfunction createExportSpecifier(\n propertyName: string | ts.Identifier | undefined,\n name: string | ts.Identifier\n): ts.ExportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createExportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createExportSpecifier(propertyName, name);\n}\n\nexport const factory = {\n ...originalFactory,\n createImportSpecifier,\n createExportSpecifier,\n};\n","import { factory } from './utils/factory';\nimport ts from 'typescript';\n\nconst defaultEndpointBuilder = factory.createIdentifier('build');\n\nexport type ObjectPropertyDefinitions = Record<string, ts.Expression | undefined>;\nexport function generateObjectProperties(obj: ObjectPropertyDefinitions) {\n return Object.entries(obj)\n .filter(([_, v]) => v)\n .map(([k, v]) => factory.createPropertyAssignment(factory.createIdentifier(k), v as ts.Expression));\n}\n\nexport function generateImportNode(pkg: string, namedImports: Record<string, string>, defaultImportName?: string) {\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n defaultImportName !== undefined ? factory.createIdentifier(defaultImportName) : undefined,\n factory.createNamedImports(\n Object.entries(namedImports).map(([propertyName, name]) =>\n factory.createImportSpecifier(\n name === propertyName ? undefined : factory.createIdentifier(propertyName),\n factory.createIdentifier(name)\n )\n )\n )\n ),\n factory.createStringLiteral(pkg)\n );\n}\n\nexport function generateCreateApiCall({\n endpointBuilder = defaultEndpointBuilder,\n endpointDefinitions,\n tag,\n}: {\n endpointBuilder?: ts.Identifier;\n endpointDefinitions: ts.ObjectLiteralExpression;\n tag: boolean;\n}) {\n const injectEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n generateObjectProperties({\n endpoints: factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, endpointBuilder, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(endpointDefinitions)\n ),\n overrideExisting: factory.createFalse(),\n }),\n true\n );\n if (tag) {\n const enhanceEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n [factory.createShorthandPropertyAssignment(factory.createIdentifier('addTagTypes'), undefined)],\n true\n );\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('enhanceEndpoints')\n ),\n undefined,\n [enhanceEndpointsObjectLiteralExpression]\n ),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n }\n\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n\nexport function generateEndpointDefinition({\n operationName,\n type,\n Response,\n QueryArg,\n queryFn,\n endpointBuilder = defaultEndpointBuilder,\n extraEndpointsProps,\n tags,\n}: {\n operationName: string;\n type: 'query' | 'mutation';\n Response: ts.TypeReferenceNode;\n QueryArg: ts.TypeReferenceNode;\n queryFn: ts.Expression;\n endpointBuilder?: ts.Identifier;\n extraEndpointsProps: ObjectPropertyDefinitions;\n tags: string[];\n}) {\n const objectProperties = generateObjectProperties({ query: queryFn, ...extraEndpointsProps });\n if (tags.length > 0) {\n objectProperties.push(\n factory.createPropertyAssignment(\n factory.createIdentifier(type === 'query' ? 'providesTags' : 'invalidatesTags'),\n factory.createArrayLiteralExpression(tags.map((tag) => factory.createStringLiteral(tag), false))\n )\n );\n }\n return factory.createPropertyAssignment(\n factory.createIdentifier(operationName),\n\n factory.createCallExpression(\n factory.createPropertyAccessExpression(endpointBuilder, factory.createIdentifier(type)),\n [Response, QueryArg],\n [factory.createObjectLiteralExpression(objectProperties, true)]\n )\n );\n}\n\nexport function generateTagTypes({ addTagTypes }: { addTagTypes: string[] }) {\n return factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('addTagTypes'),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createArrayLiteralExpression(\n addTagTypes.map((tagType) => factory.createStringLiteral(tagType)),\n true\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined)\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n","import ts from 'typescript';\nimport { getOperationName } from 'oazapfts/generate';\nimport { capitalize, isQuery } from '../utils';\nimport type { OperationDefinition, EndpointOverrides, ConfigFile } from '../types';\nimport { getOverrides } from '../generate';\nimport { factory } from '../utils/factory';\n\ntype HooksConfigOptions = NonNullable<ConfigFile['hooks']>;\n\ntype GetReactHookNameParams = {\n operationDefinition: OperationDefinition;\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\n\ntype CreateBindingParams = {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n isLazy?: boolean;\n};\n\nconst createBinding = ({\n operationDefinition: { verb, path, operation },\n overrides,\n isLazy = false,\n}: CreateBindingParams) =>\n factory.createBindingElement(\n undefined,\n undefined,\n factory.createIdentifier(\n `use${isLazy ? 'Lazy' : ''}${capitalize(getOperationName(verb, path, operation.operationId))}${\n isQuery(verb, overrides) ? 'Query' : 'Mutation'\n }`\n ),\n undefined\n );\n\nconst getReactHookName = ({ operationDefinition, endpointOverrides, config }: GetReactHookNameParams) => {\n const overrides = getOverrides(operationDefinition, endpointOverrides);\n\n const baseParams = {\n operationDefinition,\n overrides,\n };\n\n const _isQuery = isQuery(operationDefinition.verb, overrides);\n\n // If `config` is true, just generate everything\n if (typeof config === 'boolean') {\n return createBinding(baseParams);\n }\n\n // `config` is an object and we need to check for the configuration of each property\n if (_isQuery) {\n return [\n ...(config.queries ? [createBinding(baseParams)] : []),\n ...(config.lazyQueries ? [createBinding({ ...baseParams, isLazy: true })] : []),\n ];\n }\n\n return config.mutations ? createBinding(baseParams) : [];\n};\n\ntype GenerateReactHooksParams = {\n exportName: string;\n operationDefinitions: OperationDefinition[];\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\nexport const generateReactHooks = ({\n exportName,\n operationDefinitions,\n endpointOverrides,\n config,\n}: GenerateReactHooksParams) =>\n factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createObjectBindingPattern(\n operationDefinitions\n .map((operationDefinition) => getReactHookName({ operationDefinition, endpointOverrides, config }))\n .flat()\n ),\n undefined,\n undefined,\n factory.createIdentifier(exportName)\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n","export function capitalize(str: string) {\n return str.replace(str[0], str[0].toUpperCase());\n}\n","import type SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nexport type OperationDefinition = {\n path: string;\n verb: (typeof operationKeys)[number];\n pathItem: OpenAPIV3.PathItemObject;\n operation: OpenAPIV3.OperationObject;\n};\n\nexport type ParameterDefinition = OpenAPIV3.ParameterObject;\n\ntype Require<T, K extends keyof T> = { [k in K]-?: NonNullable<T[k]> } & Omit<T, K>;\ntype Optional<T, K extends keyof T> = { [k in K]?: NonNullable<T[k]> } & Omit<T, K>;\ntype Id<T> = { [K in keyof T]: T[K] } & {};\ntype AtLeastOneKey<T> = {\n [K in keyof T]-?: Pick<T, K> & Partial<T>;\n}[keyof T];\n\nexport const operationKeys = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;\n\nexport type GenerationOptions = Id<\n CommonOptions &\n Optional<OutputFileOptions, 'outputFile'> & {\n isDataResponse?(\n code: string,\n includeDefault: boolean,\n response: OpenAPIV3.ResponseObject,\n allResponses: OpenAPIV3.ResponsesObject\n ): boolean;\n }\n>;\n\nexport interface CommonOptions {\n apiFile: string;\n /**\n * filename or url\n */\n schemaFile: string;\n /**\n * defaults to \"api\"\n */\n apiImport?: string;\n /**\n * defaults to \"enhancedApi\"\n */\n exportName?: string;\n /**\n * defaults to \"ApiArg\"\n */\n argSuffix?: string;\n /**\n * defaults to \"ApiResponse\"\n */\n responseSuffix?: string;\n /**\n * defaults to empty\n */\n operationNameSuffix?: string;\n /**\n * defaults to `false`\n * `true` will generate hooks for queries and mutations, but no lazyQueries\n */\n hooks?: boolean | { queries: boolean; lazyQueries: boolean; mutations: boolean };\n /**\n * defaults to false\n * `true` will generate a union type for `undefined` properties like: `{ id?: string | undefined }` instead of `{ id?: string }`\n */\n unionUndefined?: boolean;\n /**\n * defaults to false\n * `true` will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition\n * @see https://redux-toolkit.js.org/rtk-query/usage/code-generation for more information\n */\n tag?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated path parameters\n */\n encodePathParams?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated query parameters\n */\n encodeQueryParams?: boolean;\n /**\n * defaults to false\n * `true` will \"flatten\" the arg so that you can do things like `useGetEntityById(1)` instead of `useGetEntityById({ entityId: 1 })`\n */\n flattenArg?: boolean;\n /**\n * default to false\n * If set to `true`, the default response type will be included in the generated code for all endpoints.\n * @see https://swagger.io/docs/specification/describing-responses/#default\n */\n includeDefault?: boolean;\n /**\n * default to false\n * `true` will not generate separate types for read-only and write-only properties.\n */\n mergeReadWriteOnly?: boolean;\n /**\n *\n * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.\n */\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions;\n\n /**\n * defaults to undefined\n * If present the given file will be used as prettier config when formatting the generated code. If undefined the default prettier config\n * resolution mechanism will be used.\n */\n prettierConfigFile?: string;\n}\n\nexport type TextMatcher = string | RegExp | (string | RegExp)[];\n\nexport type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;\n\nexport type EndpointMatcher = TextMatcher | EndpointMatcherFunction;\n\nexport type ParameterMatcherFunction = (parameterName: string, parameterDefinition: ParameterDefinition) => boolean;\n\nexport type ParameterMatcher = TextMatcher | ParameterMatcherFunction;\n\nexport interface OutputFileOptions extends Partial<CommonOptions> {\n outputFile: string;\n filterEndpoints?: EndpointMatcher;\n endpointOverrides?: EndpointOverrides[];\n /**\n * defaults to false\n * If passed as true it will generate TS enums instead of union of strings\n */\n useEnumType?: boolean;\n}\n\nexport type EndpointOverrides = {\n pattern: EndpointMatcher;\n} & AtLeastOneKey<{\n type: 'mutation' | 'query';\n parameterFilter: ParameterMatcher;\n}>;\n\nexport type ConfigFile =\n | Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>>\n | Id<\n Omit<CommonOptions, 'outputFile'> & {\n outputFiles: { [outputFile: string]: Omit<OutputFileOptions, 'outputFile'> };\n }\n >;\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { OperationDefinition } from '../types';\nimport { operationKeys } from '../types';\n\nexport function getOperationDefinitions(v3Doc: OpenAPIV3.Document): OperationDefinition[] {\n return Object.entries(v3Doc.paths).flatMap(([path, pathItem]) =>\n !pathItem\n ? []\n : Object.entries(pathItem)\n .filter((arg): arg is [(typeof operationKeys)[number], OpenAPIV3.OperationObject] =>\n operationKeys.includes(arg[0] as any)\n )\n .map(([verb, operation]) => ({\n path,\n verb,\n pathItem,\n operation,\n }))\n );\n}\n","import SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n// @ts-ignore\nimport converter from 'swagger2openapi';\n\nexport async function getV3Doc(\n spec: string,\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions\n): Promise<OpenAPIV3.Document> {\n const doc = await SwaggerParser.bundle(spec, {\n resolve: {\n http: httpResolverOptions,\n },\n });\n\n const isOpenApiV3 = 'openapi' in doc && doc.openapi.startsWith('3');\n\n if (isOpenApiV3) {\n return doc as OpenAPIV3.Document;\n } else {\n const result = await converter.convertObj(doc, {});\n return result.openapi as OpenAPIV3.Document;\n }\n}\n","import type { EndpointOverrides, operationKeys } from '../types';\n\nexport function isQuery(verb: (typeof operationKeys)[number], overrides: EndpointOverrides | undefined) {\n if (overrides?.type) {\n return overrides.type === 'query';\n }\n return verb === 'get';\n}\n","export function isValidUrl(string: string) {\n try {\n new URL(string);\n } catch (_) {\n return false;\n }\n\n return true;\n}\n","import path from 'node:path';\nimport prettier from 'prettier';\nimport type { BuiltInParserName } from 'prettier';\n\nconst EXTENSION_TO_PARSER: Record<string, BuiltInParserName> = {\n ts: 'typescript',\n tsx: 'typescript',\n js: 'babel',\n jsx: 'babel',\n 'js.flow': 'flow',\n flow: 'flow',\n gql: 'graphql',\n graphql: 'graphql',\n css: 'scss',\n scss: 'scss',\n less: 'scss',\n stylus: 'scss',\n markdown: 'markdown',\n md: 'markdown',\n json: 'json',\n};\n\nexport async function prettify(filePath: string | null, content: string, prettierConfigFile?: string): Promise<string> {\n let config = null;\n let parser = 'typescript';\n\n if (filePath) {\n const fileExtension = path.extname(filePath).slice(1);\n parser = EXTENSION_TO_PARSER[fileExtension];\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n editorconfig: !prettierConfigFile,\n config: prettierConfigFile,\n });\n } else if (prettierConfigFile) {\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n config: prettierConfigFile,\n });\n }\n\n return prettier.format(content, {\n parser,\n ...config,\n });\n}\n","export function removeUndefined<T>(t: T | undefined): t is T {\n return typeof t !== 'undefined';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,yBAA8B;AAC9B,IAAAA,oBAAiB;;;ACFjB,oBAAsB;AACtB,IAAAC,oBAAiB;AACjB,IAAAC,mBASO;AAEP,IAAAC,qBAAe;;;ACbf,wBAAe;AACf,oBAAmB;AAEnB,IAAM,kBAAkB,kBAAAC,QAAG;AAE3B,SAAS,sBAAsB,cAAyC,MAAyC;AAC/G,MAAI,cAAAC,QAAO,UAAU,kBAAAD,QAAG,SAAS,QAAQ;AAEvC,WAAO,gBAAgB,sBAAsB,OAAO,cAAc,IAAI;AAExE,SAAO,gBAAgB,sBAAsB,cAAc,IAAI;AACjE;AAEA,SAAS,sBACP,cACA,MACoB;AACpB,MAAI,cAAAC,QAAO,UAAU,kBAAAD,QAAG,SAAS,QAAQ;AAEvC,WAAO,gBAAgB,sBAAsB,OAAO,cAAc,IAAI;AAExE,SAAO,gBAAgB,sBAAsB,cAAc,IAAI;AACjE;AAEO,IAAM,UAAU;AAAA,EACrB,GAAG;AAAA,EACH;AAAA,EACA;AACF;;;AC3BA,IAAAE,qBAAe;AAEf,IAAM,yBAAyB,QAAQ,iBAAiB,OAAO;AAGxD,SAAS,yBAAyB,KAAgC;AACvE,SAAO,OAAO,QAA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AM,WAAkD,CAAC;AAEzD,MAAI,iBAAiB,YAAY;AAC/B,UAAM,EAAE,aAAa,GAAG,aAAa,IAAI;AACzC,eAAW,CAAC,YAAY,cAAc,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,eAAS,KAAK;AAAA,QACZ,GAAG;AAAA,QACH,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,OAAO;AACL,aAAS,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;AAMA,SAAS,yBAA4B,IAAgB;AACnD,QAAM,WAAWD,SAAQ,QAAQ,cAAc,EAAE,OAAO,CAACA,SAAQ,QAAQ,UAAU,CAAC,EAAE,CAAC;AACvF,QAAM,SAASA,SAAQ,QAAQ,YAAY;AAC3C,QAAM,gBAAgBA,SAAQ,MAAM,QAAQ;AAC5C,MAAI;AACF,IAAAA,SAAQ,MAAM,QAAQ,IAAIA,SAAQ,MAAM,MAAM;AAC9C,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,QAAI,eAAe;AACjB,MAAAA,SAAQ,MAAM,QAAQ,IAAI;AAAA,IAC5B,OAAO;AACL,aAAOA,SAAQ,MAAM,QAAQ;AAAA,IAC/B;AAAA,EACF;AACF;","names":["import_node_path","import_node_path","import_generate","import_typescript","ts","semver","import_typescript","ts","import_typescript","path","SwaggerParser","converter","path","prettier","path","ts","getOperationName","path","_getOperationName","ts","ApiGenerator","operationDefinitions","tag","isQuery","camelCase","encodePathParams","encodeQueryParams","path","require","path","fs"]}
|
package/lib/index.mjs
CHANGED
|
@@ -476,6 +476,7 @@ async function generateApi(spec, {
|
|
|
476
476
|
factory.createSourceFile(
|
|
477
477
|
[
|
|
478
478
|
generateImportNode(apiFile, { [apiImport]: "api" }),
|
|
479
|
+
generateImportNode("@acrool/react-fetcher", { IRestFulEndpointsQueryReturn: "IRestFulEndpointsQueryReturn" }),
|
|
479
480
|
...tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : [],
|
|
480
481
|
generateCreateApiCall({
|
|
481
482
|
tag,
|
|
@@ -576,9 +577,7 @@ async function generateApi(spec, {
|
|
|
576
577
|
);
|
|
577
578
|
const operationParameters = apiGen.resolveArray(operation.parameters);
|
|
578
579
|
const pathItemParameters = apiGen.resolveArray(pathItem.parameters).filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));
|
|
579
|
-
const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters]).filter(
|
|
580
|
-
argumentMatches(overrides?.parameterFilter)
|
|
581
|
-
);
|
|
580
|
+
const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters]).filter(argumentMatches(overrides?.parameterFilter)).filter((param) => param.in !== "header");
|
|
582
581
|
const allNames = parameters.map((p) => p.name);
|
|
583
582
|
const queryArg = {};
|
|
584
583
|
function generateName(name, potentialPrefix) {
|
|
@@ -666,7 +665,10 @@ async function generateApi(spec, {
|
|
|
666
665
|
operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,
|
|
667
666
|
type: isQuery2 ? "query" : "mutation",
|
|
668
667
|
Response: ResponseTypeName,
|
|
669
|
-
QueryArg
|
|
668
|
+
QueryArg: factory.createTypeReferenceNode(
|
|
669
|
+
factory.createIdentifier("IRestFulEndpointsQueryReturn"),
|
|
670
|
+
[QueryArg]
|
|
671
|
+
),
|
|
670
672
|
queryFn: generateQueryFn({
|
|
671
673
|
operationDefinition,
|
|
672
674
|
queryArg,
|
|
@@ -690,13 +692,14 @@ async function generateApi(spec, {
|
|
|
690
692
|
const { path: path4, verb } = operationDefinition;
|
|
691
693
|
const bodyParameter = Object.values(queryArg).find((def) => def.origin === "body");
|
|
692
694
|
const rootObject = factory.createIdentifier("queryArg");
|
|
695
|
+
const variablesObject = factory.createPropertyAccessExpression(rootObject, factory.createIdentifier("variables"));
|
|
693
696
|
function pickParams(paramIn) {
|
|
694
697
|
return Object.values(queryArg).filter((def) => def.origin === "param" && def.param.in === paramIn);
|
|
695
698
|
}
|
|
696
699
|
function createObjectLiteralProperty(parameters, propertyName) {
|
|
697
700
|
if (parameters.length === 0) return void 0;
|
|
698
701
|
const properties = parameters.map((param) => {
|
|
699
|
-
const value = isFlatArg ?
|
|
702
|
+
const value = isFlatArg ? variablesObject : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(param.name));
|
|
700
703
|
const encodedValue = encodeQueryParams2 && param.param?.in === "query" ? factory.createConditionalExpression(
|
|
701
704
|
value,
|
|
702
705
|
void 0,
|
|
@@ -716,7 +719,7 @@ async function generateApi(spec, {
|
|
|
716
719
|
return factory.createArrowFunction(
|
|
717
720
|
void 0,
|
|
718
721
|
void 0,
|
|
719
|
-
|
|
722
|
+
[factory.createParameterDeclaration(void 0, void 0, rootObject, void 0, void 0, void 0)],
|
|
720
723
|
void 0,
|
|
721
724
|
factory.createToken(ts4.SyntaxKind.EqualsGreaterThanToken),
|
|
722
725
|
factory.createParenthesizedExpression(
|
|
@@ -724,7 +727,7 @@ async function generateApi(spec, {
|
|
|
724
727
|
[
|
|
725
728
|
factory.createPropertyAssignment(
|
|
726
729
|
factory.createIdentifier("url"),
|
|
727
|
-
generatePathExpression(path4, pickParams("path"),
|
|
730
|
+
generatePathExpression(path4, pickParams("path"), variablesObject, isFlatArg, encodePathParams2)
|
|
728
731
|
),
|
|
729
732
|
isQuery2 && verb.toUpperCase() === "GET" ? void 0 : factory.createPropertyAssignment(
|
|
730
733
|
factory.createIdentifier("method"),
|
|
@@ -732,11 +735,18 @@ async function generateApi(spec, {
|
|
|
732
735
|
),
|
|
733
736
|
bodyParameter === void 0 ? void 0 : factory.createPropertyAssignment(
|
|
734
737
|
factory.createIdentifier("body"),
|
|
735
|
-
isFlatArg ?
|
|
738
|
+
isFlatArg ? variablesObject : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(bodyParameter.name))
|
|
736
739
|
),
|
|
737
740
|
createObjectLiteralProperty(pickParams("cookie"), "cookies"),
|
|
738
|
-
createObjectLiteralProperty(pickParams("
|
|
739
|
-
|
|
741
|
+
createObjectLiteralProperty(pickParams("query"), "params"),
|
|
742
|
+
factory.createPropertyAssignment(
|
|
743
|
+
factory.createIdentifier("fetchOptions"),
|
|
744
|
+
factory.createPropertyAccessChain(
|
|
745
|
+
rootObject,
|
|
746
|
+
factory.createToken(ts4.SyntaxKind.QuestionDotToken),
|
|
747
|
+
factory.createIdentifier("fetchOptions")
|
|
748
|
+
)
|
|
749
|
+
)
|
|
740
750
|
].filter(removeUndefined),
|
|
741
751
|
false
|
|
742
752
|
)
|
|
@@ -750,9 +760,6 @@ async function generateApi(spec, {
|
|
|
750
760
|
return {};
|
|
751
761
|
}
|
|
752
762
|
}
|
|
753
|
-
function accessProperty(rootObject, propertyName) {
|
|
754
|
-
return isValidIdentifier(propertyName) ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName)) : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));
|
|
755
|
-
}
|
|
756
763
|
function generatePathExpression(path4, pathParameters, rootObject, isFlatArg, encodePathParams) {
|
|
757
764
|
const expressions = [];
|
|
758
765
|
const head = path4.replace(/\{(.*?)}(.*?)(?=\{|$)/g, (_, expression, literal) => {
|
|
@@ -766,7 +773,7 @@ function generatePathExpression(path4, pathParameters, rootObject, isFlatArg, en
|
|
|
766
773
|
return expressions.length ? factory.createTemplateExpression(
|
|
767
774
|
factory.createTemplateHead(head),
|
|
768
775
|
expressions.map(([prop, literal], index) => {
|
|
769
|
-
const value = isFlatArg ? rootObject :
|
|
776
|
+
const value = isFlatArg ? rootObject : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(prop));
|
|
770
777
|
const encodedValue = encodePathParams ? factory.createCallExpression(factory.createIdentifier("encodeURIComponent"), void 0, [
|
|
771
778
|
factory.createCallExpression(factory.createIdentifier("String"), void 0, [value])
|
|
772
779
|
]) : value;
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/generate.ts","../src/utils/factory.ts","../src/codegen.ts","../src/generators/react-hooks.ts","../src/utils/capitalize.ts","../src/types.ts","../src/utils/getOperationDefinitions.ts","../src/utils/getV3Doc.ts","../src/utils/isQuery.ts","../src/utils/isValidUrl.ts","../src/utils/prettier.ts","../src/utils/removeUndefined.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { generateApi } from './generate';\nimport type { CommonOptions, ConfigFile, GenerationOptions, OutputFileOptions } from './types';\nimport { isValidUrl, prettify } from './utils';\nexport type { ConfigFile } from './types';\n\nconst require = createRequire(__filename);\n\nexport async function generateEndpoints(options: GenerationOptions): Promise<string | void> {\n const schemaLocation = options.schemaFile;\n\n const schemaAbsPath = isValidUrl(options.schemaFile)\n ? options.schemaFile\n : path.resolve(process.cwd(), schemaLocation);\n\n const sourceCode = await enforceOazapftsTsVersion(async () => {\n return generateApi(schemaAbsPath, options);\n });\n const { outputFile, prettierConfigFile } = options;\n if (outputFile) {\n fs.writeFileSync(\n path.resolve(process.cwd(), outputFile),\n await prettify(outputFile, sourceCode, prettierConfigFile)\n );\n } else {\n return await prettify(null, sourceCode, prettierConfigFile);\n }\n}\n\nexport function parseConfig(fullConfig: ConfigFile) {\n const outFiles: (CommonOptions & OutputFileOptions)[] = [];\n\n if ('outputFiles' in fullConfig) {\n const { outputFiles, ...commonConfig } = fullConfig;\n for (const [outputFile, specificConfig] of Object.entries(outputFiles)) {\n outFiles.push({\n ...commonConfig,\n ...specificConfig,\n outputFile,\n });\n }\n } else {\n outFiles.push(fullConfig);\n }\n return outFiles;\n}\n\n/**\n * Enforces `oazapfts` to use the same TypeScript version as this module itself uses.\n * That should prevent enums from running out of sync if both libraries use different TS versions.\n */\nfunction enforceOazapftsTsVersion<T>(cb: () => T): T {\n const ozTsPath = require.resolve('typescript', { paths: [require.resolve('oazapfts')] });\n const tsPath = require.resolve('typescript');\n const originalEntry = require.cache[ozTsPath];\n try {\n require.cache[ozTsPath] = require.cache[tsPath];\n return cb();\n } finally {\n if (originalEntry) {\n require.cache[ozTsPath] = originalEntry;\n } else {\n delete require.cache[ozTsPath];\n }\n }\n}\n","import camelCase from 'lodash.camelcase';\nimport path from 'node:path';\nimport ApiGenerator, {\n getOperationName as _getOperationName,\n getReferenceName,\n isReference,\n supportDeepObjects,\n createPropertyAssignment,\n createQuestionToken,\n isValidIdentifier,\n keywordType,\n} from 'oazapfts/generate';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport ts from 'typescript';\nimport type { ObjectPropertyDefinitions } from './codegen';\nimport { generateCreateApiCall, generateEndpointDefinition, generateImportNode, generateTagTypes } from './codegen';\nimport { generateReactHooks } from './generators/react-hooks';\nimport type {\n EndpointMatcher,\n EndpointOverrides,\n GenerationOptions,\n OperationDefinition,\n ParameterDefinition,\n ParameterMatcher,\n TextMatcher,\n} from './types';\nimport { capitalize, getOperationDefinitions, getV3Doc, removeUndefined, isQuery as testIsQuery } from './utils';\nimport { factory } from './utils/factory';\n\nconst generatedApiName = 'injectedRtkApi';\nconst v3DocCache: Record<string, OpenAPIV3.Document> = {};\n\nfunction defaultIsDataResponse(code: string, includeDefault: boolean) {\n if (includeDefault && code === 'default') {\n return true;\n }\n const parsedCode = Number(code);\n return !Number.isNaN(parsedCode) && parsedCode >= 200 && parsedCode < 300;\n}\n\nfunction getOperationName({ verb, path, operation }: Pick<OperationDefinition, 'verb' | 'path' | 'operation'>) {\n return _getOperationName(verb, path, operation.operationId);\n}\n\nfunction getTags({ verb, pathItem }: Pick<OperationDefinition, 'verb' | 'pathItem'>): string[] {\n return verb ? pathItem[verb]?.tags || [] : [];\n}\n\nfunction patternMatches(pattern?: TextMatcher) {\n const filters = Array.isArray(pattern) ? pattern : [pattern];\n return function matcher(operationName: string) {\n if (!pattern) return true;\n return filters.some((filter) =>\n typeof filter === 'string' ? filter === operationName : filter?.test(operationName)\n );\n };\n}\n\nfunction operationMatches(pattern?: EndpointMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(operationDefinition: OperationDefinition) {\n if (!pattern) return true;\n const operationName = getOperationName(operationDefinition);\n return checkMatch(operationName, operationDefinition);\n };\n}\n\nfunction argumentMatches(pattern?: ParameterMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(argumentDefinition: ParameterDefinition) {\n if (!pattern || argumentDefinition.in === 'path') return true;\n const argumentName = argumentDefinition.name;\n return checkMatch(argumentName, argumentDefinition);\n };\n}\n\nfunction withQueryComment<T extends ts.Node>(node: T, def: QueryArgDefinition, hasTrailingNewLine: boolean): T {\n const comment = def.origin === 'param' ? def.param.description : def.body.description;\n if (comment) {\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${comment} `,\n hasTrailingNewLine\n );\n }\n return node;\n}\n\nexport function getOverrides(\n operation: OperationDefinition,\n endpointOverrides?: EndpointOverrides[]\n): EndpointOverrides | undefined {\n return endpointOverrides?.find((override) => operationMatches(override.pattern)(operation));\n}\n\nexport async function generateApi(\n spec: string,\n {\n apiFile,\n apiImport = 'api',\n exportName = 'enhancedApi',\n argSuffix = 'ApiArg',\n responseSuffix = 'ApiResponse',\n operationNameSuffix = '',\n hooks = false,\n tag = false,\n outputFile,\n isDataResponse = defaultIsDataResponse,\n filterEndpoints,\n endpointOverrides,\n unionUndefined,\n encodePathParams = false,\n encodeQueryParams = false,\n flattenArg = false,\n includeDefault = false,\n useEnumType = false,\n mergeReadWriteOnly = false,\n httpResolverOptions,\n }: GenerationOptions\n) {\n const v3Doc = (v3DocCache[spec] ??= await getV3Doc(spec, httpResolverOptions));\n\n const apiGen = new ApiGenerator(v3Doc, {\n unionUndefined,\n useEnumType,\n mergeReadWriteOnly,\n });\n\n // temporary workaround for https://github.com/oazapfts/oazapfts/issues/491\n if (apiGen.spec.components?.schemas) {\n apiGen.preprocessComponents(apiGen.spec.components.schemas);\n }\n\n const operationDefinitions = getOperationDefinitions(v3Doc).filter(operationMatches(filterEndpoints));\n\n const resultFile = ts.createSourceFile(\n 'someFileName.ts',\n '',\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS\n );\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n const interfaces: Record<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration> = {};\n function registerInterface(declaration: ts.InterfaceDeclaration | ts.TypeAliasDeclaration) {\n const name = declaration.name.escapedText.toString();\n if (name in interfaces) {\n throw new Error(`interface/type alias ${name} already registered`);\n }\n interfaces[name] = declaration;\n return declaration;\n }\n\n if (outputFile) {\n outputFile = path.resolve(process.cwd(), outputFile);\n if (apiFile.startsWith('.')) {\n apiFile = path.relative(path.dirname(outputFile), apiFile);\n apiFile = apiFile.replace(/\\\\/g, '/');\n if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;\n }\n }\n apiFile = apiFile.replace(/\\.[jt]sx?$/, '');\n\n return printer.printNode(\n ts.EmitHint.Unspecified,\n factory.createSourceFile(\n [\n generateImportNode(apiFile, { [apiImport]: 'api' }),\n ...(tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : []),\n generateCreateApiCall({\n tag,\n endpointDefinitions: factory.createObjectLiteralExpression(\n operationDefinitions.map((operationDefinition) =>\n generateEndpoint({\n operationDefinition,\n overrides: getOverrides(operationDefinition, endpointOverrides),\n })\n ),\n true\n ),\n }),\n factory.createExportDeclaration(\n undefined,\n false,\n factory.createNamedExports([\n factory.createExportSpecifier(\n factory.createIdentifier(generatedApiName),\n factory.createIdentifier(exportName)\n ),\n ]),\n undefined\n ),\n ...Object.values(interfaces),\n ...apiGen.aliases,\n ...apiGen.enumAliases,\n ...(hooks\n ? [\n generateReactHooks({\n exportName: generatedApiName,\n operationDefinitions,\n endpointOverrides,\n config: hooks,\n }),\n ]\n : []),\n ],\n factory.createToken(ts.SyntaxKind.EndOfFileToken),\n ts.NodeFlags.None\n ),\n resultFile\n );\n\n function extractAllTagTypes({ operationDefinitions }: { operationDefinitions: OperationDefinition[] }) {\n const allTagTypes = new Set<string>();\n\n for (const operationDefinition of operationDefinitions) {\n const { verb, pathItem } = operationDefinition;\n for (const tag of getTags({ verb, pathItem })) {\n allTagTypes.add(tag);\n }\n }\n return [...allTagTypes];\n }\n\n function generateEndpoint({\n operationDefinition,\n overrides,\n }: {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n }) {\n const {\n verb,\n path,\n pathItem,\n operation,\n operation: { responses, requestBody },\n } = operationDefinition;\n const operationName = getOperationName({ verb, path, operation });\n const tags = tag ? getTags({ verb, pathItem }) : [];\n const isQuery = testIsQuery(verb, overrides);\n\n const returnsJson = apiGen.getResponseType(responses) === 'json';\n let ResponseType: ts.TypeNode = factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n if (returnsJson) {\n const returnTypes = Object.entries(responses || {})\n .map(\n ([code, response]) =>\n [\n code,\n apiGen.resolve(response),\n apiGen.getTypeFromResponse(response, 'readOnly') ||\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n ] as const\n )\n .filter(([status, response]) =>\n isDataResponse(status, includeDefault, apiGen.resolve(response), responses || {})\n )\n .filter(([_1, _2, type]) => type !== keywordType.void)\n .map(([code, response, type]) =>\n ts.addSyntheticLeadingComment(\n { ...type },\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* status ${code} ${response.description} `,\n false\n )\n );\n if (returnTypes.length > 0) {\n ResponseType = factory.createUnionTypeNode(returnTypes);\n }\n }\n\n const ResponseTypeName = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + responseSuffix),\n undefined,\n ResponseType\n )\n ).name\n );\n\n const operationParameters = apiGen.resolveArray(operation.parameters);\n const pathItemParameters = apiGen\n .resolveArray(pathItem.parameters)\n .filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));\n\n const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters]).filter(\n argumentMatches(overrides?.parameterFilter)\n );\n\n const allNames = parameters.map((p) => p.name);\n const queryArg: QueryArgDefinitions = {};\n function generateName(name: string, potentialPrefix: string) {\n const isPureSnakeCase = /^[a-zA-Z][a-zA-Z0-9_]*$/.test(name);\n // prefix with `query`, `path` or `body` if there are multiple paramters with the same name\n const hasNamingConflict = allNames.filter((n) => n === name).length > 1;\n if (hasNamingConflict) {\n name = `${potentialPrefix}_${name}`;\n }\n // convert to camelCase if the name is pure snake_case and there are no naming conflicts\n const camelCaseName = camelCase(name);\n if (isPureSnakeCase && !allNames.includes(camelCaseName)) {\n name = camelCaseName;\n }\n // if there are still any naming conflicts, prepend with underscore\n while (name in queryArg) {\n name = `_${name}`;\n }\n return name;\n }\n\n for (const param of parameters) {\n const name = generateName(param.name, param.in);\n queryArg[name] = {\n origin: 'param',\n name,\n originalName: param.name,\n type: apiGen.getTypeFromSchema(isReference(param) ? param : param.schema, undefined, 'writeOnly'),\n required: param.required,\n param,\n };\n }\n\n if (requestBody) {\n const body = apiGen.resolve(requestBody);\n const schema = apiGen.getSchemaFromContent(body.content);\n const type = apiGen.getTypeFromSchema(schema);\n const schemaName = camelCase(\n (type as any).name ||\n getReferenceName(schema) ||\n (typeof schema === 'object' && 'title' in schema && schema.title) ||\n 'body'\n );\n const name = generateName(schemaName in queryArg ? 'body' : schemaName, 'body');\n\n queryArg[name] = {\n origin: 'body',\n name,\n originalName: schemaName,\n type: apiGen.getTypeFromSchema(schema, undefined, 'writeOnly'),\n required: true,\n body,\n };\n }\n\n const propertyName = (name: string | ts.PropertyName): ts.PropertyName => {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);\n }\n return name;\n };\n\n const queryArgValues = Object.values(queryArg);\n\n const isFlatArg = flattenArg && queryArgValues.length === 1;\n const QueryArg = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + argSuffix),\n undefined,\n queryArgValues.length > 0\n ? isFlatArg\n ? withQueryComment(\n factory.createUnionTypeNode([\n queryArgValues[0].type,\n ...(!queryArgValues[0].required\n ? [factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)]\n : []),\n ]),\n queryArgValues[0],\n false\n )\n : factory.createTypeLiteralNode(\n queryArgValues.map((def) =>\n withQueryComment(\n factory.createPropertySignature(\n undefined,\n propertyName(def.name),\n createQuestionToken(!def.required),\n def.type\n ),\n def,\n true\n )\n )\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)\n )\n ).name\n );\n\n return generateEndpointDefinition({\n operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,\n type: isQuery ? 'query' : 'mutation',\n Response: ResponseTypeName,\n QueryArg,\n queryFn: generateQueryFn({\n operationDefinition,\n queryArg,\n isQuery,\n isFlatArg,\n encodePathParams,\n encodeQueryParams,\n }),\n extraEndpointsProps: isQuery\n ? generateQueryEndpointProps({ operationDefinition })\n : generateMutationEndpointProps({ operationDefinition }),\n tags,\n });\n }\n\n function generateQueryFn({\n operationDefinition,\n queryArg,\n isFlatArg,\n isQuery,\n encodePathParams,\n encodeQueryParams,\n }: {\n operationDefinition: OperationDefinition;\n queryArg: QueryArgDefinitions;\n isFlatArg: boolean;\n isQuery: boolean;\n encodePathParams: boolean;\n encodeQueryParams: boolean;\n }) {\n const { path, verb } = operationDefinition;\n\n const bodyParameter = Object.values(queryArg).find((def) => def.origin === 'body');\n\n const rootObject = factory.createIdentifier('queryArg');\n\n function pickParams(paramIn: string) {\n return Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === paramIn);\n }\n\n function createObjectLiteralProperty(parameters: QueryArgDefinition[], propertyName: string) {\n if (parameters.length === 0) return undefined;\n\n const properties = parameters.map((param) => {\n const value = isFlatArg ? rootObject : accessProperty(rootObject, param.name);\n\n const encodedValue =\n encodeQueryParams && param.param?.in === 'query'\n ? factory.createConditionalExpression(\n value,\n undefined,\n factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ]),\n undefined,\n factory.createIdentifier('undefined')\n )\n : value;\n\n return createPropertyAssignment(param.originalName, encodedValue);\n });\n\n return factory.createPropertyAssignment(\n factory.createIdentifier(propertyName),\n factory.createObjectLiteralExpression(properties, true)\n );\n }\n\n return factory.createArrowFunction(\n undefined,\n undefined,\n Object.keys(queryArg).length\n ? [factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)]\n : [],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(\n factory.createObjectLiteralExpression(\n [\n factory.createPropertyAssignment(\n factory.createIdentifier('url'),\n generatePathExpression(path, pickParams('path'), rootObject, isFlatArg, encodePathParams)\n ),\n isQuery && verb.toUpperCase() === 'GET'\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('method'),\n factory.createStringLiteral(verb.toUpperCase())\n ),\n bodyParameter === undefined\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('body'),\n isFlatArg\n ? rootObject\n : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(bodyParameter.name))\n ),\n createObjectLiteralProperty(pickParams('cookie'), 'cookies'),\n createObjectLiteralProperty(pickParams('header'), 'headers'),\n createObjectLiteralProperty(pickParams('query'), 'params'),\n ].filter(removeUndefined),\n false\n )\n )\n );\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateQueryEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateMutationEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n}\n\nfunction accessProperty(rootObject: ts.Identifier, propertyName: string) {\n return isValidIdentifier(propertyName)\n ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName))\n : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));\n}\n\nfunction generatePathExpression(\n path: string,\n pathParameters: QueryArgDefinition[],\n rootObject: ts.Identifier,\n isFlatArg: boolean,\n encodePathParams: boolean\n) {\n const expressions: Array<[string, string]> = [];\n\n const head = path.replace(/\\{(.*?)}(.*?)(?=\\{|$)/g, (_, expression, literal) => {\n const param = pathParameters.find((p) => p.originalName === expression);\n if (!param) {\n throw new Error(`path parameter ${expression} does not seem to be defined in '${path}'!`);\n }\n expressions.push([param.name, literal]);\n return '';\n });\n\n return expressions.length\n ? factory.createTemplateExpression(\n factory.createTemplateHead(head),\n expressions.map(([prop, literal], index) => {\n const value = isFlatArg ? rootObject : accessProperty(rootObject, prop);\n const encodedValue = encodePathParams\n ? factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ])\n : value;\n return factory.createTemplateSpan(\n encodedValue,\n index === expressions.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal)\n );\n })\n )\n : factory.createNoSubstitutionTemplateLiteral(head);\n}\n\ntype QueryArgDefinition = {\n name: string;\n originalName: string;\n type: ts.TypeNode;\n required?: boolean;\n param?: OpenAPIV3.ParameterObject;\n} & (\n | {\n origin: 'param';\n param: OpenAPIV3.ParameterObject;\n }\n | {\n origin: 'body';\n body: OpenAPIV3.RequestBodyObject;\n }\n);\ntype QueryArgDefinitions = Record<string, QueryArgDefinition>;\n","import ts from 'typescript';\nimport semver from 'semver';\n\nconst originalFactory = ts.factory;\n\nfunction createImportSpecifier(propertyName: ts.Identifier | undefined, name: ts.Identifier): ts.ImportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createImportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createImportSpecifier(propertyName, name);\n}\n\nfunction createExportSpecifier(\n propertyName: string | ts.Identifier | undefined,\n name: string | ts.Identifier\n): ts.ExportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createExportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createExportSpecifier(propertyName, name);\n}\n\nexport const factory = {\n ...originalFactory,\n createImportSpecifier,\n createExportSpecifier,\n};\n","import { factory } from './utils/factory';\nimport ts from 'typescript';\n\nconst defaultEndpointBuilder = factory.createIdentifier('build');\n\nexport type ObjectPropertyDefinitions = Record<string, ts.Expression | undefined>;\nexport function generateObjectProperties(obj: ObjectPropertyDefinitions) {\n return Object.entries(obj)\n .filter(([_, v]) => v)\n .map(([k, v]) => factory.createPropertyAssignment(factory.createIdentifier(k), v as ts.Expression));\n}\n\nexport function generateImportNode(pkg: string, namedImports: Record<string, string>, defaultImportName?: string) {\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n defaultImportName !== undefined ? factory.createIdentifier(defaultImportName) : undefined,\n factory.createNamedImports(\n Object.entries(namedImports).map(([propertyName, name]) =>\n factory.createImportSpecifier(\n name === propertyName ? undefined : factory.createIdentifier(propertyName),\n factory.createIdentifier(name)\n )\n )\n )\n ),\n factory.createStringLiteral(pkg)\n );\n}\n\nexport function generateCreateApiCall({\n endpointBuilder = defaultEndpointBuilder,\n endpointDefinitions,\n tag,\n}: {\n endpointBuilder?: ts.Identifier;\n endpointDefinitions: ts.ObjectLiteralExpression;\n tag: boolean;\n}) {\n const injectEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n generateObjectProperties({\n endpoints: factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, endpointBuilder, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(endpointDefinitions)\n ),\n overrideExisting: factory.createFalse(),\n }),\n true\n );\n if (tag) {\n const enhanceEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n [factory.createShorthandPropertyAssignment(factory.createIdentifier('addTagTypes'), undefined)],\n true\n );\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('enhanceEndpoints')\n ),\n undefined,\n [enhanceEndpointsObjectLiteralExpression]\n ),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n }\n\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n\nexport function generateEndpointDefinition({\n operationName,\n type,\n Response,\n QueryArg,\n queryFn,\n endpointBuilder = defaultEndpointBuilder,\n extraEndpointsProps,\n tags,\n}: {\n operationName: string;\n type: 'query' | 'mutation';\n Response: ts.TypeReferenceNode;\n QueryArg: ts.TypeReferenceNode;\n queryFn: ts.Expression;\n endpointBuilder?: ts.Identifier;\n extraEndpointsProps: ObjectPropertyDefinitions;\n tags: string[];\n}) {\n const objectProperties = generateObjectProperties({ query: queryFn, ...extraEndpointsProps });\n if (tags.length > 0) {\n objectProperties.push(\n factory.createPropertyAssignment(\n factory.createIdentifier(type === 'query' ? 'providesTags' : 'invalidatesTags'),\n factory.createArrayLiteralExpression(tags.map((tag) => factory.createStringLiteral(tag), false))\n )\n );\n }\n return factory.createPropertyAssignment(\n factory.createIdentifier(operationName),\n\n factory.createCallExpression(\n factory.createPropertyAccessExpression(endpointBuilder, factory.createIdentifier(type)),\n [Response, QueryArg],\n [factory.createObjectLiteralExpression(objectProperties, true)]\n )\n );\n}\n\nexport function generateTagTypes({ addTagTypes }: { addTagTypes: string[] }) {\n return factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('addTagTypes'),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createArrayLiteralExpression(\n addTagTypes.map((tagType) => factory.createStringLiteral(tagType)),\n true\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined)\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n","import ts from 'typescript';\nimport { getOperationName } from 'oazapfts/generate';\nimport { capitalize, isQuery } from '../utils';\nimport type { OperationDefinition, EndpointOverrides, ConfigFile } from '../types';\nimport { getOverrides } from '../generate';\nimport { factory } from '../utils/factory';\n\ntype HooksConfigOptions = NonNullable<ConfigFile['hooks']>;\n\ntype GetReactHookNameParams = {\n operationDefinition: OperationDefinition;\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\n\ntype CreateBindingParams = {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n isLazy?: boolean;\n};\n\nconst createBinding = ({\n operationDefinition: { verb, path, operation },\n overrides,\n isLazy = false,\n}: CreateBindingParams) =>\n factory.createBindingElement(\n undefined,\n undefined,\n factory.createIdentifier(\n `use${isLazy ? 'Lazy' : ''}${capitalize(getOperationName(verb, path, operation.operationId))}${\n isQuery(verb, overrides) ? 'Query' : 'Mutation'\n }`\n ),\n undefined\n );\n\nconst getReactHookName = ({ operationDefinition, endpointOverrides, config }: GetReactHookNameParams) => {\n const overrides = getOverrides(operationDefinition, endpointOverrides);\n\n const baseParams = {\n operationDefinition,\n overrides,\n };\n\n const _isQuery = isQuery(operationDefinition.verb, overrides);\n\n // If `config` is true, just generate everything\n if (typeof config === 'boolean') {\n return createBinding(baseParams);\n }\n\n // `config` is an object and we need to check for the configuration of each property\n if (_isQuery) {\n return [\n ...(config.queries ? [createBinding(baseParams)] : []),\n ...(config.lazyQueries ? [createBinding({ ...baseParams, isLazy: true })] : []),\n ];\n }\n\n return config.mutations ? createBinding(baseParams) : [];\n};\n\ntype GenerateReactHooksParams = {\n exportName: string;\n operationDefinitions: OperationDefinition[];\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\nexport const generateReactHooks = ({\n exportName,\n operationDefinitions,\n endpointOverrides,\n config,\n}: GenerateReactHooksParams) =>\n factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createObjectBindingPattern(\n operationDefinitions\n .map((operationDefinition) => getReactHookName({ operationDefinition, endpointOverrides, config }))\n .flat()\n ),\n undefined,\n undefined,\n factory.createIdentifier(exportName)\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n","export function capitalize(str: string) {\n return str.replace(str[0], str[0].toUpperCase());\n}\n","import type SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nexport type OperationDefinition = {\n path: string;\n verb: (typeof operationKeys)[number];\n pathItem: OpenAPIV3.PathItemObject;\n operation: OpenAPIV3.OperationObject;\n};\n\nexport type ParameterDefinition = OpenAPIV3.ParameterObject;\n\ntype Require<T, K extends keyof T> = { [k in K]-?: NonNullable<T[k]> } & Omit<T, K>;\ntype Optional<T, K extends keyof T> = { [k in K]?: NonNullable<T[k]> } & Omit<T, K>;\ntype Id<T> = { [K in keyof T]: T[K] } & {};\ntype AtLeastOneKey<T> = {\n [K in keyof T]-?: Pick<T, K> & Partial<T>;\n}[keyof T];\n\nexport const operationKeys = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;\n\nexport type GenerationOptions = Id<\n CommonOptions &\n Optional<OutputFileOptions, 'outputFile'> & {\n isDataResponse?(\n code: string,\n includeDefault: boolean,\n response: OpenAPIV3.ResponseObject,\n allResponses: OpenAPIV3.ResponsesObject\n ): boolean;\n }\n>;\n\nexport interface CommonOptions {\n apiFile: string;\n /**\n * filename or url\n */\n schemaFile: string;\n /**\n * defaults to \"api\"\n */\n apiImport?: string;\n /**\n * defaults to \"enhancedApi\"\n */\n exportName?: string;\n /**\n * defaults to \"ApiArg\"\n */\n argSuffix?: string;\n /**\n * defaults to \"ApiResponse\"\n */\n responseSuffix?: string;\n /**\n * defaults to empty\n */\n operationNameSuffix?: string;\n /**\n * defaults to `false`\n * `true` will generate hooks for queries and mutations, but no lazyQueries\n */\n hooks?: boolean | { queries: boolean; lazyQueries: boolean; mutations: boolean };\n /**\n * defaults to false\n * `true` will generate a union type for `undefined` properties like: `{ id?: string | undefined }` instead of `{ id?: string }`\n */\n unionUndefined?: boolean;\n /**\n * defaults to false\n * `true` will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition\n * @see https://redux-toolkit.js.org/rtk-query/usage/code-generation for more information\n */\n tag?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated path parameters\n */\n encodePathParams?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated query parameters\n */\n encodeQueryParams?: boolean;\n /**\n * defaults to false\n * `true` will \"flatten\" the arg so that you can do things like `useGetEntityById(1)` instead of `useGetEntityById({ entityId: 1 })`\n */\n flattenArg?: boolean;\n /**\n * default to false\n * If set to `true`, the default response type will be included in the generated code for all endpoints.\n * @see https://swagger.io/docs/specification/describing-responses/#default\n */\n includeDefault?: boolean;\n /**\n * default to false\n * `true` will not generate separate types for read-only and write-only properties.\n */\n mergeReadWriteOnly?: boolean;\n /**\n *\n * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.\n */\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions;\n\n /**\n * defaults to undefined\n * If present the given file will be used as prettier config when formatting the generated code. If undefined the default prettier config\n * resolution mechanism will be used.\n */\n prettierConfigFile?: string;\n}\n\nexport type TextMatcher = string | RegExp | (string | RegExp)[];\n\nexport type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;\n\nexport type EndpointMatcher = TextMatcher | EndpointMatcherFunction;\n\nexport type ParameterMatcherFunction = (parameterName: string, parameterDefinition: ParameterDefinition) => boolean;\n\nexport type ParameterMatcher = TextMatcher | ParameterMatcherFunction;\n\nexport interface OutputFileOptions extends Partial<CommonOptions> {\n outputFile: string;\n filterEndpoints?: EndpointMatcher;\n endpointOverrides?: EndpointOverrides[];\n /**\n * defaults to false\n * If passed as true it will generate TS enums instead of union of strings\n */\n useEnumType?: boolean;\n}\n\nexport type EndpointOverrides = {\n pattern: EndpointMatcher;\n} & AtLeastOneKey<{\n type: 'mutation' | 'query';\n parameterFilter: ParameterMatcher;\n}>;\n\nexport type ConfigFile =\n | Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>>\n | Id<\n Omit<CommonOptions, 'outputFile'> & {\n outputFiles: { [outputFile: string]: Omit<OutputFileOptions, 'outputFile'> };\n }\n >;\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { OperationDefinition } from '../types';\nimport { operationKeys } from '../types';\n\nexport function getOperationDefinitions(v3Doc: OpenAPIV3.Document): OperationDefinition[] {\n return Object.entries(v3Doc.paths).flatMap(([path, pathItem]) =>\n !pathItem\n ? []\n : Object.entries(pathItem)\n .filter((arg): arg is [(typeof operationKeys)[number], OpenAPIV3.OperationObject] =>\n operationKeys.includes(arg[0] as any)\n )\n .map(([verb, operation]) => ({\n path,\n verb,\n pathItem,\n operation,\n }))\n );\n}\n","import SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n// @ts-ignore\nimport converter from 'swagger2openapi';\n\nexport async function getV3Doc(\n spec: string,\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions\n): Promise<OpenAPIV3.Document> {\n const doc = await SwaggerParser.bundle(spec, {\n resolve: {\n http: httpResolverOptions,\n },\n });\n\n const isOpenApiV3 = 'openapi' in doc && doc.openapi.startsWith('3');\n\n if (isOpenApiV3) {\n return doc as OpenAPIV3.Document;\n } else {\n const result = await converter.convertObj(doc, {});\n return result.openapi as OpenAPIV3.Document;\n }\n}\n","import type { EndpointOverrides, operationKeys } from '../types';\n\nexport function isQuery(verb: (typeof operationKeys)[number], overrides: EndpointOverrides | undefined) {\n if (overrides?.type) {\n return overrides.type === 'query';\n }\n return verb === 'get';\n}\n","export function isValidUrl(string: string) {\n try {\n new URL(string);\n } catch (_) {\n return false;\n }\n\n return true;\n}\n","import path from 'node:path';\nimport prettier from 'prettier';\nimport type { BuiltInParserName } from 'prettier';\n\nconst EXTENSION_TO_PARSER: Record<string, BuiltInParserName> = {\n ts: 'typescript',\n tsx: 'typescript',\n js: 'babel',\n jsx: 'babel',\n 'js.flow': 'flow',\n flow: 'flow',\n gql: 'graphql',\n graphql: 'graphql',\n css: 'scss',\n scss: 'scss',\n less: 'scss',\n stylus: 'scss',\n markdown: 'markdown',\n md: 'markdown',\n json: 'json',\n};\n\nexport async function prettify(filePath: string | null, content: string, prettierConfigFile?: string): Promise<string> {\n let config = null;\n let parser = 'typescript';\n\n if (filePath) {\n const fileExtension = path.extname(filePath).slice(1);\n parser = EXTENSION_TO_PARSER[fileExtension];\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n editorconfig: !prettierConfigFile,\n config: prettierConfigFile,\n });\n } else if (prettierConfigFile) {\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n config: prettierConfigFile,\n });\n }\n\n return prettier.format(content, {\n parser,\n ...config,\n });\n}\n","export function removeUndefined<T>(t: T | undefined): t is T {\n return typeof t !== 'undefined';\n}\n"],"mappings":";AAEA,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AAIhD,IAAM,aAA6B,4BAAY;;;ACRtD,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAC9B,OAAOA,WAAU;;;ACFjB,OAAO,eAAe;AACtB,OAAOC,WAAU;AACjB,OAAO;AAAA,EACL,oBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAOC,SAAQ;;;ACbf,OAAO,QAAQ;AACf,OAAO,YAAY;AAEnB,IAAM,kBAAkB,GAAG;AAE3B,SAAS,sBAAsB,cAAyC,MAAyC;AAC/G,MAAI,OAAO,UAAU,GAAG,SAAS,QAAQ;AAEvC,WAAO,gBAAgB,sBAAsB,OAAO,cAAc,IAAI;AAExE,SAAO,gBAAgB,sBAAsB,cAAc,IAAI;AACjE;AAEA,SAAS,sBACP,cACA,MACoB;AACpB,MAAI,OAAO,UAAU,GAAG,SAAS,QAAQ;AAEvC,WAAO,gBAAgB,sBAAsB,OAAO,cAAc,IAAI;AAExE,SAAO,gBAAgB,sBAAsB,cAAc,IAAI;AACjE;AAEO,IAAM,UAAU;AAAA,EACrB,GAAG;AAAA,EACH;AAAA,EACA;AACF;;;AC3BA,OAAOC,SAAQ;AAEf,IAAM,yBAAyB,QAAQ,iBAAiB,OAAO;AAGxD,SAAS,yBAAyB,KAAgC;AACvE,SAAO,OAAO,QAAQ,GAAG,EACtB,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EACpB,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,QAAQ,yBAAyB,QAAQ,iBAAiB,CAAC,GAAG,CAAkB,CAAC;AACtG;AAEO,SAAS,mBAAmB,KAAa,cAAsC,mBAA4B;A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AAAA,EACF;AACF;","names":["path","path","ts","ts","ts","path","path","ts","getOperationName","path","ts","operationDefinitions","tag","isQuery","encodePathParams","encodeQueryParams","require","path"]}
|
|
1
|
+
{"version":3,"sources":["../node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/generate.ts","../src/utils/factory.ts","../src/codegen.ts","../src/generators/react-hooks.ts","../src/utils/capitalize.ts","../src/types.ts","../src/utils/getOperationDefinitions.ts","../src/utils/getV3Doc.ts","../src/utils/isQuery.ts","../src/utils/isValidUrl.ts","../src/utils/prettier.ts","../src/utils/removeUndefined.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { generateApi } from './generate';\nimport type { CommonOptions, ConfigFile, GenerationOptions, OutputFileOptions } from './types';\nimport { isValidUrl, prettify } from './utils';\nexport type { ConfigFile } from './types';\n\nconst require = createRequire(__filename);\n\nexport async function generateEndpoints(options: GenerationOptions): Promise<string | void> {\n const schemaLocation = options.schemaFile;\n\n const schemaAbsPath = isValidUrl(options.schemaFile)\n ? options.schemaFile\n : path.resolve(process.cwd(), schemaLocation);\n\n const sourceCode = await enforceOazapftsTsVersion(async () => {\n return generateApi(schemaAbsPath, options);\n });\n const { outputFile, prettierConfigFile } = options;\n if (outputFile) {\n fs.writeFileSync(\n path.resolve(process.cwd(), outputFile),\n await prettify(outputFile, sourceCode, prettierConfigFile)\n );\n } else {\n return await prettify(null, sourceCode, prettierConfigFile);\n }\n}\n\nexport function parseConfig(fullConfig: ConfigFile) {\n const outFiles: (CommonOptions & OutputFileOptions)[] = [];\n\n if ('outputFiles' in fullConfig) {\n const { outputFiles, ...commonConfig } = fullConfig;\n for (const [outputFile, specificConfig] of Object.entries(outputFiles)) {\n outFiles.push({\n ...commonConfig,\n ...specificConfig,\n outputFile,\n });\n }\n } else {\n outFiles.push(fullConfig);\n }\n return outFiles;\n}\n\n/**\n * Enforces `oazapfts` to use the same TypeScript version as this module itself uses.\n * That should prevent enums from running out of sync if both libraries use different TS versions.\n */\nfunction enforceOazapftsTsVersion<T>(cb: () => T): T {\n const ozTsPath = require.resolve('typescript', { paths: [require.resolve('oazapfts')] });\n const tsPath = require.resolve('typescript');\n const originalEntry = require.cache[ozTsPath];\n try {\n require.cache[ozTsPath] = require.cache[tsPath];\n return cb();\n } finally {\n if (originalEntry) {\n require.cache[ozTsPath] = originalEntry;\n } else {\n delete require.cache[ozTsPath];\n }\n }\n}\n","import camelCase from 'lodash.camelcase';\nimport path from 'node:path';\nimport ApiGenerator, {\n getOperationName as _getOperationName,\n getReferenceName,\n isReference,\n supportDeepObjects,\n createPropertyAssignment,\n createQuestionToken,\n isValidIdentifier,\n keywordType,\n} from 'oazapfts/generate';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport ts from 'typescript';\nimport type { ObjectPropertyDefinitions } from './codegen';\nimport { generateCreateApiCall, generateEndpointDefinition, generateImportNode, generateTagTypes } from './codegen';\nimport { generateReactHooks } from './generators/react-hooks';\nimport type {\n EndpointMatcher,\n EndpointOverrides,\n GenerationOptions,\n OperationDefinition,\n ParameterDefinition,\n ParameterMatcher,\n TextMatcher,\n} from './types';\nimport { capitalize, getOperationDefinitions, getV3Doc, removeUndefined, isQuery as testIsQuery } from './utils';\nimport { factory } from './utils/factory';\n\nconst generatedApiName = 'injectedRtkApi';\nconst v3DocCache: Record<string, OpenAPIV3.Document> = {};\n\nfunction defaultIsDataResponse(code: string, includeDefault: boolean) {\n if (includeDefault && code === 'default') {\n return true;\n }\n const parsedCode = Number(code);\n return !Number.isNaN(parsedCode) && parsedCode >= 200 && parsedCode < 300;\n}\n\nfunction getOperationName({ verb, path, operation }: Pick<OperationDefinition, 'verb' | 'path' | 'operation'>) {\n return _getOperationName(verb, path, operation.operationId);\n}\n\nfunction getTags({ verb, pathItem }: Pick<OperationDefinition, 'verb' | 'pathItem'>): string[] {\n return verb ? pathItem[verb]?.tags || [] : [];\n}\n\nfunction patternMatches(pattern?: TextMatcher) {\n const filters = Array.isArray(pattern) ? pattern : [pattern];\n return function matcher(operationName: string) {\n if (!pattern) return true;\n return filters.some((filter) =>\n typeof filter === 'string' ? filter === operationName : filter?.test(operationName)\n );\n };\n}\n\nfunction operationMatches(pattern?: EndpointMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(operationDefinition: OperationDefinition) {\n if (!pattern) return true;\n const operationName = getOperationName(operationDefinition);\n return checkMatch(operationName, operationDefinition);\n };\n}\n\nfunction argumentMatches(pattern?: ParameterMatcher) {\n const checkMatch = typeof pattern === 'function' ? pattern : patternMatches(pattern);\n return function matcher(argumentDefinition: ParameterDefinition) {\n if (!pattern || argumentDefinition.in === 'path') return true;\n const argumentName = argumentDefinition.name;\n return checkMatch(argumentName, argumentDefinition);\n };\n}\n\nfunction withQueryComment<T extends ts.Node>(node: T, def: QueryArgDefinition, hasTrailingNewLine: boolean): T {\n const comment = def.origin === 'param' ? def.param.description : def.body.description;\n if (comment) {\n return ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* ${comment} `,\n hasTrailingNewLine\n );\n }\n return node;\n}\n\nexport function getOverrides(\n operation: OperationDefinition,\n endpointOverrides?: EndpointOverrides[]\n): EndpointOverrides | undefined {\n return endpointOverrides?.find((override) => operationMatches(override.pattern)(operation));\n}\n\nexport async function generateApi(\n spec: string,\n {\n apiFile,\n apiImport = 'api',\n exportName = 'enhancedApi',\n argSuffix = 'ApiArg',\n responseSuffix = 'ApiResponse',\n operationNameSuffix = '',\n hooks = false,\n tag = false,\n outputFile,\n isDataResponse = defaultIsDataResponse,\n filterEndpoints,\n endpointOverrides,\n unionUndefined,\n encodePathParams = false,\n encodeQueryParams = false,\n flattenArg = false,\n includeDefault = false,\n useEnumType = false,\n mergeReadWriteOnly = false,\n httpResolverOptions,\n }: GenerationOptions\n) {\n const v3Doc = (v3DocCache[spec] ??= await getV3Doc(spec, httpResolverOptions));\n\n const apiGen = new ApiGenerator(v3Doc, {\n unionUndefined,\n useEnumType,\n mergeReadWriteOnly,\n });\n\n // temporary workaround for https://github.com/oazapfts/oazapfts/issues/491\n if (apiGen.spec.components?.schemas) {\n apiGen.preprocessComponents(apiGen.spec.components.schemas);\n }\n\n const operationDefinitions = getOperationDefinitions(v3Doc).filter(operationMatches(filterEndpoints));\n\n const resultFile = ts.createSourceFile(\n 'someFileName.ts',\n '',\n ts.ScriptTarget.Latest,\n /*setParentNodes*/ false,\n ts.ScriptKind.TS\n );\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n const interfaces: Record<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration> = {};\n function registerInterface(declaration: ts.InterfaceDeclaration | ts.TypeAliasDeclaration) {\n const name = declaration.name.escapedText.toString();\n if (name in interfaces) {\n throw new Error(`interface/type alias ${name} already registered`);\n }\n interfaces[name] = declaration;\n return declaration;\n }\n\n if (outputFile) {\n outputFile = path.resolve(process.cwd(), outputFile);\n if (apiFile.startsWith('.')) {\n apiFile = path.relative(path.dirname(outputFile), apiFile);\n apiFile = apiFile.replace(/\\\\/g, '/');\n if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;\n }\n }\n apiFile = apiFile.replace(/\\.[jt]sx?$/, '');\n\n return printer.printNode(\n ts.EmitHint.Unspecified,\n factory.createSourceFile(\n [\n generateImportNode(apiFile, { [apiImport]: 'api' }),\n generateImportNode('@acrool/react-fetcher', { IRestFulEndpointsQueryReturn: 'IRestFulEndpointsQueryReturn' }),\n ...(tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : []),\n generateCreateApiCall({\n tag,\n endpointDefinitions: factory.createObjectLiteralExpression(\n operationDefinitions.map((operationDefinition) =>\n generateEndpoint({\n operationDefinition,\n overrides: getOverrides(operationDefinition, endpointOverrides),\n })\n ),\n true\n ),\n }),\n factory.createExportDeclaration(\n undefined,\n false,\n factory.createNamedExports([\n factory.createExportSpecifier(\n factory.createIdentifier(generatedApiName),\n factory.createIdentifier(exportName)\n ),\n ]),\n undefined\n ),\n ...Object.values(interfaces),\n ...apiGen.aliases,\n ...apiGen.enumAliases,\n ...(hooks\n ? [\n generateReactHooks({\n exportName: generatedApiName,\n operationDefinitions,\n endpointOverrides,\n config: hooks,\n }),\n ]\n : []),\n ],\n factory.createToken(ts.SyntaxKind.EndOfFileToken),\n ts.NodeFlags.None\n ),\n resultFile\n );\n\n function extractAllTagTypes({ operationDefinitions }: { operationDefinitions: OperationDefinition[] }) {\n const allTagTypes = new Set<string>();\n\n for (const operationDefinition of operationDefinitions) {\n const { verb, pathItem } = operationDefinition;\n for (const tag of getTags({ verb, pathItem })) {\n allTagTypes.add(tag);\n }\n }\n return [...allTagTypes];\n }\n\n function generateEndpoint({\n operationDefinition,\n overrides,\n }: {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n }) {\n const {\n verb,\n path,\n pathItem,\n operation,\n operation: { responses, requestBody },\n } = operationDefinition;\n const operationName = getOperationName({ verb, path, operation });\n const tags = tag ? getTags({ verb, pathItem }) : [];\n const isQuery = testIsQuery(verb, overrides);\n\n const returnsJson = apiGen.getResponseType(responses) === 'json';\n let ResponseType: ts.TypeNode = factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n if (returnsJson) {\n const returnTypes = Object.entries(responses || {})\n .map(\n ([code, response]) =>\n [\n code,\n apiGen.resolve(response),\n apiGen.getTypeFromResponse(response, 'readOnly') ||\n factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n ] as const\n )\n .filter(([status, response]) =>\n isDataResponse(status, includeDefault, apiGen.resolve(response), responses || {})\n )\n .filter(([_1, _2, type]) => type !== keywordType.void)\n .map(([code, response, type]) =>\n ts.addSyntheticLeadingComment(\n { ...type },\n ts.SyntaxKind.MultiLineCommentTrivia,\n `* status ${code} ${response.description} `,\n false\n )\n );\n if (returnTypes.length > 0) {\n ResponseType = factory.createUnionTypeNode(returnTypes);\n }\n }\n\n const ResponseTypeName = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + responseSuffix),\n undefined,\n ResponseType\n )\n ).name\n );\n\n const operationParameters = apiGen.resolveArray(operation.parameters);\n const pathItemParameters = apiGen\n .resolveArray(pathItem.parameters)\n .filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));\n\n const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters])\n .filter(argumentMatches(overrides?.parameterFilter))\n .filter(param => param.in !== 'header');\n\n const allNames = parameters.map((p) => p.name);\n const queryArg: QueryArgDefinitions = {};\n function generateName(name: string, potentialPrefix: string) {\n const isPureSnakeCase = /^[a-zA-Z][a-zA-Z0-9_]*$/.test(name);\n // prefix with `query`, `path` or `body` if there are multiple paramters with the same name\n const hasNamingConflict = allNames.filter((n) => n === name).length > 1;\n if (hasNamingConflict) {\n name = `${potentialPrefix}_${name}`;\n }\n // convert to camelCase if the name is pure snake_case and there are no naming conflicts\n const camelCaseName = camelCase(name);\n if (isPureSnakeCase && !allNames.includes(camelCaseName)) {\n name = camelCaseName;\n }\n // if there are still any naming conflicts, prepend with underscore\n while (name in queryArg) {\n name = `_${name}`;\n }\n return name;\n }\n\n for (const param of parameters) {\n const name = generateName(param.name, param.in);\n queryArg[name] = {\n origin: 'param',\n name,\n originalName: param.name,\n type: apiGen.getTypeFromSchema(isReference(param) ? param : param.schema, undefined, 'writeOnly'),\n required: param.required,\n param,\n };\n }\n\n if (requestBody) {\n const body = apiGen.resolve(requestBody);\n const schema = apiGen.getSchemaFromContent(body.content);\n const type = apiGen.getTypeFromSchema(schema);\n const schemaName = camelCase(\n (type as any).name ||\n getReferenceName(schema) ||\n (typeof schema === 'object' && 'title' in schema && schema.title) ||\n 'body'\n );\n const name = generateName(schemaName in queryArg ? 'body' : schemaName, 'body');\n\n queryArg[name] = {\n origin: 'body',\n name,\n originalName: schemaName,\n type: apiGen.getTypeFromSchema(schema, undefined, 'writeOnly'),\n required: true,\n body,\n };\n }\n\n const propertyName = (name: string | ts.PropertyName): ts.PropertyName => {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);\n }\n return name;\n };\n\n const queryArgValues = Object.values(queryArg);\n\n const isFlatArg = flattenArg && queryArgValues.length === 1;\n const QueryArg = factory.createTypeReferenceNode(\n registerInterface(\n factory.createTypeAliasDeclaration(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n capitalize(operationName + operationNameSuffix + argSuffix),\n undefined,\n queryArgValues.length > 0\n ? isFlatArg\n ? withQueryComment(\n factory.createUnionTypeNode([\n queryArgValues[0].type,\n ...(!queryArgValues[0].required\n ? [factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)]\n : []),\n ]),\n queryArgValues[0],\n false\n )\n : factory.createTypeLiteralNode(\n queryArgValues.map((def) =>\n withQueryComment(\n factory.createPropertySignature(\n undefined,\n propertyName(def.name),\n createQuestionToken(!def.required),\n def.type\n ),\n def,\n true\n )\n )\n )\n : factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)\n )\n ).name\n );\n\n return generateEndpointDefinition({\n operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,\n type: isQuery ? 'query' : 'mutation',\n Response: ResponseTypeName,\n QueryArg: factory.createTypeReferenceNode(\n factory.createIdentifier('IRestFulEndpointsQueryReturn'),\n [QueryArg]\n ),\n queryFn: generateQueryFn({\n operationDefinition,\n queryArg,\n isQuery,\n isFlatArg,\n encodePathParams,\n encodeQueryParams,\n }),\n extraEndpointsProps: isQuery\n ? generateQueryEndpointProps({ operationDefinition })\n : generateMutationEndpointProps({ operationDefinition }),\n tags,\n });\n }\n\n function generateQueryFn({\n operationDefinition,\n queryArg,\n isFlatArg,\n isQuery,\n encodePathParams,\n encodeQueryParams,\n }: {\n operationDefinition: OperationDefinition;\n queryArg: QueryArgDefinitions;\n isFlatArg: boolean;\n isQuery: boolean;\n encodePathParams: boolean;\n encodeQueryParams: boolean;\n }) {\n const { path, verb } = operationDefinition;\n\n const bodyParameter = Object.values(queryArg).find((def) => def.origin === 'body');\n\n const rootObject = factory.createIdentifier('queryArg');\n const variablesObject = factory.createPropertyAccessExpression(rootObject, factory.createIdentifier('variables'));\n\n function pickParams(paramIn: string) {\n return Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === paramIn);\n }\n\n function createObjectLiteralProperty(parameters: QueryArgDefinition[], propertyName: string) {\n if (parameters.length === 0) return undefined;\n\n const properties = parameters.map((param) => {\n const value = isFlatArg \n ? variablesObject \n : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(param.name));\n\n const encodedValue =\n encodeQueryParams && param.param?.in === 'query'\n ? factory.createConditionalExpression(\n value,\n undefined,\n factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ]),\n undefined,\n factory.createIdentifier('undefined')\n )\n : value;\n\n return createPropertyAssignment(param.originalName, encodedValue);\n });\n\n return factory.createPropertyAssignment(\n factory.createIdentifier(propertyName),\n factory.createObjectLiteralExpression(properties, true)\n );\n }\n\n return factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(\n factory.createObjectLiteralExpression(\n [\n factory.createPropertyAssignment(\n factory.createIdentifier('url'),\n generatePathExpression(path, pickParams('path'), variablesObject, isFlatArg, encodePathParams)\n ),\n isQuery && verb.toUpperCase() === 'GET'\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('method'),\n factory.createStringLiteral(verb.toUpperCase())\n ),\n bodyParameter === undefined\n ? undefined\n : factory.createPropertyAssignment(\n factory.createIdentifier('body'),\n isFlatArg\n ? variablesObject\n : factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(bodyParameter.name))\n ),\n createObjectLiteralProperty(pickParams('cookie'), 'cookies'),\n createObjectLiteralProperty(pickParams('query'), 'params'),\n factory.createPropertyAssignment(\n factory.createIdentifier('fetchOptions'),\n factory.createPropertyAccessChain(\n rootObject,\n factory.createToken(ts.SyntaxKind.QuestionDotToken),\n factory.createIdentifier('fetchOptions')\n )\n ),\n ].filter(removeUndefined),\n false\n )\n )\n );\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateQueryEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n\n // eslint-disable-next-line no-empty-pattern\n function generateMutationEndpointProps({}: { operationDefinition: OperationDefinition }): ObjectPropertyDefinitions {\n return {}; /* TODO needs implementation - skip for now */\n }\n}\n\nfunction accessProperty(rootObject: ts.Identifier, propertyName: string) {\n return isValidIdentifier(propertyName)\n ? factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(propertyName))\n : factory.createElementAccessExpression(rootObject, factory.createStringLiteral(propertyName));\n}\n\nfunction generatePathExpression(\n path: string,\n pathParameters: QueryArgDefinition[],\n rootObject: ts.Identifier | ts.PropertyAccessExpression,\n isFlatArg: boolean,\n encodePathParams: boolean\n) {\n const expressions: Array<[string, string]> = [];\n\n const head = path.replace(/\\{(.*?)}(.*?)(?=\\{|$)/g, (_, expression, literal) => {\n const param = pathParameters.find((p) => p.originalName === expression);\n if (!param) {\n throw new Error(`path parameter ${expression} does not seem to be defined in '${path}'!`);\n }\n expressions.push([param.name, literal]);\n return '';\n });\n\n return expressions.length\n ? factory.createTemplateExpression(\n factory.createTemplateHead(head),\n expressions.map(([prop, literal], index) => {\n const value = isFlatArg \n ? rootObject \n : factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(prop));\n const encodedValue = encodePathParams\n ? factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [\n factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),\n ])\n : value;\n return factory.createTemplateSpan(\n encodedValue,\n index === expressions.length - 1\n ? factory.createTemplateTail(literal)\n : factory.createTemplateMiddle(literal)\n );\n })\n )\n : factory.createNoSubstitutionTemplateLiteral(head);\n}\n\ntype QueryArgDefinition = {\n name: string;\n originalName: string;\n type: ts.TypeNode;\n required?: boolean;\n param?: OpenAPIV3.ParameterObject;\n} & (\n | {\n origin: 'param';\n param: OpenAPIV3.ParameterObject;\n }\n | {\n origin: 'body';\n body: OpenAPIV3.RequestBodyObject;\n }\n);\ntype QueryArgDefinitions = Record<string, QueryArgDefinition>;\n","import ts from 'typescript';\nimport semver from 'semver';\n\nconst originalFactory = ts.factory;\n\nfunction createImportSpecifier(propertyName: ts.Identifier | undefined, name: ts.Identifier): ts.ImportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createImportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createImportSpecifier(propertyName, name);\n}\n\nfunction createExportSpecifier(\n propertyName: string | ts.Identifier | undefined,\n name: string | ts.Identifier\n): ts.ExportSpecifier {\n if (semver.satisfies(ts.version, '>= 4.5'))\n // @ts-ignore\n return originalFactory.createExportSpecifier(false, propertyName, name);\n // @ts-ignore\n return originalFactory.createExportSpecifier(propertyName, name);\n}\n\nexport const factory = {\n ...originalFactory,\n createImportSpecifier,\n createExportSpecifier,\n};\n","import { factory } from './utils/factory';\nimport ts from 'typescript';\n\nconst defaultEndpointBuilder = factory.createIdentifier('build');\n\nexport type ObjectPropertyDefinitions = Record<string, ts.Expression | undefined>;\nexport function generateObjectProperties(obj: ObjectPropertyDefinitions) {\n return Object.entries(obj)\n .filter(([_, v]) => v)\n .map(([k, v]) => factory.createPropertyAssignment(factory.createIdentifier(k), v as ts.Expression));\n}\n\nexport function generateImportNode(pkg: string, namedImports: Record<string, string>, defaultImportName?: string) {\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n defaultImportName !== undefined ? factory.createIdentifier(defaultImportName) : undefined,\n factory.createNamedImports(\n Object.entries(namedImports).map(([propertyName, name]) =>\n factory.createImportSpecifier(\n name === propertyName ? undefined : factory.createIdentifier(propertyName),\n factory.createIdentifier(name)\n )\n )\n )\n ),\n factory.createStringLiteral(pkg)\n );\n}\n\nexport function generateCreateApiCall({\n endpointBuilder = defaultEndpointBuilder,\n endpointDefinitions,\n tag,\n}: {\n endpointBuilder?: ts.Identifier;\n endpointDefinitions: ts.ObjectLiteralExpression;\n tag: boolean;\n}) {\n const injectEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n generateObjectProperties({\n endpoints: factory.createArrowFunction(\n undefined,\n undefined,\n [factory.createParameterDeclaration(undefined, undefined, endpointBuilder, undefined, undefined, undefined)],\n undefined,\n factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n factory.createParenthesizedExpression(endpointDefinitions)\n ),\n overrideExisting: factory.createFalse(),\n }),\n true\n );\n if (tag) {\n const enhanceEndpointsObjectLiteralExpression = factory.createObjectLiteralExpression(\n [factory.createShorthandPropertyAssignment(factory.createIdentifier('addTagTypes'), undefined)],\n true\n );\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('enhanceEndpoints')\n ),\n undefined,\n [enhanceEndpointsObjectLiteralExpression]\n ),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n }\n\n return factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('injectedRtkApi'),\n undefined,\n undefined,\n factory.createCallExpression(\n factory.createPropertyAccessExpression(\n factory.createIdentifier('api'),\n factory.createIdentifier('injectEndpoints')\n ),\n undefined,\n [injectEndpointsObjectLiteralExpression]\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n\nexport function generateEndpointDefinition({\n operationName,\n type,\n Response,\n QueryArg,\n queryFn,\n endpointBuilder = defaultEndpointBuilder,\n extraEndpointsProps,\n tags,\n}: {\n operationName: string;\n type: 'query' | 'mutation';\n Response: ts.TypeReferenceNode;\n QueryArg: ts.TypeReferenceNode;\n queryFn: ts.Expression;\n endpointBuilder?: ts.Identifier;\n extraEndpointsProps: ObjectPropertyDefinitions;\n tags: string[];\n}) {\n const objectProperties = generateObjectProperties({ query: queryFn, ...extraEndpointsProps });\n if (tags.length > 0) {\n objectProperties.push(\n factory.createPropertyAssignment(\n factory.createIdentifier(type === 'query' ? 'providesTags' : 'invalidatesTags'),\n factory.createArrayLiteralExpression(tags.map((tag) => factory.createStringLiteral(tag), false))\n )\n );\n }\n return factory.createPropertyAssignment(\n factory.createIdentifier(operationName),\n\n factory.createCallExpression(\n factory.createPropertyAccessExpression(endpointBuilder, factory.createIdentifier(type)),\n [Response, QueryArg],\n [factory.createObjectLiteralExpression(objectProperties, true)]\n )\n );\n}\n\nexport function generateTagTypes({ addTagTypes }: { addTagTypes: string[] }) {\n return factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier('addTagTypes'),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createArrayLiteralExpression(\n addTagTypes.map((tagType) => factory.createStringLiteral(tagType)),\n true\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined)\n )\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n}\n","import ts from 'typescript';\nimport { getOperationName } from 'oazapfts/generate';\nimport { capitalize, isQuery } from '../utils';\nimport type { OperationDefinition, EndpointOverrides, ConfigFile } from '../types';\nimport { getOverrides } from '../generate';\nimport { factory } from '../utils/factory';\n\ntype HooksConfigOptions = NonNullable<ConfigFile['hooks']>;\n\ntype GetReactHookNameParams = {\n operationDefinition: OperationDefinition;\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\n\ntype CreateBindingParams = {\n operationDefinition: OperationDefinition;\n overrides?: EndpointOverrides;\n isLazy?: boolean;\n};\n\nconst createBinding = ({\n operationDefinition: { verb, path, operation },\n overrides,\n isLazy = false,\n}: CreateBindingParams) =>\n factory.createBindingElement(\n undefined,\n undefined,\n factory.createIdentifier(\n `use${isLazy ? 'Lazy' : ''}${capitalize(getOperationName(verb, path, operation.operationId))}${\n isQuery(verb, overrides) ? 'Query' : 'Mutation'\n }`\n ),\n undefined\n );\n\nconst getReactHookName = ({ operationDefinition, endpointOverrides, config }: GetReactHookNameParams) => {\n const overrides = getOverrides(operationDefinition, endpointOverrides);\n\n const baseParams = {\n operationDefinition,\n overrides,\n };\n\n const _isQuery = isQuery(operationDefinition.verb, overrides);\n\n // If `config` is true, just generate everything\n if (typeof config === 'boolean') {\n return createBinding(baseParams);\n }\n\n // `config` is an object and we need to check for the configuration of each property\n if (_isQuery) {\n return [\n ...(config.queries ? [createBinding(baseParams)] : []),\n ...(config.lazyQueries ? [createBinding({ ...baseParams, isLazy: true })] : []),\n ];\n }\n\n return config.mutations ? createBinding(baseParams) : [];\n};\n\ntype GenerateReactHooksParams = {\n exportName: string;\n operationDefinitions: OperationDefinition[];\n endpointOverrides: EndpointOverrides[] | undefined;\n config: HooksConfigOptions;\n};\nexport const generateReactHooks = ({\n exportName,\n operationDefinitions,\n endpointOverrides,\n config,\n}: GenerateReactHooksParams) =>\n factory.createVariableStatement(\n [factory.createModifier(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createObjectBindingPattern(\n operationDefinitions\n .map((operationDefinition) => getReactHookName({ operationDefinition, endpointOverrides, config }))\n .flat()\n ),\n undefined,\n undefined,\n factory.createIdentifier(exportName)\n ),\n ],\n ts.NodeFlags.Const\n )\n );\n","export function capitalize(str: string) {\n return str.replace(str[0], str[0].toUpperCase());\n}\n","import type SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nexport type OperationDefinition = {\n path: string;\n verb: (typeof operationKeys)[number];\n pathItem: OpenAPIV3.PathItemObject;\n operation: OpenAPIV3.OperationObject;\n};\n\nexport type ParameterDefinition = OpenAPIV3.ParameterObject;\n\ntype Require<T, K extends keyof T> = { [k in K]-?: NonNullable<T[k]> } & Omit<T, K>;\ntype Optional<T, K extends keyof T> = { [k in K]?: NonNullable<T[k]> } & Omit<T, K>;\ntype Id<T> = { [K in keyof T]: T[K] } & {};\ntype AtLeastOneKey<T> = {\n [K in keyof T]-?: Pick<T, K> & Partial<T>;\n}[keyof T];\n\nexport const operationKeys = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;\n\nexport type GenerationOptions = Id<\n CommonOptions &\n Optional<OutputFileOptions, 'outputFile'> & {\n isDataResponse?(\n code: string,\n includeDefault: boolean,\n response: OpenAPIV3.ResponseObject,\n allResponses: OpenAPIV3.ResponsesObject\n ): boolean;\n }\n>;\n\nexport interface CommonOptions {\n apiFile: string;\n /**\n * filename or url\n */\n schemaFile: string;\n /**\n * defaults to \"api\"\n */\n apiImport?: string;\n /**\n * defaults to \"enhancedApi\"\n */\n exportName?: string;\n /**\n * defaults to \"ApiArg\"\n */\n argSuffix?: string;\n /**\n * defaults to \"ApiResponse\"\n */\n responseSuffix?: string;\n /**\n * defaults to empty\n */\n operationNameSuffix?: string;\n /**\n * defaults to `false`\n * `true` will generate hooks for queries and mutations, but no lazyQueries\n */\n hooks?: boolean | { queries: boolean; lazyQueries: boolean; mutations: boolean };\n /**\n * defaults to false\n * `true` will generate a union type for `undefined` properties like: `{ id?: string | undefined }` instead of `{ id?: string }`\n */\n unionUndefined?: boolean;\n /**\n * defaults to false\n * `true` will result in all generated endpoints having `providesTags`/`invalidatesTags` declarations for the `tags` of their respective operation definition\n * @see https://redux-toolkit.js.org/rtk-query/usage/code-generation for more information\n */\n tag?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated path parameters\n */\n encodePathParams?: boolean;\n /**\n * defaults to false\n * `true` will add `encodeURIComponent` to the generated query parameters\n */\n encodeQueryParams?: boolean;\n /**\n * defaults to false\n * `true` will \"flatten\" the arg so that you can do things like `useGetEntityById(1)` instead of `useGetEntityById({ entityId: 1 })`\n */\n flattenArg?: boolean;\n /**\n * default to false\n * If set to `true`, the default response type will be included in the generated code for all endpoints.\n * @see https://swagger.io/docs/specification/describing-responses/#default\n */\n includeDefault?: boolean;\n /**\n * default to false\n * `true` will not generate separate types for read-only and write-only properties.\n */\n mergeReadWriteOnly?: boolean;\n /**\n *\n * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.\n */\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions;\n\n /**\n * defaults to undefined\n * If present the given file will be used as prettier config when formatting the generated code. If undefined the default prettier config\n * resolution mechanism will be used.\n */\n prettierConfigFile?: string;\n}\n\nexport type TextMatcher = string | RegExp | (string | RegExp)[];\n\nexport type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;\n\nexport type EndpointMatcher = TextMatcher | EndpointMatcherFunction;\n\nexport type ParameterMatcherFunction = (parameterName: string, parameterDefinition: ParameterDefinition) => boolean;\n\nexport type ParameterMatcher = TextMatcher | ParameterMatcherFunction;\n\nexport interface OutputFileOptions extends Partial<CommonOptions> {\n outputFile: string;\n filterEndpoints?: EndpointMatcher;\n endpointOverrides?: EndpointOverrides[];\n /**\n * defaults to false\n * If passed as true it will generate TS enums instead of union of strings\n */\n useEnumType?: boolean;\n}\n\nexport type EndpointOverrides = {\n pattern: EndpointMatcher;\n} & AtLeastOneKey<{\n type: 'mutation' | 'query';\n parameterFilter: ParameterMatcher;\n}>;\n\nexport type ConfigFile =\n | Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>>\n | Id<\n Omit<CommonOptions, 'outputFile'> & {\n outputFiles: { [outputFile: string]: Omit<OutputFileOptions, 'outputFile'> };\n }\n >;\n","import type { OpenAPIV3 } from 'openapi-types';\nimport type { OperationDefinition } from '../types';\nimport { operationKeys } from '../types';\n\nexport function getOperationDefinitions(v3Doc: OpenAPIV3.Document): OperationDefinition[] {\n return Object.entries(v3Doc.paths).flatMap(([path, pathItem]) =>\n !pathItem\n ? []\n : Object.entries(pathItem)\n .filter((arg): arg is [(typeof operationKeys)[number], OpenAPIV3.OperationObject] =>\n operationKeys.includes(arg[0] as any)\n )\n .map(([verb, operation]) => ({\n path,\n verb,\n pathItem,\n operation,\n }))\n );\n}\n","import SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\n// @ts-ignore\nimport converter from 'swagger2openapi';\n\nexport async function getV3Doc(\n spec: string,\n httpResolverOptions?: SwaggerParser.HTTPResolverOptions\n): Promise<OpenAPIV3.Document> {\n const doc = await SwaggerParser.bundle(spec, {\n resolve: {\n http: httpResolverOptions,\n },\n });\n\n const isOpenApiV3 = 'openapi' in doc && doc.openapi.startsWith('3');\n\n if (isOpenApiV3) {\n return doc as OpenAPIV3.Document;\n } else {\n const result = await converter.convertObj(doc, {});\n return result.openapi as OpenAPIV3.Document;\n }\n}\n","import type { EndpointOverrides, operationKeys } from '../types';\n\nexport function isQuery(verb: (typeof operationKeys)[number], overrides: EndpointOverrides | undefined) {\n if (overrides?.type) {\n return overrides.type === 'query';\n }\n return verb === 'get';\n}\n","export function isValidUrl(string: string) {\n try {\n new URL(string);\n } catch (_) {\n return false;\n }\n\n return true;\n}\n","import path from 'node:path';\nimport prettier from 'prettier';\nimport type { BuiltInParserName } from 'prettier';\n\nconst EXTENSION_TO_PARSER: Record<string, BuiltInParserName> = {\n ts: 'typescript',\n tsx: 'typescript',\n js: 'babel',\n jsx: 'babel',\n 'js.flow': 'flow',\n flow: 'flow',\n gql: 'graphql',\n graphql: 'graphql',\n css: 'scss',\n scss: 'scss',\n less: 'scss',\n stylus: 'scss',\n markdown: 'markdown',\n md: 'markdown',\n json: 'json',\n};\n\nexport async function prettify(filePath: string | null, content: string, prettierConfigFile?: string): Promise<string> {\n let config = null;\n let parser = 'typescript';\n\n if (filePath) {\n const fileExtension = path.extname(filePath).slice(1);\n parser = EXTENSION_TO_PARSER[fileExtension];\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n editorconfig: !prettierConfigFile,\n config: prettierConfigFile,\n });\n } else if (prettierConfigFile) {\n config = await prettier.resolveConfig(process.cwd(), {\n useCache: true,\n config: prettierConfigFile,\n });\n }\n\n return prettier.format(content, {\n parser,\n ...config,\n });\n}\n","export function removeUndefined<T>(t: T | undefined): t is T {\n return typeof t !== 'undefined';\n}\n"],"mappings":";AAEA,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AAIhD,IAAM,aAA6B,4BAAY;;;ACRtD,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAC9B,OAAOA,WAAU;;;ACFjB,OAAO,eAAe;AACtB,OAAOC,WAAU;AACjB,OAAO;AAAA,EACL,oBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAOC,SAAQ;;;ACbf,OAAO,QAAQ;AACf,OAAO,YAAY;AAEnB,IAAM,kBAAkB,GAAG;AAE3B,SAAS,sBAAsB,cAAyC,MAAyC;AAC/G,MAAI,OAAO,UAAU,GAAG,SAAS,QAAQ;AAEvC,WAAO,gBAAgB,sBAAsB,OAAO,cAAc,IAAI;AAExE,SAAO,gBAAgB,sBAAsB,cAAc,IAAI;AACjE;AAEA,SAAS,sBACP,cACA,MACoB;AACpB,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,WAAkD,CAAC;AAEzD,MAAI,iBAAiB,YAAY;AAC/B,UAAM,EAAE,aAAa,GAAG,aAAa,IAAI;AACzC,eAAW,CAAC,YAAY,cAAc,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,eAAS,KAAK;AAAA,QACZ,GAAG;AAAA,QACH,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,OAAO;AACL,aAAS,KAAK,UAAU;AAAA,EAC1B;AACA,SAAO;AACT;AAMA,SAAS,yBAA4B,IAAgB;AACnD,QAAM,WAAWD,SAAQ,QAAQ,cAAc,EAAE,OAAO,CAACA,SAAQ,QAAQ,UAAU,CAAC,EAAE,CAAC;AACvF,QAAM,SAASA,SAAQ,QAAQ,YAAY;AAC3C,QAAM,gBAAgBA,SAAQ,MAAM,QAAQ;AAC5C,MAAI;AACF,IAAAA,SAAQ,MAAM,QAAQ,IAAIA,SAAQ,MAAM,MAAM;AAC9C,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,QAAI,eAAe;AACjB,MAAAA,SAAQ,MAAM,QAAQ,IAAI;AAAA,IAC5B,OAAO;AACL,aAAOA,SAAQ,MAAM,QAAQ;AAAA,IAC/B;AAAA,EACF;AACF;","names":["path","path","ts","ts","ts","path","path","ts","getOperationName","path","ts","operationDefinitions","tag","isQuery","encodePathParams","encodeQueryParams","path","require","path"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acrool/rtk-query-codegen-openapi",
|
|
3
|
-
"version": "0.0.2-test.
|
|
3
|
+
"version": "0.0.2-test.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"src"
|
|
47
47
|
],
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@acrool/react-fetcher": "^0.0.4",
|
|
49
50
|
"@babel/core": "^7.12.10",
|
|
50
51
|
"@babel/preset-env": "^7.12.11",
|
|
51
52
|
"@babel/preset-typescript": "^7.12.7",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@types/lodash.camelcase": "^4.3.9",
|
|
57
58
|
"@types/node": "^20.11.10",
|
|
58
59
|
"@types/semver": "^7.3.9",
|
|
60
|
+
"async-mutex": "^0.5.0",
|
|
59
61
|
"chalk": "^4.1.0",
|
|
60
62
|
"del": "^6.0.0",
|
|
61
63
|
"esbuild": "^0.25.1",
|
|
@@ -81,10 +83,5 @@
|
|
|
81
83
|
"semver": "^7.3.5",
|
|
82
84
|
"swagger2openapi": "^7.0.4",
|
|
83
85
|
"typescript": "^5.8.2"
|
|
84
|
-
},
|
|
85
|
-
"husky": {
|
|
86
|
-
"hooks": {
|
|
87
|
-
"pre-commit": "pretty-quick --staged"
|
|
88
|
-
}
|
|
89
86
|
}
|
|
90
87
|
}
|
package/src/bin/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { generateEndpoints, parseConfig } from '@rtk-query
|
|
3
|
+
import { generateEndpoints, parseConfig } from '@acrool/rtk-query-codegen-openapi';
|
|
4
4
|
import program from 'commander';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { dirname, resolve } from 'node:path';
|
package/src/generate.ts
CHANGED
|
@@ -168,6 +168,7 @@ export async function generateApi(
|
|
|
168
168
|
factory.createSourceFile(
|
|
169
169
|
[
|
|
170
170
|
generateImportNode(apiFile, { [apiImport]: 'api' }),
|
|
171
|
+
generateImportNode('@acrool/react-fetcher', { IRestFulEndpointsQueryReturn: 'IRestFulEndpointsQueryReturn' }),
|
|
171
172
|
...(tag ? [generateTagTypes({ addTagTypes: extractAllTagTypes({ operationDefinitions }) })] : []),
|
|
172
173
|
generateCreateApiCall({
|
|
173
174
|
tag,
|
|
@@ -288,9 +289,9 @@ export async function generateApi(
|
|
|
288
289
|
.resolveArray(pathItem.parameters)
|
|
289
290
|
.filter((pp) => !operationParameters.some((op) => op.name === pp.name && op.in === pp.in));
|
|
290
291
|
|
|
291
|
-
const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters])
|
|
292
|
-
argumentMatches(overrides?.parameterFilter)
|
|
293
|
-
|
|
292
|
+
const parameters = supportDeepObjects([...pathItemParameters, ...operationParameters])
|
|
293
|
+
.filter(argumentMatches(overrides?.parameterFilter))
|
|
294
|
+
.filter(param => param.in !== 'header');
|
|
294
295
|
|
|
295
296
|
const allNames = parameters.map((p) => p.name);
|
|
296
297
|
const queryArg: QueryArgDefinitions = {};
|
|
@@ -398,7 +399,10 @@ export async function generateApi(
|
|
|
398
399
|
operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,
|
|
399
400
|
type: isQuery ? 'query' : 'mutation',
|
|
400
401
|
Response: ResponseTypeName,
|
|
401
|
-
QueryArg
|
|
402
|
+
QueryArg: factory.createTypeReferenceNode(
|
|
403
|
+
factory.createIdentifier('IRestFulEndpointsQueryReturn'),
|
|
404
|
+
[QueryArg]
|
|
405
|
+
),
|
|
402
406
|
queryFn: generateQueryFn({
|
|
403
407
|
operationDefinition,
|
|
404
408
|
queryArg,
|
|
@@ -434,6 +438,7 @@ export async function generateApi(
|
|
|
434
438
|
const bodyParameter = Object.values(queryArg).find((def) => def.origin === 'body');
|
|
435
439
|
|
|
436
440
|
const rootObject = factory.createIdentifier('queryArg');
|
|
441
|
+
const variablesObject = factory.createPropertyAccessExpression(rootObject, factory.createIdentifier('variables'));
|
|
437
442
|
|
|
438
443
|
function pickParams(paramIn: string) {
|
|
439
444
|
return Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === paramIn);
|
|
@@ -443,7 +448,9 @@ export async function generateApi(
|
|
|
443
448
|
if (parameters.length === 0) return undefined;
|
|
444
449
|
|
|
445
450
|
const properties = parameters.map((param) => {
|
|
446
|
-
const value = isFlatArg
|
|
451
|
+
const value = isFlatArg
|
|
452
|
+
? variablesObject
|
|
453
|
+
: factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(param.name));
|
|
447
454
|
|
|
448
455
|
const encodedValue =
|
|
449
456
|
encodeQueryParams && param.param?.in === 'query'
|
|
@@ -470,9 +477,7 @@ export async function generateApi(
|
|
|
470
477
|
return factory.createArrowFunction(
|
|
471
478
|
undefined,
|
|
472
479
|
undefined,
|
|
473
|
-
|
|
474
|
-
? [factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)]
|
|
475
|
-
: [],
|
|
480
|
+
[factory.createParameterDeclaration(undefined, undefined, rootObject, undefined, undefined, undefined)],
|
|
476
481
|
undefined,
|
|
477
482
|
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
478
483
|
factory.createParenthesizedExpression(
|
|
@@ -480,7 +485,7 @@ export async function generateApi(
|
|
|
480
485
|
[
|
|
481
486
|
factory.createPropertyAssignment(
|
|
482
487
|
factory.createIdentifier('url'),
|
|
483
|
-
generatePathExpression(path, pickParams('path'),
|
|
488
|
+
generatePathExpression(path, pickParams('path'), variablesObject, isFlatArg, encodePathParams)
|
|
484
489
|
),
|
|
485
490
|
isQuery && verb.toUpperCase() === 'GET'
|
|
486
491
|
? undefined
|
|
@@ -493,12 +498,19 @@ export async function generateApi(
|
|
|
493
498
|
: factory.createPropertyAssignment(
|
|
494
499
|
factory.createIdentifier('body'),
|
|
495
500
|
isFlatArg
|
|
496
|
-
?
|
|
497
|
-
: factory.createPropertyAccessExpression(
|
|
501
|
+
? variablesObject
|
|
502
|
+
: factory.createPropertyAccessExpression(variablesObject, factory.createIdentifier(bodyParameter.name))
|
|
498
503
|
),
|
|
499
504
|
createObjectLiteralProperty(pickParams('cookie'), 'cookies'),
|
|
500
|
-
createObjectLiteralProperty(pickParams('header'), 'headers'),
|
|
501
505
|
createObjectLiteralProperty(pickParams('query'), 'params'),
|
|
506
|
+
factory.createPropertyAssignment(
|
|
507
|
+
factory.createIdentifier('fetchOptions'),
|
|
508
|
+
factory.createPropertyAccessChain(
|
|
509
|
+
rootObject,
|
|
510
|
+
factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
511
|
+
factory.createIdentifier('fetchOptions')
|
|
512
|
+
)
|
|
513
|
+
),
|
|
502
514
|
].filter(removeUndefined),
|
|
503
515
|
false
|
|
504
516
|
)
|
|
@@ -526,7 +538,7 @@ function accessProperty(rootObject: ts.Identifier, propertyName: string) {
|
|
|
526
538
|
function generatePathExpression(
|
|
527
539
|
path: string,
|
|
528
540
|
pathParameters: QueryArgDefinition[],
|
|
529
|
-
rootObject: ts.Identifier,
|
|
541
|
+
rootObject: ts.Identifier | ts.PropertyAccessExpression,
|
|
530
542
|
isFlatArg: boolean,
|
|
531
543
|
encodePathParams: boolean
|
|
532
544
|
) {
|
|
@@ -545,7 +557,9 @@ function generatePathExpression(
|
|
|
545
557
|
? factory.createTemplateExpression(
|
|
546
558
|
factory.createTemplateHead(head),
|
|
547
559
|
expressions.map(([prop, literal], index) => {
|
|
548
|
-
const value = isFlatArg
|
|
560
|
+
const value = isFlatArg
|
|
561
|
+
? rootObject
|
|
562
|
+
: factory.createPropertyAccessExpression(rootObject, factory.createIdentifier(prop));
|
|
549
563
|
const encodedValue = encodePathParams
|
|
550
564
|
? factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [
|
|
551
565
|
factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),
|