swagger-api / swagger-api/swagger-codegen

[Java] Client - Missing import in JSON.java when using `Object` as schema name

Open
#10,175 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

When defining an Object as schema the io.swagger.client.JSON file doesn't compile anymore due to an ambigous usage of Object

Compile error message:

Error:(1397, 29) java: reference to Object is ambiguous
  both class io.swagger.client.model.Object in io.swagger.client.model and class java.lang.Object in java.lang match
// Line 1397
public String serialize(Object obj) {
        return gson.toJson(obj);
    }
Swagger-codegen version

3.0.19

Swagger declaration file content or url

https://pastebin.com/x85KPJtC

Command line used for generation
java -jar swagger-codegen-cli-3.0.19.jar generate -i openapi.json -l java -o clients/java
Steps to reproduce
  1. Create a client of a schema which contains Object as schema name
  2. Try to compile the client
Suggest a fix/enhancement

The import to java.lang.Object should be added to JSON.java in this case

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

Generate the Java client with swagger-codegen-cli 3.0.19 using the supplied OpenAPI declaration, then inspect clients/java JSON.java around line 1397. Reproduce the compilation error with a schema named Object; done means the generated client compiles without the ambiguous Object reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.