openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Support free-form objects
A free-form object (arbitrary property/value pairs) is defined as:
type: object
This is equivalent to
type: object additionalProperties: true
and
type: object additionalProperties: {}
https://swagger.io/docs/specification/data-models/data-types/
https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1154 might be resolved by the PR.
#1154 might be resolved by the PR.
This PR partially resolves #1154. It resolves the case where the object is completely free-form, but doesn't resolve the case where an object schema explicitly defines some properties, and also adds additionalProperties: true
. For example, the following is a valid schema:
Person:
type: object
properties:
name:
type: string
additionalProperties: true
This means the name
property must be of type string
, but other properties with arbitrary types are also allowed. This is equivalent to a Typescript type like:
export type Person = {
name?: string,
[key: string]: any
}
However the code in this PR will emit just:
export type Person = Record<string, any>;
This incorrectly allows the name
property to have any type.