Skip to content

Commit a8973c9

Browse files
Update samples
1 parent b72877a commit a8973c9

File tree

41 files changed

+518
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+518
-86
lines changed

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -438,6 +439,36 @@ public String parameterToString(Object param) {
438439
}
439440
}
440441

442+
/**
443+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
444+
* @param collectionFormat The format to convert to
445+
* @param name The name of the parameter
446+
* @param value The parameter's value
447+
* @return a Map containing the Json-serialized String value(s) of the input parameter
448+
*/
449+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
450+
Collection<?> valueCollection;
451+
if (value instanceof Collection) {
452+
valueCollection = (Collection<?>) value;
453+
} else {
454+
try {
455+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
456+
} catch (JsonProcessingException e) {
457+
throw new RuntimeException(e);
458+
}
459+
}
460+
461+
List<String> values = new ArrayList<>();
462+
for(Object o : valueCollection) {
463+
try {
464+
values.add(objectMapper.writeValueAsString(o));
465+
} catch (JsonProcessingException e) {
466+
throw new RuntimeException(e);
467+
}
468+
}
469+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
470+
}
471+
441472
/**
442473
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
443474
* @param collectionFormat The format to convert to

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/api/HeaderApi.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ private ResponseSpec testHeaderIntegerBooleanStringEnumsRequestCreation(@jakarta
6666
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<>();
6767
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
6868

69-
7069
if (integerHeader != null)
7170
headerParams.add("integer_header", apiClient.parameterToString(integerHeader));
7271
if (booleanHeader != null)

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/api/QueryApi.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private ResponseSpec testEnumRefStringRequestCreation(@jakarta.annotation.Nullab
7171

7272
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_nonref_string_query", enumNonrefStringQuery));
7373
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_ref_string_query", enumRefStringQuery));
74-
74+
7575
final String[] localVarAccepts = {
7676
"text/plain"
7777
};
@@ -149,7 +149,7 @@ private ResponseSpec testQueryDatetimeDateStringRequestCreation(@jakarta.annotat
149149
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "datetime_query", datetimeQuery));
150150
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "date_query", dateQuery));
151151
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_query", stringQuery));
152-
152+
153153
final String[] localVarAccepts = {
154154
"text/plain"
155155
};
@@ -230,7 +230,7 @@ private ResponseSpec testQueryIntegerBooleanStringRequestCreation(@jakarta.annot
230230
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "integer_query", integerQuery));
231231
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "boolean_query", booleanQuery));
232232
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_query", stringQuery));
233-
233+
234234
final String[] localVarAccepts = {
235235
"text/plain"
236236
};
@@ -312,7 +312,7 @@ private ResponseSpec testQueryStyleDeepObjectExplodeTrueObjectRequestCreation(@j
312312
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
313313
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
314314
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
315-
315+
316316
final String[] localVarAccepts = {
317317
"text/plain"
318318
};
@@ -383,7 +383,7 @@ private ResponseSpec testQueryStyleDeepObjectExplodeTrueObjectAllOfRequestCreati
383383
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
384384

385385
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_object", queryObject));
386-
386+
387387
final String[] localVarAccepts = {
388388
"text/plain"
389389
};
@@ -454,7 +454,7 @@ private ResponseSpec testQueryStyleFormExplodeFalseArrayIntegerRequestCreation(@
454454
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
455455

456456
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "query_object", queryObject));
457-
457+
458458
final String[] localVarAccepts = {
459459
"text/plain"
460460
};
@@ -525,7 +525,7 @@ private ResponseSpec testQueryStyleFormExplodeFalseArrayStringRequestCreation(@j
525525
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
526526

527527
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "query_object", queryObject));
528-
528+
529529
final String[] localVarAccepts = {
530530
"text/plain"
531531
};
@@ -596,7 +596,7 @@ private ResponseSpec testQueryStyleFormExplodeTrueArrayStringRequestCreation(@ja
596596
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
597597

598598
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "values", queryObject.getValues()));
599-
599+
600600
final String[] localVarAccepts = {
601601
"text/plain"
602602
};
@@ -672,7 +672,7 @@ private ResponseSpec testQueryStyleFormExplodeTrueObjectRequestCreation(@jakarta
672672
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
673673
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
674674
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
675-
675+
676676
final String[] localVarAccepts = {
677677
"text/plain"
678678
};
@@ -743,7 +743,7 @@ private ResponseSpec testQueryStyleFormExplodeTrueObjectAllOfRequestCreation(@ja
743743
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
744744

745745
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_object", queryObject));
746-
746+
747747
final String[] localVarAccepts = {
748748
"text/plain"
749749
};
@@ -814,9 +814,9 @@ private ResponseSpec testQueryStyleJsonSerializationObjectRequestCreation(@jakar
814814
final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<>();
815815
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<>();
816816

817-
queryParams.putAll(apiClient.parameterToMultiValueMap(null, "json_serialized_object_ref_string_query", jsonSerializedObjectRefStringQuery));
818-
queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "json_serialized_object_array_ref_string_query", jsonSerializedObjectArrayRefStringQuery));
819-
817+
queryParams.putAll(apiClient.parameterToMultiValueMapJson(null, "json_serialized_object_ref_string_query", jsonSerializedObjectRefStringQuery));
818+
queryParams.putAll(apiClient.parameterToMultiValueMapJson(ApiClient.CollectionFormat.valueOf("csv".toUpperCase(Locale.ROOT)), "json_serialized_object_array_ref_string_query", jsonSerializedObjectArrayRefStringQuery));
819+
820820
final String[] localVarAccepts = {
821821
"text/plain"
822822
};

samples/client/others/java/restclient-enum-in-multipart/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -437,6 +438,36 @@ public String parameterToString(Object param) {
437438
}
438439
}
439440

441+
/**
442+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
443+
* @param collectionFormat The format to convert to
444+
* @param name The name of the parameter
445+
* @param value The parameter's value
446+
* @return a Map containing the Json-serialized String value(s) of the input parameter
447+
*/
448+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
449+
Collection<?> valueCollection;
450+
if (value instanceof Collection) {
451+
valueCollection = (Collection<?>) value;
452+
} else {
453+
try {
454+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
455+
} catch (JsonProcessingException e) {
456+
throw new RuntimeException(e);
457+
}
458+
}
459+
460+
List<String> values = new ArrayList<>();
461+
for(Object o : valueCollection) {
462+
try {
463+
values.add(objectMapper.writeValueAsString(o));
464+
} catch (JsonProcessingException e) {
465+
throw new RuntimeException(e);
466+
}
467+
}
468+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
469+
}
470+
440471
/**
441472
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
442473
* @param collectionFormat The format to convert to

samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -436,6 +437,36 @@ public String parameterToString(Object param) {
436437
}
437438
}
438439

440+
/**
441+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
442+
* @param collectionFormat The format to convert to
443+
* @param name The name of the parameter
444+
* @param value The parameter's value
445+
* @return a Map containing the Json-serialized String value(s) of the input parameter
446+
*/
447+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
448+
Collection<?> valueCollection;
449+
if (value instanceof Collection) {
450+
valueCollection = (Collection<?>) value;
451+
} else {
452+
try {
453+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
454+
} catch (JsonProcessingException e) {
455+
throw new RuntimeException(e);
456+
}
457+
}
458+
459+
List<String> values = new ArrayList<>();
460+
for(Object o : valueCollection) {
461+
try {
462+
values.add(objectMapper.writeValueAsString(o));
463+
} catch (JsonProcessingException e) {
464+
throw new RuntimeException(e);
465+
}
466+
}
467+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
468+
}
469+
439470
/**
440471
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
441472
* @param collectionFormat The format to convert to

samples/client/others/java/webclient-sealedInterface/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -415,6 +416,36 @@ public String parameterToString(Object param) {
415416
}
416417
}
417418

419+
/**
420+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
421+
* @param collectionFormat The format to convert to
422+
* @param name The name of the parameter
423+
* @param value The parameter's value
424+
* @return a Map containing the Json-serialized String value(s) of the input parameter
425+
*/
426+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
427+
Collection<?> valueCollection;
428+
if (value instanceof Collection) {
429+
valueCollection = (Collection<?>) value;
430+
} else {
431+
try {
432+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
433+
} catch (JsonProcessingException e) {
434+
throw new RuntimeException(e);
435+
}
436+
}
437+
438+
List<String> values = new ArrayList<>();
439+
for(Object o : valueCollection) {
440+
try {
441+
values.add(objectMapper.writeValueAsString(o));
442+
} catch (JsonProcessingException e) {
443+
throw new RuntimeException(e);
444+
}
445+
}
446+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
447+
}
448+
418449
/**
419450
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
420451
* @param collectionFormat The format to convert to

samples/client/others/java/webclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -415,6 +416,36 @@ public String parameterToString(Object param) {
415416
}
416417
}
417418

419+
/**
420+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
421+
* @param collectionFormat The format to convert to
422+
* @param name The name of the parameter
423+
* @param value The parameter's value
424+
* @return a Map containing the Json-serialized String value(s) of the input parameter
425+
*/
426+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
427+
Collection<?> valueCollection;
428+
if (value instanceof Collection) {
429+
valueCollection = (Collection<?>) value;
430+
} else {
431+
try {
432+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
433+
} catch (JsonProcessingException e) {
434+
throw new RuntimeException(e);
435+
}
436+
}
437+
438+
List<String> values = new ArrayList<>();
439+
for(Object o : valueCollection) {
440+
try {
441+
values.add(objectMapper.writeValueAsString(o));
442+
} catch (JsonProcessingException e) {
443+
throw new RuntimeException(e);
444+
}
445+
}
446+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
447+
}
448+
418449
/**
419450
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
420451
* @param collectionFormat The format to convert to

samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package org.openapitools.client;
1515

16+
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.DeserializationFeature;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -436,6 +437,36 @@ public String parameterToString(Object param) {
436437
}
437438
}
438439

440+
/**
441+
* Converts a parameter to a {@link MultiValueMap} containing Json-serialized values for use in REST requests
442+
* @param collectionFormat The format to convert to
443+
* @param name The name of the parameter
444+
* @param value The parameter's value
445+
* @return a Map containing the Json-serialized String value(s) of the input parameter
446+
*/
447+
public MultiValueMap<String, String> parameterToMultiValueMapJson(CollectionFormat collectionFormat, String name, Object value) {
448+
Collection<?> valueCollection;
449+
if (value instanceof Collection) {
450+
valueCollection = (Collection<?>) value;
451+
} else {
452+
try {
453+
return parameterToMultiValueMap(collectionFormat, name, objectMapper.writeValueAsString(value));
454+
} catch (JsonProcessingException e) {
455+
throw new RuntimeException(e);
456+
}
457+
}
458+
459+
List<String> values = new ArrayList<>();
460+
for(Object o : valueCollection) {
461+
try {
462+
values.add(objectMapper.writeValueAsString(o));
463+
} catch (JsonProcessingException e) {
464+
throw new RuntimeException(e);
465+
}
466+
}
467+
return parameterToMultiValueMap(collectionFormat, name, "[" + StringUtils.collectionToDelimitedString(values, collectionFormat.separator) + "]");
468+
}
469+
439470
/**
440471
* Converts a parameter to a {@link MultiValueMap} for use in REST requests
441472
* @param collectionFormat The format to convert to

0 commit comments

Comments
 (0)