Skip to content

[BUG] [typescript-fetch] Type for map>array>item generated but not imported #6192

Open
@bard

Description

@bard

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 4.3.1
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When an item of an array of a map is specified through a referenced schema, the type for the item is not generated.

For example, for an endpoint specification of:

  "/characters":
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                additionalProperties:
                  type: array
                  items:
                    $ref: "#/components/schemas/Character"

And a schema specification of:

    Character:
      required: ["first", "name"]
      properties:
        id:
          type: integer
        name:
          type: string

The Character type is not generated:

api/apis/DefaultApi.ts:25:82 - error TS2304: Cannot find name 'Character'.

25     async charactersGetRaw(): Promise<runtime.ApiResponse<{ [key: string]: Array<Character>; }>> {
                                                                                    ~~~~~~~~~

api/apis/DefaultApi.ts:42:59 - error TS2304: Cannot find name 'Character'.

42     async charactersGet(): Promise<{ [key: string]: Array<Character>; }> {
                                                             ~~~~~~~~~


Found 2 errors.
openapi-generator version

4.3.1

OpenAPI declaration file content or url

https://github.com/bard/openapi-generator-missing-type/blob/master/example.yaml

Excerpt:

  "/characters":
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                additionalProperties:
                  type: array
                  items:
                    $ref: "#/components/schemas/Character"
Command line used for generation
openapi-generator generate -g typescript-fetch --additional-properties=typescriptThreePlus=true -i example.yaml -o api
Steps to reproduce
  1. Clone https://github.com/bard/openapi-generator-missing-type
  2. Run yarn install && yarn test
Related issues/PRs

#5995 seems to solve a similar issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions