fern-api / fern

Input OpenAPI. Output SDKs and Docs.
https://buildwithfern.com
Apache License 2.0
2.69k stars 152 forks source link

[Bug] Open API importer disregards `anyOf` and picks one of the values #4327

Open krassowski opened 3 months ago

krassowski commented 3 months ago

Describe the bug

When generating from Open API with anyOf we got Python SDK like name_or_index: Optional[str] which then switched to name_or_index: Optional[int] in a subsequent update. It should be name_or_index: Optional[Union[str, int]].

I think this is not a problem in Python SDK generator but in OpenAPI importer because the REST API docs page also shows:

image

To reproduce

{
  "required": false,
  "schema": {
    "title": "Name or Index",
    "anyOf": [
      {
        "type": "integer"
      },
      {
        "type": "string"
      }
    ],
    "default": 0
  },
  "name": "name_or_index",
  "in": "query"
},

Expected behavior

We get union of integer and string in SDKs and in the docs.

Of note, somewhat works fine for an array of items:

{
  "required": false,
  "schema": {
    "title": "Columns",
    "type": "array",
    "items": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "string"
        }
      ]
    },
    "description": "should be a list of strings or a list of integers"
  },
  "name": "columns",
  "in": "query"
},

image

But it is also wrong because it should show list of unions, not a union.

Yet in the response object where columns are required it does work correctly:

"columns": {
  "title": "Columns",
  "type": "array",
  "items": {
    "anyOf": [
      {
        "type": "string"
      },
      {
        "type": "integer"
      },
      {
        "type": "number"
      }
    ]
  }
},

image

Screenshots

See above

CLI Version

0.39.1

Additional context

None

krassowski commented 3 months ago

I also see this in the docs generated with CLI v0.39.6.