Skip to content

properties + anyOf generates incorrect output #567

Open
@gborobio73

Description

@gborobio73

Given this schema:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string"
    },
    "validFrom": {
      "type": "string"
    },
    "validTo": {
      "type": "string"
    }
  },
  "anyOf": [
    {
      "required": ["id", "validFrom"]
    },
    {
      "required": ["id", "validTo"]
    }
  ],
  "title": "Assortment"
}

This is the type generated:

export type Assortment = Assortment1 & Assortment2;
export type Assortment1 = {
  [k: string]: unknown;
};

export interface Assortment2 {
  id?: string;
  validFrom?: string;
  validTo?: string;
}

And I was hoping it would generate something like this:

export type Assortment =
  | {
      id: string;
      validFrom: string;
      validTo?: string;
    }
  | {
      id: string;
      validFrom?: string;
      validTo: string;
    };

I might be doing something wrong, so my apologies in advance.

Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions