[Java][jersey2] Use builder pattern for requests (#4666)

* Use builder pattern for requests

* petstore

* Add @throws annotation

* regenerate jersey2 test files

* Also group bodyParam in builder class

* petstore java6

* regenerate java8

* ensure up to date
This commit is contained in:
Hippolyte HENRY
2020-01-18 09:12:20 +01:00
committed by William Cheng
parent 420039c9eb
commit ee984c38a5
139 changed files with 2378 additions and 1330 deletions

View File

@@ -12,6 +12,7 @@ Method | HTTP request | Description
> Client call123testSpecialTags(body)
To test special tags
To test special tags and operation ID starting with number
@@ -33,8 +34,9 @@ public class Example {
AnotherFakeApi apiInstance = new AnotherFakeApi(defaultClient);
Client body = new Client(); // Client | client model
try {
try {
Client result = apiInstance.call123testSpecialTags(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnotherFakeApi#call123testSpecialTags");

View File

@@ -25,6 +25,7 @@ Method | HTTP request | Description
> createXmlItem(xmlItem)
creates an XmlItem
this route creates an XmlItem
@@ -46,8 +47,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
XmlItem xmlItem = new XmlItem(); // XmlItem | XmlItem Body
try {
try {
apiInstance.createXmlItem(xmlItem);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#createXmlItem");
System.err.println("Status code: " + e.getCode());
@@ -91,6 +94,7 @@ No authorization required
Test serialization of outer boolean types
### Example
@@ -110,8 +114,9 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
Boolean body = true; // Boolean | Input boolean as post body
try {
try {
Boolean result = apiInstance.fakeOuterBooleanSerialize(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeOuterBooleanSerialize");
@@ -156,6 +161,7 @@ No authorization required
Test serialization of object with outer number type
### Example
@@ -175,8 +181,9 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
OuterComposite body = new OuterComposite(); // OuterComposite | Input composite as post body
try {
try {
OuterComposite result = apiInstance.fakeOuterCompositeSerialize(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeOuterCompositeSerialize");
@@ -221,6 +228,7 @@ No authorization required
Test serialization of outer number types
### Example
@@ -240,8 +248,9 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
BigDecimal body = new BigDecimal(); // BigDecimal | Input number as post body
try {
try {
BigDecimal result = apiInstance.fakeOuterNumberSerialize(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeOuterNumberSerialize");
@@ -286,6 +295,7 @@ No authorization required
Test serialization of outer string types
### Example
@@ -305,8 +315,9 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
String body = "body_example"; // String | Input string as post body
try {
try {
String result = apiInstance.fakeOuterStringSerialize(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeOuterStringSerialize");
@@ -351,7 +362,8 @@ No authorization required
For this test, the body for this request much reference a schema named `File`.
For this test, the body for this request much reference a schema named `File`.
### Example
@@ -370,8 +382,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
FileSchemaTestClass body = new FileSchemaTestClass(); // FileSchemaTestClass |
try {
try {
apiInstance.testBodyWithFileSchema(body);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testBodyWithFileSchema");
System.err.println("Status code: " + e.getCode());
@@ -415,6 +429,7 @@ No authorization required
### Example
```java
@@ -433,8 +448,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
String query = "query_example"; // String |
User body = new User(); // User |
try {
try {
apiInstance.testBodyWithQueryParams(query, body);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testBodyWithQueryParams");
System.err.println("Status code: " + e.getCode());
@@ -477,10 +494,11 @@ No authorization required
> Client testClientModel(body)
To test \"client\" model
To test \"client\" model
To test "client" model
### Example
```java
@@ -498,8 +516,9 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
Client body = new Client(); // Client | client model
try {
try {
Client result = apiInstance.testClientModel(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testClientModel");
@@ -542,10 +561,14 @@ No authorization required
> testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback)
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Fake endpoint for testing various parameters
假端點
偽のエンドポイント
가짜 엔드 포인트
### Example
```java
@@ -582,8 +605,10 @@ public class Example {
OffsetDateTime dateTime = new OffsetDateTime(); // OffsetDateTime | None
String password = "password_example"; // String | None
String paramCallback = "paramCallback_example"; // String | None
try {
try {
apiInstance.testEndpointParameters(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testEndpointParameters");
System.err.println("Status code: " + e.getCode());
@@ -639,6 +664,7 @@ null (empty response body)
> testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString)
To test enum parameters
To test enum parameters
@@ -667,8 +693,10 @@ public class Example {
Double enumQueryDouble = 3.4D; // Double | Query parameter enum test (double)
List<String> enumFormStringArray = "$"; // List<String> | Form parameter enum test (string array)
String enumFormString = "-efg"; // String | Form parameter enum test (string)
try {
try {
apiInstance.testEnumParameters(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumFormStringArray, enumFormString);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testEnumParameters");
System.err.println("Status code: " + e.getCode());
@@ -716,7 +744,8 @@ No authorization required
## testGroupParameters
> testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group, stringGroup, booleanGroup, int64Group)
> testGroupParameters().requiredStringGroup(requiredStringGroup).requiredBooleanGroup(requiredBooleanGroup).requiredInt64Group(requiredInt64Group).stringGroup(stringGroup).booleanGroup(booleanGroup).int64Group(int64Group).execute();
Fake endpoint to test group parameters (optional)
@@ -744,8 +773,16 @@ public class Example {
Integer stringGroup = 56; // Integer | String in group parameters
Boolean booleanGroup = true; // Boolean | Boolean in group parameters
Long int64Group = 56L; // Long | Integer in group parameters
try {
apiInstance.testGroupParameters(requiredStringGroup, requiredBooleanGroup, requiredInt64Group, stringGroup, booleanGroup, int64Group);
try {
api.testGroupParameters()
.requiredStringGroup(requiredStringGroup)
.requiredBooleanGroup(requiredBooleanGroup)
.requiredInt64Group(requiredInt64Group)
.stringGroup(stringGroup)
.booleanGroup(booleanGroup)
.int64Group(int64Group)
.execute();
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testGroupParameters");
System.err.println("Status code: " + e.getCode());
@@ -792,6 +829,7 @@ No authorization required
> testInlineAdditionalProperties(param)
test inline additionalProperties
### Example
@@ -811,8 +849,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
Map<String, String> param = new HashMap(); // Map<String, String> | request body
try {
try {
apiInstance.testInlineAdditionalProperties(param);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testInlineAdditionalProperties");
System.err.println("Status code: " + e.getCode());
@@ -854,6 +894,7 @@ No authorization required
> testJsonFormData(param, param2)
test json serialization of form data
### Example
@@ -874,8 +915,10 @@ public class Example {
FakeApi apiInstance = new FakeApi(defaultClient);
String param = "param_example"; // String | field1
String param2 = "param2_example"; // String | field2
try {
try {
apiInstance.testJsonFormData(param, param2);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testJsonFormData");
System.err.println("Status code: " + e.getCode());
@@ -920,6 +963,7 @@ No authorization required
To test the collection format in query parameters
### Example
@@ -943,8 +987,10 @@ public class Example {
List<String> http = Arrays.asList(); // List<String> |
List<String> url = Arrays.asList(); // List<String> |
List<String> context = Arrays.asList(); // List<String> |
try {
try {
apiInstance.testQueryParameterCollectionFormat(pipe, ioutil, http, url, context);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#testQueryParameterCollectionFormat");
System.err.println("Status code: " + e.getCode());

View File

@@ -12,6 +12,7 @@ Method | HTTP request | Description
> Client testClassname(body)
To test class name in snake case
To test class name in snake case
@@ -40,8 +41,9 @@ public class Example {
FakeClassnameTags123Api apiInstance = new FakeClassnameTags123Api(defaultClient);
Client body = new Client(); // Client | client model
try {
try {
Client result = apiInstance.testClassname(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeClassnameTags123Api#testClassname");

View File

@@ -20,6 +20,7 @@ Method | HTTP request | Description
> addPet(body)
Add a new pet to the store
### Example
@@ -44,8 +45,10 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
Pet body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
try {
apiInstance.addPet(body);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#addPet");
System.err.println("Status code: " + e.getCode());
@@ -88,6 +91,7 @@ null (empty response body)
> deletePet(petId, apiKey)
Deletes a pet
### Example
@@ -113,8 +117,10 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
Long petId = 56L; // Long | Pet id to delete
String apiKey = "apiKey_example"; // String |
try {
try {
apiInstance.deletePet(petId, apiKey);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#deletePet");
System.err.println("Status code: " + e.getCode());
@@ -158,6 +164,7 @@ null (empty response body)
> List&lt;Pet&gt; findPetsByStatus(status)
Finds Pets by status
Multiple status values can be provided with comma separated strings
@@ -184,8 +191,9 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
List<String> status = Arrays.asList("available"); // List<String> | Status values that need to be considered for filter
try {
try {
List<Pet> result = apiInstance.findPetsByStatus(status);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#findPetsByStatus");
@@ -229,6 +237,7 @@ Name | Type | Description | Notes
> List&lt;Pet&gt; findPetsByTags(tags)
Finds Pets by tags
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@@ -255,8 +264,9 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
List<String> tags = Arrays.asList(); // List<String> | Tags to filter by
try {
try {
List<Pet> result = apiInstance.findPetsByTags(tags);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#findPetsByTags");
@@ -300,6 +310,7 @@ Name | Type | Description | Notes
> Pet getPetById(petId)
Find pet by ID
Returns a single pet
@@ -328,8 +339,9 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
Long petId = 56L; // Long | ID of pet to return
try {
try {
Pet result = apiInstance.getPetById(petId);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#getPetById");
@@ -374,6 +386,7 @@ Name | Type | Description | Notes
> updatePet(body)
Update an existing pet
### Example
@@ -398,8 +411,10 @@ public class Example {
PetApi apiInstance = new PetApi(defaultClient);
Pet body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
try {
apiInstance.updatePet(body);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#updatePet");
System.err.println("Status code: " + e.getCode());
@@ -444,6 +459,7 @@ null (empty response body)
> updatePetWithForm(petId, name, status)
Updates a pet in the store with form data
### Example
@@ -470,8 +486,10 @@ public class Example {
Long petId = 56L; // Long | ID of pet that needs to be updated
String name = "name_example"; // String | Updated name of the pet
String status = "status_example"; // String | Updated status of the pet
try {
try {
apiInstance.updatePetWithForm(petId, name, status);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#updatePetWithForm");
System.err.println("Status code: " + e.getCode());
@@ -515,6 +533,7 @@ null (empty response body)
> ModelApiResponse uploadFile(petId, additionalMetadata, file)
uploads an image
### Example
@@ -541,8 +560,9 @@ public class Example {
Long petId = 56L; // Long | ID of pet to update
String additionalMetadata = "additionalMetadata_example"; // String | Additional data to pass to server
File file = new File("/path/to/file"); // File | file to upload
try {
try {
ModelApiResponse result = apiInstance.uploadFile(petId, additionalMetadata, file);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#uploadFile");
@@ -587,6 +607,7 @@ Name | Type | Description | Notes
> ModelApiResponse uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata)
uploads an image (required)
### Example
@@ -613,8 +634,9 @@ public class Example {
Long petId = 56L; // Long | ID of pet to update
File requiredFile = new File("/path/to/file"); // File | file to upload
String additionalMetadata = "additionalMetadata_example"; // String | Additional data to pass to server
try {
try {
ModelApiResponse result = apiInstance.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#uploadFileWithRequiredFile");

View File

@@ -15,9 +15,10 @@ Method | HTTP request | Description
> deleteOrder(orderId)
Delete purchase order by ID
For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example
@@ -36,8 +37,10 @@ public class Example {
StoreApi apiInstance = new StoreApi(defaultClient);
String orderId = "orderId_example"; // String | ID of the order that needs to be deleted
try {
try {
apiInstance.deleteOrder(orderId);
} catch (ApiException e) {
System.err.println("Exception when calling StoreApi#deleteOrder");
System.err.println("Status code: " + e.getCode());
@@ -80,6 +83,7 @@ No authorization required
> Map&lt;String, Integer&gt; getInventory()
Returns pet inventories by status
Returns a map of status codes to quantities
@@ -107,8 +111,9 @@ public class Example {
//api_key.setApiKeyPrefix("Token");
StoreApi apiInstance = new StoreApi(defaultClient);
try {
try {
Map<String, Integer> result = apiInstance.getInventory();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StoreApi#getInventory");
@@ -148,9 +153,10 @@ This endpoint does not need any parameter.
> Order getOrderById(orderId)
Find purchase order by ID
For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example
@@ -169,8 +175,9 @@ public class Example {
StoreApi apiInstance = new StoreApi(defaultClient);
Long orderId = 56L; // Long | ID of pet that needs to be fetched
try {
try {
Order result = apiInstance.getOrderById(orderId);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StoreApi#getOrderById");
@@ -215,6 +222,7 @@ No authorization required
> Order placeOrder(body)
Place an order for a pet
### Example
@@ -234,8 +242,9 @@ public class Example {
StoreApi apiInstance = new StoreApi(defaultClient);
Order body = new Order(); // Order | order placed for purchasing the pet
try {
try {
Order result = apiInstance.placeOrder(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StoreApi#placeOrder");

View File

@@ -19,6 +19,7 @@ Method | HTTP request | Description
> createUser(body)
Create user
This can only be done by the logged in user.
@@ -40,8 +41,10 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
User body = new User(); // User | Created user object
try {
try {
apiInstance.createUser(body);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#createUser");
System.err.println("Status code: " + e.getCode());
@@ -83,6 +86,7 @@ No authorization required
> createUsersWithArrayInput(body)
Creates list of users with given input array
### Example
@@ -102,8 +106,10 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
List<User> body = Arrays.asList(); // List<User> | List of user object
try {
try {
apiInstance.createUsersWithArrayInput(body);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#createUsersWithArrayInput");
System.err.println("Status code: " + e.getCode());
@@ -145,6 +151,7 @@ No authorization required
> createUsersWithListInput(body)
Creates list of users with given input array
### Example
@@ -164,8 +171,10 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
List<User> body = Arrays.asList(); // List<User> | List of user object
try {
try {
apiInstance.createUsersWithListInput(body);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#createUsersWithListInput");
System.err.println("Status code: " + e.getCode());
@@ -207,6 +216,7 @@ No authorization required
> deleteUser(username)
Delete user
This can only be done by the logged in user.
@@ -228,8 +238,10 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
String username = "username_example"; // String | The name that needs to be deleted
try {
try {
apiInstance.deleteUser(username);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#deleteUser");
System.err.println("Status code: " + e.getCode());
@@ -272,6 +284,7 @@ No authorization required
> User getUserByName(username)
Get user by user name
### Example
@@ -291,8 +304,9 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
String username = "username_example"; // String | The name that needs to be fetched. Use user1 for testing.
try {
try {
User result = apiInstance.getUserByName(username);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#getUserByName");
@@ -337,6 +351,7 @@ No authorization required
> String loginUser(username, password)
Logs user into the system
### Example
@@ -357,8 +372,9 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
String username = "username_example"; // String | The user name for login
String password = "password_example"; // String | The password for login in clear text
try {
try {
String result = apiInstance.loginUser(username, password);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#loginUser");
@@ -403,6 +419,7 @@ No authorization required
> logoutUser()
Logs out current logged in user session
### Example
@@ -421,8 +438,10 @@ public class Example {
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
UserApi apiInstance = new UserApi(defaultClient);
try {
try {
apiInstance.logoutUser();
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#logoutUser");
System.err.println("Status code: " + e.getCode());
@@ -461,6 +480,7 @@ No authorization required
> updateUser(username, body)
Updated user
This can only be done by the logged in user.
@@ -483,8 +503,10 @@ public class Example {
UserApi apiInstance = new UserApi(defaultClient);
String username = "username_example"; // String | name that need to be deleted
User body = new User(); // User | Updated user object
try {
try {
apiInstance.updateUser(username, body);
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#updateUser");
System.err.println("Status code: " + e.getCode());