OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] Type for map>array>item generated but not imported
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
- Clone https://github.com/bard/openapi-generator-missing-type
- Run
yarn install && yarn test
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/5995 seems to solve a similar issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked example.yaml and run yarn install && yarn test to reproduce the typescript-fetch generation failure. Trace the generated type references in api/apis/DefaultApi.ts; done means the referenced Character type is generated or imported correctly and the reproduction tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100