-
Notifications
You must be signed in to change notification settings - Fork 1
Fix duplicate enum/type alias exports in types-plugin #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Enum Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: Success | ||
| components: | ||
| schemas: | ||
| Status: | ||
| type: string | ||
| enum: | ||
| - active | ||
| - inactive | ||
| - pending | ||
| Priority: | ||
| type: string | ||
| enum: | ||
| - low | ||
| - medium | ||
| - high | ||
| Task: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: string | ||
| status: | ||
| $ref: '#/components/schemas/Status' | ||
| priority: | ||
| $ref: '#/components/schemas/Priority' | ||
| name: | ||
| type: string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ describe.concurrent("e2e", () => { | |
|
|
||
| const configFile = ` | ||
| import { experimental_openapiFetchPlugin } from "../../../src/plugins"; | ||
|
|
||
| export default { plugins: [experimental_openapiFetchPlugin()] }; | ||
| `; | ||
|
|
||
|
|
@@ -124,4 +124,46 @@ describe.concurrent("e2e", () => { | |
| }, | ||
| timeout | ||
| ); | ||
|
|
||
| test( | ||
| "enums.yaml / enum generation without duplicate type aliases", | ||
| async ({ expect, onTestFinished }) => { | ||
| const tempFolder = await createTemporaryFolder({ onTestFinished }); | ||
|
|
||
| const configFile = ` | ||
| export default { | ||
| openApiTsOptions: { | ||
| enum: true | ||
| } | ||
| }; | ||
| `; | ||
|
|
||
| await writeFile(join(tempFolder, "create-schemas.config.ts"), configFile); | ||
|
|
||
| const result = await runCompiledBin({ | ||
| source: join(dataFolder, "enums.yaml"), | ||
| outdir: join(tempFolder, "dist"), | ||
| cwd: tempFolder | ||
| }); | ||
|
|
||
| const typesFile = result.find(file => file.filename === openapiTypeScriptFilename); | ||
| assert(typesFile); | ||
|
|
||
| // Verify enums are generated | ||
| expect(typesFile.code).toContain("export enum Status"); | ||
| expect(typesFile.code).toContain("export enum Priority"); | ||
|
|
||
| // Verify NO duplicate type aliases for enums | ||
| const statusTypeAliasRegex = /export type Status = components\["schemas"\]\["Status"\];/; | ||
| const priorityTypeAliasRegex = /export type Priority = components\["schemas"\]\["Priority"\];/; | ||
| expect(typesFile.code).not.toMatch(statusTypeAliasRegex); | ||
| expect(typesFile.code).not.toMatch(priorityTypeAliasRegex); | ||
|
|
||
| // Verify non-enum types still get type aliases | ||
| expect(typesFile.code).toContain('export type Task = components["schemas"]["Task"];'); | ||
|
|
||
| expect(typesFile.code).toMatchSnapshot(); | ||
| }, | ||
| timeout | ||
| ); | ||
|
Comment on lines
+128
to
+168
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new enum filtering logic should have a unit test in
tests/plugins.test.tsto supplement the E2E test. Consider adding a test case that passes code with enum declarations totypesPluginand verifies that type aliases are only generated for non-enum schemas.Example test structure: