Skip to content

Commit

Permalink
[Java][OkHttp-Gson] fix: free form query parameters for okhttp-gson (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
llendi committed Aug 15, 2024
1 parent 05c1093 commit 38ebf0b
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,30 @@ public class ApiClient {
}
{{/dynamicOperations}}
/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();
// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}
return params;
}
/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class {{classname}} {
{{^dynamicOperations}}
{{#queryParams}}
if ({{paramName}} != null) {
{{#collectionFormat}}localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(localVarApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));
{{#isFreeFormObject}}localVarQueryParams.addAll(localVarApiClient.freeFormParameterToPairs({{paramName}}));{{/isFreeFormObject}}{{^isFreeFormObject}}{{#collectionFormat}}localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(localVarApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));{{/isFreeFormObject}}
}

{{/queryParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,21 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/FreeFormObjectTestClass'
/fake/free-form-query-parameters:
get:
parameters:
- in: "query"
name: "fixed"
schema:
type: "string"
- in: "query"
name: "free-form"
schema:
type: "object"
style: "form"
responses:
200:
description: OK
/fake/test-query-parameters:
put:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,30 @@ public List<Pair> parameterToPairs(Parameter param, Collection value) {
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,30 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
return params;
}

/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();

// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}

final Map<String, Object> valuesMap = (Map<String, Object>) value;

for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}

return params;
}


/**
* Formats the specified collection path parameter to a string value.
*
Expand Down
Loading

0 comments on commit 38ebf0b

Please sign in to comment.