Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

openapi - Open Api Generator supportJava6=true - Client not working on java 6

Goodmorning,

I am trying to generate an API client in Java with Open API. Sadly, it needs to work with java 6. I enable the flag, and everything works fine in the development environment (Eclipse) running on Java 11 with compliance for Java 6. When I export the JAR and try to run it in the staging environment with JRE 1.6, I get the error ClassDefNotFound okhttp3/Interceptor. If I try to download this dependency from Maven I then get Unsupported major.minor version 52.0.

So, I am wondering if the flag supportJava6 actually does something or not, since it seems like it requires at least Java 8.

Am I doing something wrong?

Best regards

UPDATE:

The API specs: https://api.civilianext.it/Protocollo/api/help/v1/docs

The API is authorized with client_ID and secret. I have made a small lib for the authorization, that works with Java6, so the auth is working and done.

What is not working is the API, at runtime usually (it compiles with some quick fixes).

I used both Swagger and OpenAPI, running locally in a docker.

BEWARE: I changed these files many times, I do not remember all combinations and configurations I tried. I do know I tried everything it was posted here in StackOverflow and even more, and nothing worked. I've been here for like a month trying everything when I have time.

These are the latest configurations I tried:

OpenAPI:

version: "3.6"
  services:
    openapi-codegen-cli:
      image: openapitools/openapi-generator-cli:v4.3.1
      volumes:
      - '.:/local'
      command: generate -g jaxrs-spec -i local/in/api.yml -o /local/out/jaxrs-client --additional-properties=dataLibrary=threetenbp,java8=false --skip-validate-spec

volumes:
 openapi_data:

Swagger:

swagger-codegen-cli:
   image: swaggerapi/swagger-codegen-cli
   volumes:
   - '.:/local'
   command: generate -l java -i local/json/api.json -c local/config/config.json -o /local/out/java-client

// config.json

{
  supportJava6: true,
}

Once the code is generated, I usually have to fix the pom.xml, adding <pluginManagement> tags. Then I build the project with mvn clean install. The build compiles and I usually get some errors at runtime, about unsupported major.minor version.

I also tried this: https://github.com/OpenAPITools/openapi-generator/issues/8383


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

1 Answer

0 votes
by (71.8m points)

You should use version 1.x of okhttp. Read carefully the change log at https://square.github.io/okhttp/changelog_1x/. Try first with version 1.1.1.

You can download the jar from maven repository at https://mvnrepository.com/artifact/com.squareup.okhttp/okhttp


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...