OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Generating client library with retrofit2, creates incorrect documentation/code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used? 4.2.3
- Have you search for related issues/PRs?
- What's the actual output vs expected output? Incorrect Documentation or code
Description
For given open-api spec, when generating client code for Retrofit2 library,
The generated code or documentation is incorrect.
There are methods/classes missing or the generated markdown documentation is incorrect.
openapi-generator version
Using Generator version 4.2.3 installed via homebrew
OpenAPI declaration file content or url
Using the below fromParameter.yaml spec file, I am generating a retrofit2 based client library
openapi: 3.0.0
servers:
- url: "localhost:8080"
info:
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
paths:
/get_path_style:
get:
operationId: getFormStyleParamMethod
parameters:
- in: query
name: styleQPName
style: form
schema:
type: object
properties:
queryParmObjField1:
type: string
responses:
"200":
description: OK
/get_path_explode:
get:
operationId: getExplodingParmMethod
parameters:
- in: query
name: explodingQPName
style: form
explode: true
schema:
type: object
properties:
queryParamObjExplodedField1:
type: string
responses:
"200":
description: OK
This generates Documentation in docs folder with a file DefaultApi.md and the details for usage shows the sample as below but that is incorrect
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.DefaultApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:8080");
DefaultApi apiInstance = new DefaultApi(defaultClient);
ExplodingQPName explodingQPName = new ExplodingQPName(); // ExplodingQPName |
try {
apiInstance.getExplodingParmMethod(explodingQPName);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#getExplodingParmMethod");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
- There is NO
Configuration.javaclass generated - There is no method
setBasePath(String urlbase)method present onAPIClient.javaclass
Command line used for generation
openapi-generator generate -i fromParameter.yaml -c codegen-config.json -g java -o sources/clients/java/
the codegen-config.json is as follows
{
"dateLibrary": "java8",
"delegatePattern": true,
"hideGenerationTimestamp": true,
"java8": true,
"library": "retrofit2"
}
Language - Java
Library - Retrofit2
Steps to reproduce
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied fromParameter.yaml and codegen-config.json, then run the shown openapi-generator command with the Retrofit2 library. Compare docs/DefaultApi.md with the generated APIClient.java and check the reported absence of Configuration.java and setBasePath(String urlbase). Done means the generated documentation matches the available Java API and the expected classes or methods are present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100