Generate typescript-fetch API from anyOf

39 views Asked by At

Here is the schema:

// metric.json
{
  "openapi": "3.0.2",
  "info": { "title": "FastAPI", "version": "0.1.0" },
  "paths": {},
  "components": {
    "schemas": {
      "Metric": {
        "title": "Metric",
        "required": ["value"],
        "type": "object",
        "properties": {
          "value": {
            "title": "Value",
            "anyOf": [
              { "type": "array", "items": { "type": "number" } },
              { "type": "number" }
            ]
          }
        }
      }
    }
  }
}

And to generate the API:

$ npx openapi-generator-cli version
7.4.0
$ npx openapi-generator-cli generate -g typescript-fetch -o api -i ./metric.json

Then in the generated API, we can see that value is of type Value, which is an empty interface:

// api/models/Metric.ts
export interface Metric {
    /**
     * 
     * @type {Value}
     * @memberof Metric
     */
    value: Value;
}

// api/models/Value.ts
export interface Value {
}

Can we have a union type in the generated API?

0

There are 0 answers