Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The typescript-fetch
generator builds a ModelToJSON
and ModelToJSONTyped
method for each model type, for example:
In the example above, UserToJSON
calls UserToJSONTyped
.
UserToJSONTyped
’s signature is correct: it takes a value: User? | null
, and returns an any
.
UserToJSON
’s signature is incorrect: it takes the same arguments and returns the same values, but it is declared as taking a json: any
(rather than value: User? | null
) and returning a User
.
While in the simple case, User
and the “JSON User
” models are equivalent, this is not true if a field needs special handling when serialising or deserialising. For example, a Date
field expressed as an ISO 7816 timestamp (string
) or integer timestamp in JSON.
openapi-generator version
Current HEAD (587fcff)
OpenAPI declaration file content or url
Petstore example in openapi-generator repository
Generation Details
Visible in all of the example typescript-fetch
builds in the openapi-generator repository.
Steps to reproduce
As above
Related issues/PRs
This regression seems like it was introduced in #19524
Suggest a fix
Change this:
To:
export function {{classname}}ToJSON(value?: {{classname}} | null ): any {
return {{classname}}ToJSONTyped(value, false);
}
And change this in a similar way, copying its ToJSONTyped
method signature:
modelEnum
has the reverse issue: ToJSON
is correct, but ToJSONTyped
has the wrong type information: