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: true
In 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=true here:
|
"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:
-
in packages/openapi-fetch, run pnpm run generate-types
-
then try to call a method like .map on that array, it will break in lint: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
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=trueand almost all JsonSchemas in my openapi have:In 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.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: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:openapi-typescript/packages/openapi-fetch/package.json
Line 49 in f3a3a19
add an array to the schemas in the tests (i.e. add an array as an attribute to either of these:
openapi-typescript/packages/openapi-fetch/test/http-methods/schemas/get.yaml
Line 46 in f3a3a19
in packages/openapi-fetch, run
pnpm run generate-typesthen 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-markersanywhere, or made any other changes to the code.Extra