Skip to content

Conversation

@webjunkie
Copy link
Contributor

Fixes #1511

I ran into this when using orval with a Django REST Framework OpenAPI spec. The generated TypeScript wouldn't compile because enums were declared in the wrong order:

export const Combined = { ...BlankEnum } // TS error: used before declaration
// ... hundreds of lines later ...
export const BlankEnum = { '': '' }

The issue is that schemas get output in alphabetical order, but combined enums using spread syntax need their dependencies declared first.

I added dependency tracking through the resolvers and a topological sort before output. Added a test that reproduces the original issue.

@melloware melloware force-pushed the fix/enum-declaration-order branch from c00bf22 to b16898d Compare December 1, 2025 12:29
@melloware
Copy link
Collaborator

you might have to run yarn update-samples script.

@melloware melloware force-pushed the fix/enum-declaration-order branch from b16898d to 8412dcc Compare December 1, 2025 12:53
@webjunkie
Copy link
Contributor Author

Ah, thanks! It said unchanged previously, but that is nonsense. Had to clean caches to get it updated.

@melloware
Copy link
Collaborator

ok now yarn format :)

@melloware melloware marked this pull request as ready for review December 1, 2025 14:03
Schemas/enums were output in alphabetical order, causing TS errors
when a combined enum spread referenced another declared later:

  export const Combined = { ...BlankEnum } // error: used before declaration
  export const BlankEnum = { '': '' }

Track dependencies through resolvers and sort before output.

Fixes orval-labs#1511
@melloware melloware force-pushed the fix/enum-declaration-order branch from 42746e9 to 2e0bc10 Compare December 1, 2025 14:07
Copilot AI review requested due to automatic review settings December 1, 2025 14:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@melloware melloware marked this pull request as draft December 1, 2025 14:08
@melloware melloware marked this pull request as ready for review December 1, 2025 14:15
@melloware melloware merged commit 5602581 into orval-labs:master Dec 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orval generates some enums that are used before they are declared

2 participants