-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[BUG] [Java Client]OneOf inside property of a schema generates broken class (OneOfstringstring) #5730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The same problem generating using CMD: |
Fix on master only works with Jackson clients, the default is not Jackson. You need to set the library, for instance |
Thanks, it works |
Cool. Can you close the issue then? |
The class OneOfstringstring?? is not generated on path class IpApi:
|
Same issue. It's not work for me. openapi: "3.0.1"
info:
version: "1.0.0"
title: "oneOf Test"
paths:
/pets:
post:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer Generated Java package org.openapitools.client.api;
import org.openapitools.client.ApiClient;
import org.openapitools.client.model.PetsPOST;
import org.openapitools.client.model.UNKNOWN_BASE_TYPE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-04-16T18:33:15.038+02:00[Europe/Paris]")
@Component("org.openapitools.client.api.DefaultApi")
public class DefaultApi {
private ApiClient apiClient;
public DefaultApi() {
this(new ApiClient());
}
@Autowired
public DefaultApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
*
*
* <p><b>200</b> - Updated
* @param UNKNOWN_BASE_TYPE (optional)
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public void petsPost(UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE) throws RestClientException {
petsPostWithHttpInfo(UNKNOWN_BASE_TYPE);
}
/**
*
*
* <p><b>200</b> - Updated
* @param UNKNOWN_BASE_TYPE (optional)
* @return ResponseEntity<Void>
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity<Void> petsPostWithHttpInfo(UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE) throws RestClientException {
Object postBody = UNKNOWN_BASE_TYPE;
String path = apiClient.expandPath("/pets", Collections.<String, Object>emptyMap());
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap formParams = new LinkedMultiValueMap();
final String[] accepts = { };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {
"application/json"
};
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] { };
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType);
}
} Step to reproduce
Create method with parameter |
Hi All, Even I am facing the same issue when open API spec YAML file is given as input, implementation logic created by using open API generator utility but when we try to build the implementation using mvn clean package we are facing the same following issue. we used @jfeltesse-mdsol comment using the flag --library native while generating implementation login for open API spec. but when we try to build using command mvn clean package , again different issues as follows. is there any other way is there for this? Regards |
Is it fair to say it's fixed then? Fixed if you're using Jackson. The current fix I'm trying for the generated code is simply replacing the OneOf... with a common superclass - I'm guessing this won't work for all cases. |
@jfeltesse-mdsol what could be the fix for this? |
Just tested with openapi-generator-cli-5.0.0-20200422.090118-38.jar but the problem is not solved. |
@ngp-star It's a big pain but at the moment I'm just replacing use of the interface with a common superclass, not sure if this works for you: $ find build/open-api-generated/src/main/java/ -type f -name "*.java" -exec sed -i 's/OneOfAllTheTypes/CommonSuperclass/g' {} \; |
This work around works for me. |
@gravelld like should we build the open API source code? then use your command for replacement? |
I would just add it to whatever build script you have. |
@gravelld I don't have build script I installed open API generator CLI tool from that I ma generating implementations |
Then write a script (bash, batch, whatever) to run the workaround after the classes are generated. Or, just remember to do it every time. |
@gravelld |
@gravelld getting following error Moreover, I don't have any class or interface named OneOfAllTheTypes in my generated implementation. |
Sorry - can't really help because it depends on your OS and this is getting off topic. You normally wouldn't have just |
Please give the latest master a try with the |
Description
I tried to generate java client code of a model containing oneOf, the code is generated but the generated class IObject (see the example) uses the class OneOfstringstring which is not generaated.
openapi-generator version
openapi-generator-cli-4.3.0-20200326.174439-234
OpenAPI declaration file content or url
The complete example :
Command line used for generation
I'm using OpenApi studio
Steps to reproduce
Generate the above example with java client.
Related issues/PRs
#5382
The text was updated successfully, but these errors were encountered: