swagger-api / swagger-api/swagger-codegen

[Java] Documentation examples generated by api_doc.mustache for feign, resttemplate, retrofit, retrofit2, google-api-client, rest-assured are incorrect

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

Because of this code snippet in the JavaClientCodegen.java, ApiException.java is not generated for the feign, resttemplate, retrofit, retrofit2, google-api-client, and rest-assured libraries.

https://github.com/swagger-api/swagger-codegen/blob/9a1460aba1a08ea3095e191caf156c666721feae/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java#L206-L211

The generated documentation examples that use ApiException are invalid. For example,

Source:

// Import classes:
//import io.swagger.client.ApiException;
//import io.swagger.client.api.AnotherFakeApi;


AnotherFakeApi apiInstance = new AnotherFakeApi();
Client body = new Client(); // Client | client model
try {
    Client result = apiInstance.testSpecialTags(body);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling AnotherFakeApi#testSpecialTags");
    e.printStackTrace();
}

This code will not run because ApiException is not a generated class.

Furthermore, the AnotherFakeAPi, is not a class, but instead an interface in retrofit. Thus, the generic api_doc.mustache template does not apply for this framework.

Swagger-codegen version

3.0.20. Based on the repository, version 2 has the same problem.

Steps to reproduce

Repository provides an example of this issue: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/retrofit2/docs/AnotherFakeApi.md#example

Suggest a fix/enhancement

I would like to write an api_doc.mustache template for these libraries, but I do not know what are the appropriate example code to write now that ApiException isn't a viable class. Is there some other error type for these frameworks?

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 referenced JavaClientCodegen.java lines and the api_doc.mustache template, then inspect the generated sample at samples/client/petstore/java/retrofit2/docs/AnotherFakeApi.md and its AnotherFakeApi.java interface. Compare the documentation examples for the listed libraries with their generated APIs. Done means those examples no longer reference an absent ApiException or an inapplicable generic template.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.