Skip to content
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

Inline properties in AllOf that is not a ref #1628

Open
StefanBRas opened this issue Sep 16, 2024 · 4 comments
Open

Inline properties in AllOf that is not a ref #1628

StefanBRas opened this issue Sep 16, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@StefanBRas
Copy link

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 
@melloware melloware added the enhancement New feature or request label Sep 16, 2024
@soartec-lab
Copy link
Member

The current format has the advantage that you can import just one type at a time, like this:

import { UserWithNameAllOf } from '..user.ts'.

@melloware
Copy link
Collaborator

@soartec-lab good point. I would lean towards "won't fix"

@StefanBRas
Copy link
Author

StefanBRas commented Sep 17, 2024

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?

@melloware
Copy link
Collaborator

Yes PR is welcome @StefanBRas !

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

No branches or pull requests

3 participants