Skip to content

[TypeScript] Add support for nested arrays (array of string arrays) #4549

Closed

Description

Hey there. Running into an issue with the generated client. I have a schema where one of the properties is an array of string arrays. It is returned in an API response and it looks like the following:

      "Foo": {
        "type": "object",
        "properties": {
          "sortBy": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },

When I make an API call using the generated client, I get this error:

Error: encountered an unknown type during deserialization object

The stacktrace points to the generated models. When I inspect the generated model, I see that the a few things are off.

The code fails during deserialization in this function. Looks like the wrong function is invoked getCollectionOfPrimitiveValues

export function deserializeIntoFoo(foo: Partial<Foo> | undefined = {}) : Record<string, (node: ParseNode) => void> {
    return {
        "sortBy": n => { foo.sortBy = n.getCollectionOfPrimitiveValues<string>(); },
    }
}

The schema is typed incorrectly. It should be string[][]

export interface Foo extends Parsable {
    /**
     * The sortBy property
     */
    sortBy?: string[];
}

Also I changed the OpenAPI spec a few different ways and here are my findings.

  1. Untyped the nested array. Same error. The property is typed as UntypedNode[]
  2. Changed the nested array to object type. No error, but in the response the array value is parsed as an object { "0": "updatedAt", "1": "DESC" }
  3. Removed properties from Foo. No error, but Foo is no longer typed correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

generatorIssues or improvements relater to generation capabilities.type:bugA broken experience

Type

No type

Projects

  • Status

    Done ✔️

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions