hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
634 stars 44 forks source link

incorrect type generated when combining oneOf with properties #713

Open tannera-cargill opened 5 days ago

tannera-cargill commented 5 days ago

Description

This library is incorrectly generating TypeScript types for OpenAPI schemas that combine oneOf with properties. The generated type only includes the oneOf union, ignoring the additional properties defined in the schema.

OpenAPI specification (optional)

{
  "CompositionWithOneOfWithRefAndPropertiesFlat": {
    "type": "object",
    "oneOf": [
      {
        "$ref": "#/components/parameters/SimpleParameter"
      },
      {
        "$ref": "#/components/schemas/NonAsciiStringæøåÆØÅöôêÊ字符串"
      }
    ],
    "required": [
      "baz",
      "qux"
    ],
    "properties": {
      "baz": {
        "type": "integer",
        "format": "uint16",
        "minimum": 0.0,
        "nullable": true
      },
      "qux": {
        "type": "integer",
        "format": "uint8",
        "minimum": 0.0
      }
    }
  }
}

Expected behavior The generated TypeScript type should be an intersection of the oneOf union and an object type with the additional properties. Something like:

export type CompositionWithOneOfWithRefAndPropertiesFlat = 
  (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) 
  & {
    baz?: number;
    qux: number;
  };

Actual behavior

 export type CompositionWithOneOfWithRefAndPropertiesFlat = ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串;

Configuration

No response

System information (optional)

No response

mrlubos commented 5 days ago

Thanks for reporting @tannera-cargill