Bug Report Checklist
Description
In an openapi.yml file we have schemas that are arrays of other schemas. If we set the option generateAliasAsModel to true, the typescript-fetch generator's generated output no longer maps the array's items, as it does with any other JSON, but just returns the raw JSON. This is a problem especially if the JSON contains date string values that should be mapped to a Date object in TypeScript.
openapi-generator version
I tried it with 7.1.0 and 7.2.0, and also with the latest master (at this time) of this repository.
OpenAPI declaration file content or url
I uploaded an openapi.yml to PasteBin https://pastebin.com/etjz4Uhs
Generation Details
openapi-generator-cli generate -i ./openapi.yml -o ./sdk/src -g typescript-fetch --additional-properties=disallowAdditionalPropertiesIfNotPresent=false --additional-properties=supportsES6=true --additional-properties=generateAliasAsModel=true
Steps to reproduce
Execute the generator command from above. The generated file sdk/src/models/CarList.ts contains this code:
export function CarListFromJSONTyped(json: any, ignoreDiscriminator: boolean): CarList {
return json;
}
This function should not return the JSON as-is, but should call the function CarListItemFromJSON() from CarListItem.ts for every item of the array.
If you remove the generateAliasAsModel option from the generate command, the getCarsRaw() function from DefaultApi.ts does this itself.
Related issues/PRs
I didn't find any related Issue or PR for this.
Suggest a fix
I think the bug is in the file modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache.
Lines 100 to 102 contain this code:
{{^hasVars}}
return json;
{{/hasVars}}
As far as I understand this code, it is correct that the generator enters the not hasVars case. But inside this case, there should be another check if the content of the JSON is an array and if that array contains only primitive values (string, number, bool) or other objects. In the case of objects the generated code should call the specific mapper for the specific type.
Bug Report Checklist
Description
In an openapi.yml file we have schemas that are arrays of other schemas. If we set the option
generateAliasAsModeltotrue, thetypescript-fetchgenerator's generated output no longer maps the array's items, as it does with any other JSON, but just returns the raw JSON. This is a problem especially if the JSON contains date string values that should be mapped to aDateobject in TypeScript.openapi-generator version
I tried it with 7.1.0 and 7.2.0, and also with the latest master (at this time) of this repository.
OpenAPI declaration file content or url
I uploaded an openapi.yml to PasteBin https://pastebin.com/etjz4Uhs
Generation Details
Steps to reproduce
Execute the generator command from above. The generated file
sdk/src/models/CarList.tscontains this code:This function should not return the JSON as-is, but should call the function
CarListItemFromJSON()fromCarListItem.tsfor every item of the array.If you remove the
generateAliasAsModeloption from the generate command, thegetCarsRaw()function fromDefaultApi.tsdoes this itself.Related issues/PRs
I didn't find any related Issue or PR for this.
Suggest a fix
I think the bug is in the file
modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache.Lines 100 to 102 contain this code:
As far as I understand this code, it is correct that the generator enters the
not hasVarscase. But inside this case, there should be another check if the content of the JSON is an array and if that array contains only primitive values (string, number, bool) or other objects. In the case of objects the generated code should call the specific mapper for the specific type.