swagger-api / swagger-api/swagger-codegen

[JAVA, SPRING] change name of generated class to existing one

Open
#11,913 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

To reference an existing class during generation the parameter --import-mappings can be used. However this is only working if the component name from your yaml-specification is the same as the class name you reference.

Swagger-codegen version

3.0.33

Suggest a fix/enhancement

It would be great if u could use the --type-mappings parameter to rename the class name and use it additional to the --import-mappings where you specifiy the import for the class.

Example:

If Im forced to use an existing specification which cant be touched, i could define another class with another name as implementation - e.g:

Component in Specification-file:

...
components:
  schemas:

    PatchComponent:
      type: object
...

and then via --type--mappings changeing the name from PatchComponent to JsonMergePatch
and via --import-mappings from your model package changed to javax.json.JsonMergePatch for PatchComponent

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 reproducing generation from the shown OpenAPI schema with --type-mappings and --import-mappings on swagger-codegen 3.0.33. Trace how the PatchComponent name is resolved for Java/Spring generation; done means an existing javax.json.JsonMergePatch class can be referenced while the generated model name is changed without generating a duplicate.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Feature
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.