swagger-api / swagger-api/swagger-codegen

[JAVA] [RESTTEMPLATE] import-mappings does not rename classes inside generated class

Open
#8,098 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

I had to use one API which uses Geolatte in model classes. When I generate code I'll get many classes that does not exist in source project. For example GeometryobjectDTO is generated. That includes many classes that are unusable, for example PositionSequenceDTO.

Best option is to skip generation of those extra classes and use Geolatte classes instead. Import mappings option didn't do that trick for me.

Same json generated working for typescript.

Swagger-codegen version

2.2.3 and 2.3.1

Swagger declaration file content or url

https://gist.github.com/llaocto3/becf5041525b0d2cff51e4046468c25e

Command line used for generation

swagger-codegen-cli generate -i http://localhost:80/v2/api-docs -o /tmp/pettest -l java -D library=resttemplate --model-name-suffix=DTO --import-mappings GeometryobjectDTO=org.geolatte.geom.Geometry,PositionDTO=org.geolatte.geom.Position

Steps to reproduce
  1. Download spring boot server example from swagger-codegen project
  2. To model Pet add these lines:
  @JsonProperty("geometry")
  private Geometry<?> geometry;

  @JsonProperty("position")
  private Geometry<Position> position;
  1. Add also import for Geolatte
import org.geolatte.geom.Geometry;
import org.geolatte.geom.Position;
  1. Compile and run
  2. Generate with command given in above section
Related issues/PRs

Didn't find any related issues.

Suggest a fix/enhancement

When given different names in mapping classes, rename also the class inside model.

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

Reproduce the issue with the supplied swagger-codegen-cli command, the linked Swagger declaration, and the Java RESTTemplate generator. Inspect the generated GeometryobjectDTO and PositionDTO model references; done means import mappings cause the generated model to use Geolatte Geometry and Position without generating unusable replacement classes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, 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.