Skip to content

Generates & { property: unknown; } with allOf union #958

Closed
@essential-randomness

Description

@essential-randomness

Hi,
I've created the following test file:

components:
  schemas:
    BoardSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        slug:
          type: string
        avatar_url:
          type: string
          format: uri-reference
      required:
        - id
        - slug
        - avatar_url
    LoggedInBoardSummary:
      allOf:
        - $ref: "#/components/schemas/BoardSummary"
        - type: object
          properties:
            muted:
              type: boolean
            pinned:
              type: boolean
      required:
        - muted
        - pinned

and it results in the following components generation, which seems correct to me, except for the fact that it results in an additional union with "unknown" types:

export interface components {
  schemas: {
    BoardSummary: {
      /** Format: uuid */
      id: string;
      slug: string;
      /** Format: uri-reference */
      avatar_url: string;
    };
    LoggedInBoardSummary: components["schemas"]["BoardSummary"] & {
      muted?: boolean;
      pinned?: boolean;
    } & { // <-- why is this here?
      muted: unknown;
      pinned: unknown;
    };
  };
}

I assume that muted and pinned not being in the original schema results in the extra union.

I've tried cloning the repo and generating the types with up-to-date code as I heard there's some 3.1 improvements coming, but it seems to result in the same issue. I've also tried playing around with unevaluatedProperties: false, but got the same result.

Is this a bug in the library, or do I have some incorrect assumptions? I may be willing to give a shot at fixing it, but don't know where to start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs welcomePRs are welcome to solve this issue!bugSomething isn't workingplannedExpected in an upcoming version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions