-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
openapi-fetch version
0.17.0
Description
it is broken using both the latest openapi-typescript package and using the previous version without re-generating the types.
I always use --immutable=true and almost all JsonSchemas in my openapi have:
additionalProperties: false
readOnly: trueIn the latest 0.17.0 version, Arrays in the response bodies of openapi-fetch are iterable objects that remove methods for reading arrays, like .map.
'{ readonly [x: number]: string; readonly length: number; toString: {}; toLocaleString: {}; concat: {}; join: {}; slice: {}; indexOf: {}; lastIndexOf: {}; every: {}; some: {}; forEach: {}; ... 20 more ...; readonly [Symbol.unscopables]: { ...; }; }'
I can workaround this and get the old behavior before version 0.17.0, by putting this iterable object into Array.from, then typing it as readonly:
const openapiFetchArray = response.data.myArray; /* `Readable` object from openapi-typescript-helpers */
const desiredArray: readonly Item[] = Array.from(openapiFetchArray);Reproduction
this is reproduced on type-checking a project using openapi-fetch after updating to 0.17.0
To reproduce in the unittests of this repo:
-
Add
--immutable=truehere:"generate-types": "openapi-typescript -c test/redocly.yaml", -
add an array to the schemas in the tests (i.e. add an array as an attribute to either of these:
components: -
in packages/openapi-fetch, run
pnpm run generate-types -
then try to call a method like
.mapon that array, it will break inlint:ts. However, the test may successfully run, because it is a typescript error only.
Expected result
I think this should be opt-in. I do not have --read-write-markers anywhere, or made any other changes to the code.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)