Skip to content

Readable in new openapi-typescript-helpers is broken #2615

@evrom

Description

@evrom

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:

  1. Add --immutable=true here:

    "generate-types": "openapi-typescript -c test/redocly.yaml",

  2. add an array to the schemas in the tests (i.e. add an array as an attribute to either of these:

  3. in packages/openapi-fetch, run pnpm run generate-types

  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions