OpenAPITools / OpenAPITools/openapi-generator

[BUG] Enum path parameters' naming is wrong when used by multiple endpoints

Open
#20,627 0 comments 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? - (Swagger)
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hello,
I have a path parameter which is of type enum and I want to generate a model for it. My API has a few endpoints that are using the same enum for a path parameter. When the code is generated (tried with Java, Typescript, Typescript-Angular), the enum's name has a prefix related to one of the endpoints, which for me is wrong, because it's being used in other endpoints. I tried both with $ref to the parameter definition and as
inline definition part of the endpoint definition.

openapi-generator version

Tried with:
7.11.0 (latest at the moment)
7.7.0

OpenAPI declaration file content or url

https://gist.github.com/Vankata-Petrov/b4904c164c993d9e2c888387e76c9c76

Generation Details

None

Steps to reproduce

Run a generator for the file above and provide inline schema option "RESOLVE_INLINE_ENUMS=true"
E.g. npx openapi-generator-cli generate -i <openapi.json location> -g typescript -o <result_destination> --additional-properties=stringEnums=true,npmName=test-api --inline-schema-options RESOLVE_INLINE_ENUMS=true

Related issues/PRs

None

Suggest a fix

Couldn't find where this can be fixed, but I would expect that when "$ref" is used to point to a specific parameter definition, its name, also part of the definition, is taken into account and is used for all endpoints, which are using the same parameter reference.

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 with the OpenAPI declaration in the linked gist and reproduce the result using the openapi-generator-cli command with the typescript generator and RESOLVE_INLINE_ENUMS=true. Compare generated output for the shared enum parameter across endpoints and then check the Java, TypeScript, and TypeScript-Angular generators. Done means the shared parameter's intended name is retained consistently wherever its reference is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.