orval
orval copied to clipboard
Inline properties in `AllOf` that is not a ref
What are the steps to reproduce this issue?
Given the spec
openapi: 3.0.3
info:
title: test
version: 0.1.0
paths: {}
components:
schemas:
User:
type: object
properties:
id:
type: string
UserWithName:
allOf:
- $ref: '#/components/schemas/User'
- type: object
properties:
name:
type: string
I get
// user.ts
export interface User {
id?: string;
}
// userWithNameAllOf.ts
export type UserWithNameAllOf = {
name?: string;
};
// userWithName.ts
import type { User } from './user';
import type { UserWithNameAllOf } from './userWithNameAllOf';
export type UserWithName = User & UserWithNameAllOf;
Which is correctly, by the AllOf is kinda redundant.
What were you expecting to happen?
// user.ts
export interface User {
id?: string;
}
export type UserWithNameAllOf =
// userWithName.ts
import type { User } from './user';
export type UserWithName = User & {name?: string};
Which is equivalent, but nicer. …
Any logs, error output, etc?
…
Any other comments?
I can see that some people might want to have it as a separate type, but the names quickly become long and ugly.
Maybe it should be a configuration option?
What versions are you using?
System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Max
Memory: 69.92 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
npmPackages:
@tanstack/react-query: ^4.22.0 => 4.36.1
axios: ^1.7.4 => 1.7.7
orval: 7.1.0 => 7.1.0
The current format has the advantage that you can import just one type at a time, like this:
import { UserWithNameAllOf } from '..user.ts'.
@soartec-lab good point. I would lean towards "won't fix"
You can say Omit<UserWithName, keyof User> to get that type instead, which I also think is nicer because it clearly shows that I want all fields in UserWithName that isn't in User whereas the name UserWithNameAllOf doesn't carry any information.
In our project, we have around 30 of these AllOf and all of them are a single discriminator field that gets its own AllOf type which is just noise here.
Wold you accept a PR with a configuration for it?
Yes PR is welcome @StefanBRas !
@StefanBRas have you started on this? Otherwise I'm interested in picking it up in the future
@matthewaptaylor go ahead
Hey! Ah sorry, I started but then got kinda stuck on the testing setup. I should probably have reported back. Feel free to pick it up