openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Support `additionalProperties: true`
In OpenAPI 3, a schema like:
AnyValues:
description: An object whose property values can be of any type
type: object
additionalProperties: true
Should be equivalent to a typescript type like:
type AnyValues = {
[key: string]: any
};
However what openapi-typescript-codegen actually generates is a type like this:
type AnyValues = {
};
That is, an object with no properties.
Additionally, OpenAPI allows combining additionalProperties: true
with explicit property definitions. So an OpenAPI schema like this:
SomeType:
type: object
required: [name]
properties:
name:
type: string
additionalProperties: true
Should result in a typescript type like:
type SomeType = {
name: string,
[key: string]: any
};
but in fact it results in:
type SomeType = {
name: string
};
Desired result: additionalProperties: true
in an object schema should result in a [key: string]: any
property in the corresponding typescript type.
This is seems to be related to this one: #1066
This is seems to be related to this one: #1066
That issue is different. In that case, the problem is that the spec doesn't specify a type for the schemas. That is, it has types defined like
schemas:
Account:
properties:
balance:
type: string
description: balance in unit WEI, presented with hex string
example: '0x47ff1f90327aa0f8e'
energy:
type: string
description: energy in uint WEI, presented with hex string
example: '0xcf624158d591398'
hasCode:
type: boolean
description: whether the account has code
example: false
Simply adding type: object
to the type fixes the problem. I'm not sure if the type
field is supposed to be optional, but in any case it's a different problem.
Hey @ajenkins-cargometrics, if this is still relevant, we got this feature in our fork that is kept in sync with this repository, would love you to give it a try