Better handling of allOf in request body (#16991)

* better handling of allOf in request body, add tests

* additional checks

* fix description
This commit is contained in:
William Cheng
2023-11-05 22:43:45 +08:00
committed by GitHub
parent 339596aeec
commit 49208144e1
41 changed files with 2682 additions and 1 deletions

View File

@@ -349,6 +349,79 @@ public class BodyApi {
}
return localVarRequestBuilder;
}
/**
* Test body parameter(s)
* Test body parameter(s)
* @param pet Pet object that needs to be added to the store (optional)
* @return Pet
* @throws ApiException if fails to make API call
*/
public Pet testEchoBodyAllOfPet(Pet pet) throws ApiException {
ApiResponse<Pet> localVarResponse = testEchoBodyAllOfPetWithHttpInfo(pet);
return localVarResponse.getData();
}
/**
* Test body parameter(s)
* Test body parameter(s)
* @param pet Pet object that needs to be added to the store (optional)
* @return ApiResponse&lt;Pet&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<Pet> testEchoBodyAllOfPetWithHttpInfo(Pet pet) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = testEchoBodyAllOfPetRequestBuilder(pet);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("testEchoBodyAllOfPet", localVarResponse);
}
return new ApiResponse<Pet>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Pet>() {}) // closes the InputStream
);
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder testEchoBodyAllOfPetRequestBuilder(Pet pet) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/echo/body/allOf/Pet";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "application/json");
try {
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(pet);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Test free form object
* Test free form object

View File

@@ -60,6 +60,28 @@ public class CustomTest {
Assert.assertNull(p2);
}
/**
* Test allOf body parameter(s)
* <p>
* Test allOf body parameter(s)
*
* @throws ApiException if the Api call fails
*/
@Test
public void testEchoBodyAllOfPet() throws ApiException {
Pet queryObject = new Pet().id(12345L).name("Hello World").
photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category"));
Pet p = bodyApi.testEchoBodyAllOfPet(queryObject);
Assert.assertNotNull(p);
Assert.assertEquals("Hello World", p.getName());
Assert.assertEquals(Long.valueOf(12345L), p.getId());
// response is empty body
Pet p2 = bodyApi.testEchoBodyPet(null);
Assert.assertNull(p2);
}
/**
* Test query parameter(s)
* <p>