You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Bug Report Checklist
Description
The
typescript-fetch
generator builds aModelToJSON
andModelToJSONTyped
method for each model type, for example:openapi-generator/samples/client/petstore/typescript-fetch/builds/default/models/User.ts
Lines 100 to 107 in 587fcff
In the example above,
UserToJSON
callsUserToJSONTyped
.UserToJSONTyped
’s signature is correct: it takes avalue: User? | null
, and returns anany
.UserToJSON
’s signature is incorrect: it takes the same arguments and returns the same values, but it is declared as taking ajson: any
(rather thanvalue: User? | null
) and returning aUser
.While in the simple case,
User
and the “JSONUser
” models are equivalent, this is not true if a field needs special handling when serialising or deserialising. For example, aDate
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:
openapi-generator/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache
Lines 44 to 46 in 587fcff
To:
And change this in a similar way, copying its
ToJSONTyped
method signature:openapi-generator/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache
Lines 111 to 113 in 587fcff
modelEnum
has the reverse issue:ToJSON
is correct, butToJSONTyped
has the wrong type information:openapi-generator/modules/openapi-generator/src/main/resources/typescript-fetch/modelEnum.mustache
Lines 22 to 28 in 587fcff
The text was updated successfully, but these errors were encountered: