Skip to content

Commit

Permalink
parameterize formParams
Browse files Browse the repository at this point in the history
fixes #5782
  • Loading branch information
jonfreedman committed Apr 1, 2020
1 parent 0b02345 commit 7a26ce5
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class {{classname}} {
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();{{#hasQueryParams}}
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();{{#hasQueryParams}}

{{#queryParams}}queryParams.putAll(apiClient.parameterToMultiValueMap({{#collectionFormat}}ApiClient.CollectionFormat.valueOf("{{{collectionFormat}}}".toUpperCase(Locale.ROOT)){{/collectionFormat}}{{^collectionFormat}}null{{/collectionFormat}}, "{{baseName}}", {{paramName}}));{{#hasMore}}
{{/hasMore}}{{/queryParams}}{{/hasQueryParams}}{{#hasHeaderParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
import java.util.TimeZone;

import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.HttpBearerAuth;

import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.OAuth;


@Component("org.openapitools.client.ApiClient")
public class ApiClient {
public enum CollectionFormat {
Expand Down Expand Up @@ -153,55 +153,31 @@ public Map<String, Authentication> getAuthentications() {
}

/**
* Get authentication for the given name.
*
* @param authName The authentication name
* @return The authentication, null if not found
*/
public Authentication getAuthentication(String authName) {
return authentications.get(authName);
}

/**
* Helper method to set token for HTTP bearer authentication.
* @param bearerToken the token
*/
public void setBearerToken(String bearerToken) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(bearerToken);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}

/**
* Helper method to set username for the first HTTP basic authentication.
* @param username the username
* Helper method to set API key value for the first API key authentication.
* @param apiKey the API key
*/
public void setUsername(String username) {
public void setApiKey(String apiKey) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKey(apiKey);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
throw new RuntimeException("No API key authentication configured!");
}

/**
* Helper method to set password for the first HTTP basic authentication.
* @param password the password
* Helper method to set API key prefix for the first API key authentication.
* @param apiKeyPrefix the API key prefix
*/
public void setPassword(String password) {
public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
if (auth instanceof ApiKeyAuth) {
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
throw new RuntimeException("No API key authentication configured!");
}

/**
Expand Down Expand Up @@ -232,6 +208,34 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
throw new RuntimeException("No API key authentication configured!");
}

/**
* Helper method to set username for the first HTTP basic authentication.
* @param username the username
*/
public void setUsername(String username) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}

/**
* Helper method to set password for the first HTTP basic authentication.
* @param password the password
*/
public void setPassword(String password) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}

/**
* Helper method to set access token for the first OAuth2 authentication.
* @param accessToken the access token
Expand All @@ -246,6 +250,16 @@ public void setAccessToken(String accessToken) {
throw new RuntimeException("No OAuth2 authentication configured!");
}

/**
* Get authentication for the given name.
*
* @param authName The authentication name
* @return The authentication, null if not found
*/
public Authentication getAuthentication(String authName) {
return authentications.get(authName);
}

/**
* Set the User-Agent header's value (by adding to the default header map).
* @param userAgent the user agent string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseEntity<Client> call123testSpecialTagsWithHttpInfo(Client body) th
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ResponseEntity<Void> createXmlItemWithHttpInfo(XmlItem xmlItem) throws Re
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = { };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
Expand Down Expand Up @@ -130,7 +130,7 @@ public ResponseEntity<Boolean> fakeOuterBooleanSerializeWithHttpInfo(Boolean bod
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"*/*"
Expand Down Expand Up @@ -172,7 +172,7 @@ public ResponseEntity<OuterComposite> fakeOuterCompositeSerializeWithHttpInfo(Ou
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"*/*"
Expand Down Expand Up @@ -214,7 +214,7 @@ public ResponseEntity<BigDecimal> fakeOuterNumberSerializeWithHttpInfo(BigDecima
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"*/*"
Expand Down Expand Up @@ -256,7 +256,7 @@ public ResponseEntity<String> fakeOuterStringSerializeWithHttpInfo(String body)
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"*/*"
Expand Down Expand Up @@ -302,7 +302,7 @@ public ResponseEntity<Void> testBodyWithFileSchemaWithHttpInfo(FileSchemaTestCla
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = { };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
Expand Down Expand Up @@ -355,7 +355,7 @@ public ResponseEntity<Void> testBodyWithQueryParamsWithHttpInfo(String query, Us
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query", query));

Expand Down Expand Up @@ -404,7 +404,7 @@ public ResponseEntity<Client> testClientModelWithHttpInfo(Client body) throws Re
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"application/json"
Expand Down Expand Up @@ -495,7 +495,7 @@ public ResponseEntity<Void> testEndpointParametersWithHttpInfo(BigDecimal number
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

if (integer != null)
formParams.add("integer", integer);
Expand Down Expand Up @@ -581,7 +581,7 @@ public ResponseEntity<Void> testEnumParametersWithHttpInfo(List<String> enumHead
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "enum_query_string_array", enumQueryStringArray));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_query_string", enumQueryString));
Expand Down Expand Up @@ -662,7 +662,7 @@ public ResponseEntity<Void> testGroupParametersWithHttpInfo(Integer requiredStri
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(null, "required_string_group", requiredStringGroup));
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "required_int64_group", requiredInt64Group));
Expand Down Expand Up @@ -716,7 +716,7 @@ public ResponseEntity<Void> testInlineAdditionalPropertiesWithHttpInfo(Map<Strin
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = { };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
Expand Down Expand Up @@ -769,7 +769,7 @@ public ResponseEntity<Void> testJsonFormDataWithHttpInfo(String param, String pa
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

if (param != null)
formParams.add("param", param);
Expand Down Expand Up @@ -848,7 +848,7 @@ public ResponseEntity<Void> testQueryParameterCollectionFormatWithHttpInfo(List<
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "pipe", pipe));
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "ioutil", ioutil));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseEntity<Client> testClassnameWithHttpInfo(Client body) throws Rest
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 MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

final String[] accepts = {
"application/json"
Expand Down
Loading

0 comments on commit 7a26ce5

Please sign in to comment.