swagger-api / swagger-api/swagger-codegen

[JAVA] Client code does not compile for Iterable<ConcreteClass> API return type

Open
#4,031 1 comment 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 have a resource class with an Iterable as a return type:

    @GET
    @Timed
    @Path("/all")
    public Iterable<Saying> sayHellos() {
        LinkedList<Saying> sayings = new LinkedList<Saying>();

        sayings.add(new Saying(counter.incrementAndGet(), "Austin Powers"));
        sayings.add(new Saying(counter.incrementAndGet(), "Dr. Evil"));
        return sayings;
    }

Saying.java:

public class Saying {
    private long id;

    @Length(max = 3)
    private String content;

    public Saying() {
        // Jackson deserialization
    }

    public Saying(long id, String content) {
        this.id = id;
        this.content = content;
    }

    @JsonProperty
    public long getId() {
        return id;
    }

    @JsonProperty
    public String getContent() {
        return content;
    }
}

This generates the following specification:

https://github.com/digital-abyss/swagger-codegen-issue/blob/master/swagger.json

When trying to compile this using swagger-codegen, I encounter errors:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[42,31] cannot find symbol
  symbol:   class IterableSaying
  location: package io.swagger.client.model
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[220,12] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[231,24] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[244,70] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[221,21] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[233,49] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[266,49] cannot find symbol
  symbol:   class IterableSaying
  location: class io.swagger.client.api.DefaultApi
[INFO] 7 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.479 s
[INFO] Finished at: 2016-10-18T15:17:26-04:00
[INFO] Final Memory: 16M/366M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project swagger-java-client: Compilation failure: Compilation failure:
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[42,31] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: package io.swagger.client.model
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[220,12] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[231,24] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[244,70] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[221,21] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[233,49] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] //sanitized/path/swagger-codegen/test-client/src/main/java/io/swagger/client/api/DefaultApi.java:[266,49] cannot find symbol
[ERROR] symbol:   class IterableSaying
[ERROR] location: class io.swagger.client.api.DefaultApi
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

This is the return value of the endpoint:

[{"id":1,"content":"Austin Powers"},{"id":2,"content":"Dr. Evil"}]

If I replace Iterable interface with List, the generated source compiles.

Swagger-codegen version
commit c3a12cb3f99d643de1c2e29c5e8ddfe543b9e178
Merge: f345600 c26833f
Author: wing328 <wing328hk@gmail.com>
Date:   Tue Oct 18 23:22:09 2016 +0800

    Merge pull request #4027 from diega/patch-1

    [java] Allow setting test folder
Swagger declaration file content or url

https://github.com/digital-abyss/swagger-codegen-issue/blob/master/swagger.json

Command line used for generation
java/jdk1.8.0_101/bin/java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
    -i swagger.json \
    -l java \
    -o test-client
cd test-client
mvn clean package
Steps to reproduce
server "${workspace_loc:app1}/conf.yml
  • generate JSON swagger file:
curl http://localhost:8080/swagger.json
  • Try to build client:
java/jdk1.8.0_101/bin/java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
    -i swagger.json \
    -l java \
    -o test-client
cd test-client
mvn clean package
Related issues

Could not find a related issue.

Suggest a Fix

Would be happy to assist trying to fix.

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 supplied swagger.json and the generated test-client/src/main/java/io/swagger/client/api/DefaultApi.java, comparing output for Iterable with the working List case. Run the stated code-generation command followed by mvn clean package; done means the generated Java client compiles without references to the nonexistent IterableSaying class.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.