Skip to content

Conversation

@superxiao
Copy link
Contributor

@superxiao superxiao commented Dec 16, 2025

Breaking change: Inlines combined types by default, cleaning up generated types by removing unnecessary intermediate type aliases.

Helps with #1644 - eliminates verbose names like ListOfActivitiesResponseAnyOfDataAnyOfItem....

// orval.config.ts - to restore old behavior
output: {
  override: {
    useCombinedTypeAliases: true,
  },
},

Estimated impact on a real project:

Metric Before After Change
Types 1,549 ~252 -84%
Lines 7,156 ~5,859 -18%

Fewer intermediate types means better readability and potentially faster type inference.

The change handles two cases:

1. Intermediate object types - things like ResponseAnyOf, ResponseOneOfTwo go away:

// before
export type Response401OneOf = { defined: true; ... };
export type Response401OneOfTwo = { defined: false; ... };
export type Response401 = Response401OneOf | Response401OneOfTwo;

// after
export type Response401 = { defined: true; ... } | { defined: false; ... };

2. Primitive union properties - explicit anyOf/oneOf with primitives get inlined:

// before (anyOf: [{type: string}, {type: number}])
export type MyObjectField = string | number;
export interface MyObject {
  field?: MyObjectField;
}

// after
export interface MyObject {
  field?: string | number;
}

Set useCombinedTypeAliases: true to restore the old behavior of creating intermediate type aliases.

Property-level inline objects still get named types (complex types benefit from a name anyway):

// anyOf with inline objects at property level - still creates named type
export type MyObjectResult = { data?: string } | { error?: string };
export interface MyObject {
  result?: MyObjectResult;
}

…on types

When enabled, combined types (anyOf/oneOf/allOf) are inlined instead of
creating intermediate type aliases like ResponseAnyOf, MyObjectField.

- Add inlineCombinedTypes option (default: false for backward compatibility)
- Skip intermediate propName generation in combineSchemas when enabled
- Use conditional regex in resolveObject to only match '{' when enabled
@superxiao
Copy link
Contributor Author

As the real world example in the PR description shows, such an option could cut down some excessive single-use types for a project I'm working on (where the generated file is still growing fast). Let me know if you think this is a good idea or not.

@melloware
Copy link
Collaborator

@anymaniax @soartec-lab what do you think? I am all for less generated code...

@soartec-lab
Copy link
Member

@superxiao @melloware
I agree with this. I don't find many cases where I want to refer to polymorphic types, so it might be a good idea to make this behavior the default and separate types optional. If that's the case, V8 is the right time.

@melloware
Copy link
Collaborator

agreed this should be the default.

@melloware melloware added the enhancement New feature or request label Dec 17, 2025
@melloware melloware added this to the 8.0.0 milestone Dec 17, 2025
@melloware
Copy link
Collaborator

@superxiao can you make this the default true and make them opt out of it with false

- Rename flag from inlineCombinedTypes to useCombinedTypeAliases
- Default to false (inline by default, opt-in to create aliases)
- Simplify logic: if (useCombinedTypeAliases) instead of === false check
- Update tests to verify default behavior with unmodified context
@superxiao superxiao changed the title add inlineCombinedTypes option to reduce intermediate type aliases inline combined types by default, add useCombinedTypeAliases opt-out Dec 17, 2025
@superxiao
Copy link
Contributor Author

superxiao commented Dec 17, 2025

PR has been updated to make the inlining default behavior. New option is renamed from inlineCombinedTypes to useCombinedTypeAliases - false and undefined is the default.

@melloware melloware linked an issue Dec 17, 2025 that may be closed by this pull request
@melloware
Copy link
Collaborator

This is fantastic!

@melloware melloware merged commit 9f649d6 into orval-labs:master Dec 17, 2025
2 checks passed
@soartec-lab
Copy link
Member

@superxiao
Thanks for great improvement. Could you also make a PR to document it?

@superxiao
Copy link
Contributor Author

#2657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orval overuses AnyOf types delimiter

3 participants