Skip to content

Commit c0a7652

Browse files
[java][doc] Fix Makdown examples: wrong collection type used to initialize Sets (#23160)
* Fix markdown example generation: Arrays.asList() was used to instanciate Sets without checking 'uniqueItems' * Update generated samples
1 parent c085974 commit c0a7652

30 files changed

Lines changed: 38 additions & 30 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,16 @@ public void setParameterExampleValue(CodegenParameter p) {
17691769
innerExample = p.items.defaultValue;
17701770
}
17711771
example = "Arrays.asList(" + innerExample + ")";
1772+
if (p.uniqueItems) {
1773+
example = "new LinkedHashSet<>(" + example + ")";
1774+
}
17721775
} else {
1773-
example = "Arrays.asList()";
1776+
if (p.uniqueItems) {
1777+
example = "new LinkedHashSet<>()";
1778+
}
1779+
else {
1780+
example = "Arrays.asList()";
1781+
}
17741782
}
17751783
} else if (Boolean.TRUE.equals(p.isMap)) {
17761784
example = "new HashMap()";

samples/client/petstore/java-helidon-client/v3/se/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public class Example {
261261
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
262262

263263
PetApi apiInstance = new PetApi(defaultClient);
264-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
264+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
265265
try {
266266
Set<Pet> result = apiInstance.findPetsByTags(tags);
267267
System.out.println(result);

samples/client/petstore/java-helidon-client/v4/se/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public class Example {
261261
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
262262

263263
PetApi apiInstance = new PetApi(defaultClient);
264-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
264+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
265265
try {
266266
Set<Pet> result = apiInstance.findPetsByTags(tags);
267267
System.out.println(result);

samples/client/petstore/java/apache-httpclient/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public class Example {
261261
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
262262

263263
PetApi apiInstance = new PetApi(defaultClient);
264-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
264+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
265265
try {
266266
Set<Pet> result = apiInstance.findPetsByTags(tags);
267267
System.out.println(result);

samples/client/petstore/java/google-api-client/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public class Example {
257257
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
258258

259259
PetApi apiInstance = new PetApi(defaultClient);
260-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
260+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
261261
try {
262262
Set<Pet> result = apiInstance.findPetsByTags(tags);
263263
System.out.println(result);

samples/client/petstore/java/jersey2-java8-localdatetime/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public class Example {
254254
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
255255

256256
PetApi apiInstance = new PetApi(defaultClient);
257-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
257+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
258258
try {
259259
Set<Pet> result = apiInstance.findPetsByTags(tags);
260260
System.out.println(result);

samples/client/petstore/java/jersey2-java8/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public class Example {
254254
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
255255

256256
PetApi apiInstance = new PetApi(defaultClient);
257-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
257+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
258258
try {
259259
Set<Pet> result = apiInstance.findPetsByTags(tags);
260260
System.out.println(result);

samples/client/petstore/java/microprofile-rest-client-3.0-jackson/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public class Example {
263263
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
264264

265265
PetApi apiInstance = new PetApi(defaultClient);
266-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
266+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
267267
try {
268268
Set<Pet> result = apiInstance.findPetsByTags(tags);
269269
System.out.println(result);

samples/client/petstore/java/microprofile-rest-client-3.0/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public class Example {
263263
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
264264

265265
PetApi apiInstance = new PetApi(defaultClient);
266-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
266+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
267267
try {
268268
Set<Pet> result = apiInstance.findPetsByTags(tags);
269269
System.out.println(result);

samples/client/petstore/java/microprofile-rest-client/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public class Example {
263263
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
264264

265265
PetApi apiInstance = new PetApi(defaultClient);
266-
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
266+
Set<String> tags = new LinkedHashSet<>(); // Set<String> | Tags to filter by
267267
try {
268268
Set<Pet> result = apiInstance.findPetsByTags(tags);
269269
System.out.println(result);

0 commit comments

Comments
 (0)