OpenAPITools / OpenAPITools/openapi-generator

[BUG][Typescript-axios] Missing import with only additionalProperties object with array and ref

Open
#5,601 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When a response returns an object with only additionalProperties of type array with a ref the import is missing in the code generation (as seen in the gist). It does work correctly if the response was an object with additionalProperties of simply that ref for example.

openapi-generator version

4.2.3

OpenAPI declaration file content or url

Swagger JSON

Command line used for generation

Using NodeJS - yarn openapi-generator generate -c config.json --enable-post-process-file -i swagger.json -g typescript-axios -o ./src/openapi
Our config.json is as follows

{
  "withSeparateModelsAndApi": true,
  "modelPackage": "models",
  "apiPackage": "api"
}

(this issue is only relevant if you have withSeparateModelsAndApi enabled)

Steps to reproduce

Simply generate using the provided swagger.json

Related issues/PRs
Suggest a fix

Need to investigate further

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided yarn openapi-generator command with swagger.json and config.json, using the linked Swagger JSON as the reproduction case. Inspect the typescript-axios generation path for model import resolution when withSeparateModelsAndApi is enabled. Done means the generated model includes the import for the referenced array type and still handles the non-array additionalProperties case.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, openapi, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.