[Java][resttemplate] better code format (#10033)

* java restemplate: better code format

* update samples
This commit is contained in:
William Cheng
2021-07-25 16:07:04 +08:00
committed by GitHub
parent 8eba70dd3d
commit f0ebcd56d1
16 changed files with 414 additions and 353 deletions

View File

@@ -93,6 +93,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
private final String separator;
private CollectionFormat(String separator) {
this.separator = separator;
}
@@ -149,6 +150,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Get the current base path
*
* @return String the base path
*/
public String getBasePath() {
@@ -157,6 +159,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Set the base path, which should include the host
*
* @param basePath the base path
* @return ApiClient this client
*/
@@ -167,6 +170,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Get authentications (key: authentication name, value: authentication).
*
* @return Map the currently configured authentication types
*/
public Map<String, Authentication> getAuthentications() {
@@ -186,6 +190,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
{{#hasHttpBearerMethods}}
/**
* Helper method to set token for HTTP bearer authentication.
*
* @param bearerToken the token
*/
public void setBearerToken(String bearerToken) {
@@ -203,6 +208,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
{{#hasHttpBasicMethods}}
/**
* Helper method to set username for the first HTTP basic authentication.
*
* @param username Username
*/
public void setUsername(String username) {
@@ -234,6 +240,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
{{#hasApiKeyMethods}}
/**
* Helper method to set API key value for the first API key authentication.
*
* @param apiKey the API key
*/
public void setApiKey(String apiKey) {
@@ -248,6 +255,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Helper method to set API key prefix for the first API key authentication.
*
* @param apiKeyPrefix API key prefix
*/
public void setApiKeyPrefix(String apiKeyPrefix) {
@@ -265,6 +273,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
{{#hasOAuthMethods}}
/**
* Helper method to set access token for the first OAuth2 authentication.
*
* @param accessToken Access token
*/
public void setAccessToken(String accessToken) {
@@ -281,6 +290,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Set the User-Agent header's value (by adding to the default header map).
*
* @param userAgent the user agent string
* @return ApiClient this client
*/
@@ -379,6 +389,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Parse the given string into Date object.
*
* @param str the string to parse
* @return the Date parsed from the string
*/
@@ -392,6 +403,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Format the given Date object into string.
*
* @param date the date to format
* @return the formatted date as string
*/
@@ -401,6 +413,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Format the given parameter object into string.
*
* @param param the object to convert
* @return String the parameter represented as a String
*/
@@ -449,6 +462,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
*
* @param collectionFormat The format to convert to
* @param name The name of the parameter
* @param value The parameter's value
@@ -495,6 +509,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Check if the given {@code String} is a JSON MIME.
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -517,6 +532,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -526,6 +542,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Check if the given {@code String} is a Problem JSON MIME (RFC-7807).
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents Problem JSON, false otherwise
*/
@@ -577,6 +594,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Select the body to use for the request
*
* @param obj the body object
* @param formParams the form parameters
* @param contentType the content type of the request
@@ -589,6 +607,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Expand path template with variables
*
* @param pathTemplate path template with placeholders
* @param variables variables to replace
* @return path with placeholders replaced by variables
@@ -599,6 +618,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Include queryParams in uriParams taking into account the paramName
*
* @param queryParam The query parameters
* @param uriParams The path parameters
* return templatized query string
@@ -715,6 +735,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* Add cookies to the request that is being built
*
* @param cookies The cookies to add
* @param requestBuilder The current request
*/

View File

@@ -74,6 +74,7 @@ public class ApiClient extends JavaTimeFormatter {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
private final String separator;
private CollectionFormat(String separator) {
this.separator = separator;
}
@@ -130,6 +131,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Get the current base path
*
* @return String the base path
*/
public String getBasePath() {
@@ -138,6 +140,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Set the base path, which should include the host
*
* @param basePath the base path
* @return ApiClient this client
*/
@@ -148,6 +151,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Get authentications (key: authentication name, value: authentication).
*
* @return Map the currently configured authentication types
*/
public Map<String, Authentication> getAuthentications() {
@@ -167,6 +171,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set username for the first HTTP basic authentication.
*
* @param username Username
*/
public void setUsername(String username) {
@@ -196,6 +201,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set API key value for the first API key authentication.
*
* @param apiKey the API key
*/
public void setApiKey(String apiKey) {
@@ -210,6 +216,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set API key prefix for the first API key authentication.
*
* @param apiKeyPrefix API key prefix
*/
public void setApiKeyPrefix(String apiKeyPrefix) {
@@ -225,6 +232,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set access token for the first OAuth2 authentication.
*
* @param accessToken Access token
*/
public void setAccessToken(String accessToken) {
@@ -240,6 +248,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Set the User-Agent header's value (by adding to the default header map).
*
* @param userAgent the user agent string
* @return ApiClient this client
*/
@@ -336,6 +345,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Parse the given string into Date object.
*
* @param str the string to parse
* @return the Date parsed from the string
*/
@@ -349,6 +359,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Format the given Date object into string.
*
* @param date the date to format
* @return the formatted date as string
*/
@@ -358,6 +369,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Format the given parameter object into string.
*
* @param param the object to convert
* @return String the parameter represented as a String
*/
@@ -406,6 +418,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
*
* @param collectionFormat The format to convert to
* @param name The name of the parameter
* @param value The parameter's value
@@ -452,6 +465,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Check if the given {@code String} is a JSON MIME.
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -474,6 +488,7 @@ public class ApiClient extends JavaTimeFormatter {
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -483,6 +498,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Check if the given {@code String} is a Problem JSON MIME (RFC-7807).
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents Problem JSON, false otherwise
*/
@@ -534,6 +550,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Select the body to use for the request
*
* @param obj the body object
* @param formParams the form parameters
* @param contentType the content type of the request
@@ -546,6 +563,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Expand path template with variables
*
* @param pathTemplate path template with placeholders
* @param variables variables to replace
* @return path with placeholders replaced by variables
@@ -556,6 +574,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Include queryParams in uriParams taking into account the paramName
*
* @param queryParam The query parameters
* @param uriParams The path parameters
* return templatized query string
@@ -672,6 +691,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Add cookies to the request that is being built
*
* @param cookies The cookies to add
* @param requestBuilder The current request
*/

View File

@@ -69,6 +69,7 @@ public class ApiClient extends JavaTimeFormatter {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
private final String separator;
private CollectionFormat(String separator) {
this.separator = separator;
}
@@ -125,6 +126,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Get the current base path
*
* @return String the base path
*/
public String getBasePath() {
@@ -133,6 +135,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Set the base path, which should include the host
*
* @param basePath the base path
* @return ApiClient this client
*/
@@ -143,6 +146,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Get authentications (key: authentication name, value: authentication).
*
* @return Map the currently configured authentication types
*/
public Map<String, Authentication> getAuthentications() {
@@ -162,6 +166,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set username for the first HTTP basic authentication.
*
* @param username Username
*/
public void setUsername(String username) {
@@ -191,6 +196,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set API key value for the first API key authentication.
*
* @param apiKey the API key
*/
public void setApiKey(String apiKey) {
@@ -205,6 +211,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set API key prefix for the first API key authentication.
*
* @param apiKeyPrefix API key prefix
*/
public void setApiKeyPrefix(String apiKeyPrefix) {
@@ -220,6 +227,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Helper method to set access token for the first OAuth2 authentication.
*
* @param accessToken Access token
*/
public void setAccessToken(String accessToken) {
@@ -235,6 +243,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Set the User-Agent header's value (by adding to the default header map).
*
* @param userAgent the user agent string
* @return ApiClient this client
*/
@@ -331,6 +340,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Parse the given string into Date object.
*
* @param str the string to parse
* @return the Date parsed from the string
*/
@@ -344,6 +354,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Format the given Date object into string.
*
* @param date the date to format
* @return the formatted date as string
*/
@@ -353,6 +364,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Format the given parameter object into string.
*
* @param param the object to convert
* @return String the parameter represented as a String
*/
@@ -401,6 +413,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
*
* @param collectionFormat The format to convert to
* @param name The name of the parameter
* @param value The parameter's value
@@ -447,6 +460,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Check if the given {@code String} is a JSON MIME.
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -469,6 +483,7 @@ public class ApiClient extends JavaTimeFormatter {
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents JSON, false otherwise
*/
@@ -478,6 +493,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Check if the given {@code String} is a Problem JSON MIME (RFC-7807).
*
* @param mediaType the input MediaType
* @return boolean true if the MediaType represents Problem JSON, false otherwise
*/
@@ -529,6 +545,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Select the body to use for the request
*
* @param obj the body object
* @param formParams the form parameters
* @param contentType the content type of the request
@@ -541,6 +558,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Expand path template with variables
*
* @param pathTemplate path template with placeholders
* @param variables variables to replace
* @return path with placeholders replaced by variables
@@ -551,6 +569,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Include queryParams in uriParams taking into account the paramName
*
* @param queryParam The query parameters
* @param uriParams The path parameters
* return templatized query string
@@ -667,6 +686,7 @@ public class ApiClient extends JavaTimeFormatter {
/**
* Add cookies to the request that is being built
*
* @param cookies The cookies to add
* @param requestBuilder The current request
*/