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
I'm generating a typescript-fetch client using OpenAPI Generator 4.0.0-beta. After running the generator, I notice that the resulting code attempts to coerce a dictionary to an array. According the documentation, a dictionary can be defined by specifying additionalProperties.
$ git clone https://gist.github.com/rzane/99f6106c72bead20faf39c8ad004c4d0 bug-report
$ cd bug-report
$ npm install
$ npm run generate
$ npm run test
You should see the following output:
> tsc -p src --noEmit
src/models/Example.ts:37:9 - error TS2322: Type 'ExampleItems[]' is not assignable to type '{ [key: string]: ExampleItems; }'.
Index signature is missing in type 'ExampleItems[]'.
37 'items': (json['items'] as Array<any>).map(ExampleItemsFromJSON),
~~~~~~~
src/models/Example.ts:32:5
32 items: { [key: string]: ExampleItems; };
~~~~~
The expected type comes from property 'items' which is declared here on type 'Example'
src/models/Example.ts:46:19 - error TS2352: Conversion of type '{ [key: string]: ExampleItems; }' to type 'any[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type '{ [key: string]: ExampleItems; }' is missing the following properties from type 'any[]': length, pop, push, concat, and 25 more.
46 'items': (value.items as Array<any>).map(ExampleItemsToJSON),
~~~~~~~~~~~~~~~~~~~~~~~~~
The source of the error can be found in src/models/Example.ts, which contains the following:
Change isContainer -> isListContainer for existing array support.
Add isMapContainer control flow, adding map support.
Add utility function to help map openapi map/dictionaries to ts maps.
CloseOpenAPITools#1878
Description
Description
I'm generating a
typescript-fetch
client using OpenAPI Generator 4.0.0-beta. After running the generator, I notice that the resulting code attempts to coerce a dictionary to an array. According the documentation, a dictionary can be defined by specifyingadditionalProperties
.openapi-generator version
4.0.0-beta
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
You should see the following output:
The source of the error can be found in src/models/Example.ts, which contains the following:
Related issues/PRs
I couldn't find one 🤷♂️
Suggest a fix
Add a
mapValues
function to theruntime.ts
file:Then, in the case of a dictionary, change the above implementation to:
The text was updated successfully, but these errors were encountered: