Skip to content

Commit e517a2e

Browse files
rajzikjan.silhan
andauthored
feat: Only generate utils if they don't exist (#288)
* feat: Only generate utils when they don't exists * run fix:prettier --------- Co-authored-by: jan.silhan <[email protected]>
1 parent d1976e0 commit e517a2e

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

plugins/typescript/CHANGELOG.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
## [10.0.0](https://github.com/fabien0102/openapi-codegen/compare/typescript-v9.2.0...typescript-v10.0.0) (2025-02-04)
44

5-
65
### ⚠ BREAKING CHANGES
76

8-
* deep merge variables with fetcherOptions from context. ([#284](https://github.com/fabien0102/openapi-codegen/issues/284))
9-
* Generated enum should be in pascal case ([#282](https://github.com/fabien0102/openapi-codegen/issues/282))
7+
- deep merge variables with fetcherOptions from context. ([#284](https://github.com/fabien0102/openapi-codegen/issues/284))
8+
- Generated enum should be in pascal case ([#282](https://github.com/fabien0102/openapi-codegen/issues/282))
109

1110
### Features
1211

13-
* Adding constant handling ([#220](https://github.com/fabien0102/openapi-codegen/issues/220)) ([8944be4](https://github.com/fabien0102/openapi-codegen/commit/8944be44a36a3100cf2ac9f683d245b59a3f954e))
14-
12+
- Adding constant handling ([#220](https://github.com/fabien0102/openapi-codegen/issues/220)) ([8944be4](https://github.com/fabien0102/openapi-codegen/commit/8944be44a36a3100cf2ac9f683d245b59a3f954e))
1513

1614
### Bug Fixes
1715

18-
* deep merge variables with fetcherOptions from context. ([#284](https://github.com/fabien0102/openapi-codegen/issues/284)) ([2678ea4](https://github.com/fabien0102/openapi-codegen/commit/2678ea407a64cd373adddd868a969b2e3bcc586a))
19-
* Escape special chars in enum name ([#283](https://github.com/fabien0102/openapi-codegen/issues/283)) ([3392588](https://github.com/fabien0102/openapi-codegen/commit/33925883600418bbdfff65437ce4a1b796766b12))
20-
* Fixed fetcher template to compile when noUncheckedIndexedAccess ts compile option is set ([#228](https://github.com/fabien0102/openapi-codegen/issues/228)) ([ecf90cd](https://github.com/fabien0102/openapi-codegen/commit/ecf90cd247e4133a13557ab83fed3ced1a9460d5))
21-
* Generated enum should be in pascal case ([#282](https://github.com/fabien0102/openapi-codegen/issues/282)) ([e16bc82](https://github.com/fabien0102/openapi-codegen/commit/e16bc826a580aaae2f7b29fbb31fe53a7d6a6f57))
22-
* Invalid variable access inside fetcher ([#277](https://github.com/fabien0102/openapi-codegen/issues/277)) ([ea21f34](https://github.com/fabien0102/openapi-codegen/commit/ea21f34552c47a10151e0536fb2c521d687924c1))
16+
- deep merge variables with fetcherOptions from context. ([#284](https://github.com/fabien0102/openapi-codegen/issues/284)) ([2678ea4](https://github.com/fabien0102/openapi-codegen/commit/2678ea407a64cd373adddd868a969b2e3bcc586a))
17+
- Escape special chars in enum name ([#283](https://github.com/fabien0102/openapi-codegen/issues/283)) ([3392588](https://github.com/fabien0102/openapi-codegen/commit/33925883600418bbdfff65437ce4a1b796766b12))
18+
- Fixed fetcher template to compile when noUncheckedIndexedAccess ts compile option is set ([#228](https://github.com/fabien0102/openapi-codegen/issues/228)) ([ecf90cd](https://github.com/fabien0102/openapi-codegen/commit/ecf90cd247e4133a13557ab83fed3ced1a9460d5))
19+
- Generated enum should be in pascal case ([#282](https://github.com/fabien0102/openapi-codegen/issues/282)) ([e16bc82](https://github.com/fabien0102/openapi-codegen/commit/e16bc826a580aaae2f7b29fbb31fe53a7d6a6f57))
20+
- Invalid variable access inside fetcher ([#277](https://github.com/fabien0102/openapi-codegen/issues/277)) ([ea21f34](https://github.com/fabien0102/openapi-codegen/commit/ea21f34552c47a10151e0536fb2c521d687924c1))
2321

2422
## [9.2.0](https://github.com/fabien0102/openapi-codegen/compare/typescript-v9.1.0...typescript-v9.2.0) (2025-01-31)
2523

plugins/typescript/src/generators/generateFetchers.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ describe("generateFetchers", () => {
7272
config
7373
);
7474

75-
expect(writeFile.mock.calls[1][0]).toBe("petstoreComponents.ts");
76-
expect(writeFile.mock.calls[1][1]).toMatchInlineSnapshot(`
75+
expect(writeFile.mock.calls[0][0]).toBe("petstoreComponents.ts");
76+
expect(writeFile.mock.calls[0][1]).toMatchInlineSnapshot(`
7777
"/**
7878
* Generated by @openapi-codegen
7979
*
@@ -124,8 +124,8 @@ describe("generateFetchers", () => {
124124
{ ...config, filenamePrefix: "" }
125125
);
126126

127-
expect(writeFile.mock.calls[1][0]).toBe("components.ts");
128-
expect(writeFile.mock.calls[1][1]).toMatchInlineSnapshot(`
127+
expect(writeFile.mock.calls[0][0]).toBe("components.ts");
128+
expect(writeFile.mock.calls[0][1]).toMatchInlineSnapshot(`
129129
"/**
130130
* Generated by @openapi-codegen
131131
*
@@ -183,8 +183,8 @@ describe("generateFetchers", () => {
183183
config
184184
);
185185

186-
expect(writeFile.mock.calls[1][0]).toBe("petstoreComponents.ts");
187-
expect(writeFile.mock.calls[1][1]).toMatchInlineSnapshot(`
186+
expect(writeFile.mock.calls[0][0]).toBe("petstoreComponents.ts");
187+
expect(writeFile.mock.calls[0][1]).toMatchInlineSnapshot(`
188188
"/**
189189
* Generated by @openapi-codegen
190190
*
@@ -244,8 +244,8 @@ describe("generateFetchers", () => {
244244
config
245245
);
246246

247-
expect(writeFile.mock.calls[1][0]).toBe("petstoreComponents.ts");
248-
expect(writeFile.mock.calls[1][1]).toMatchInlineSnapshot(`
247+
expect(writeFile.mock.calls[0][0]).toBe("petstoreComponents.ts");
248+
expect(writeFile.mock.calls[0][1]).toMatchInlineSnapshot(`
249249
"/**
250250
* Generated by @openapi-codegen
251251
*

plugins/typescript/src/generators/generateFetchers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ export const generateFetchers = async (context: Context, config: Config) => {
225225
}
226226
);
227227

228-
if (usedImportsKeys.includes("utils")) {
228+
if (
229+
!context.existsFile(`${utilsFilename}.ts`) &&
230+
usedImportsKeys.includes("utils")
231+
) {
229232
await context.writeFile(`${utilsFilename}.ts`, getUtils());
230233
}
231234

0 commit comments

Comments
 (0)