Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

gson - Error while compiling swagger-codegen java Petstore sdk

I am trying to generate a java API using swagger-codegen (3.0.0) I am using the swagger-codegen-cli-3.0.24.jar version of codegen jar. I ran the following command to generate the SDK for the sample petstore project:

java -jar swagger-codegen-cli.jar generate -i code/swagger-codegen/modules/swagger-codegen/src/test/resources/3_0_0/petstore.json -l java -o out/pet-java

When I am compiling the generated sdk project:

cd out/pet-java
mvn clean package

I am getting the below error:

Compilation failure
[ERROR] out/pet-java/src/main/java/io/swagger/client/model/Pet.java:[87,34] cannot find symbol
[ERROR]   symbol:   method nextObject()
[ERROR]   location: variable jsonReader of type com.google.gson.stream.JsonReader
it is using <gson-version>2.8.1</gson-version> as dependency.
question from:https://stackoverflow.com/questions/65843067/error-while-compiling-swagger-codegen-java-petstore-sdk

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ultimately the real answer is for swagger-codegen to fix their regression. They've admitted that it's a problem. In the mean time I've worked around the issue for my particular situation. To demonstrate the types of changes that are necessary, see below:

enter image description here

In some files instead of nextObject(), there may be a call to next(). The solution is the same, however.

Apologies for any confusion in the diff. Apparently I left the original lines in the file commented out below the working replacement line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...