Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added TemporaryTest/store.ts
Empty file.
15 changes: 14 additions & 1 deletion packages/rtk-query-codegen-openapi/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export async function generateApi(
useEnumType = false,
mergeReadWriteOnly = false,
httpResolverOptions,
ESMExtensions = false
}: GenerationOptions
) {
const v3Doc = (v3DocCache[spec] ??= await getV3Doc(spec, httpResolverOptions));
Expand Down Expand Up @@ -161,7 +162,19 @@ export async function generateApi(
if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;
}
}
apiFile = apiFile.replace(/\.[jt]sx?$/, '');

if(ESMExtensions === true){
apiFile = apiFile.replace(/\.js$|\.ts$|\.mjs$|\.mts$|\.jsx$|\.tsx$/, (extension) => {
if (extension ==='.js') return '.js';
if (extension ==='.ts') return '.js';
if (extension ==='.mjs') return '.mjs';
if (extension ==='.mts') return '.mjs';
if (extension ==='.jsx') return '.jsx';
if (extension ==='.tsx') return '.jsx';
return apiFile;
});
};
if(!ESMExtensions || ESMExtensions === false){apiFile = apiFile.replace(/\.[jt]sx?$/, '');};

return printer.printNode(
ts.EmitHint.Unspecified,
Expand Down
5 changes: 5 additions & 0 deletions packages/rtk-query-codegen-openapi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export interface CommonOptions {
* resolution mechanism will be used.
*/
prettierConfigFile?: string;
/**
* default to false
* Will generate imports with file extension matching the expected compiled output of the api file
*/
ESMExtensions?:boolean;
}

export type TextMatcher = string | RegExp | (string | RegExp)[];
Expand Down
Loading