From 139b1e7aaae0021570a63f5a9618a819ac6531b6 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 24 Sep 2026 10:02:44 +0800 Subject: [PATCH 1/2] update samples --- samples/client/wildcard-accept-header/java/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/client/wildcard-accept-header/java/build.gradle b/samples/client/wildcard-accept-header/java/build.gradle index 181c3a201e08..ce09e960be4d 100644 --- a/samples/client/wildcard-accept-header/java/build.gradle +++ b/samples/client/wildcard-accept-header/java/build.gradle @@ -24,6 +24,10 @@ sourceSets { main.java.srcDirs = ['src/main/java'] } +ext { + jakarta_annotation_version = "1.3.5" +} + if(hasProperty('target') && target == 'android') { apply plugin: 'com.android.library' @@ -103,10 +107,6 @@ if(hasProperty('target') && target == 'android') { } } -ext { - jakarta_annotation_version = "1.3.5" -} - dependencies { implementation "com.google.code.findbugs:jsr305:3.0.2" implementation 'com.squareup.okhttp3:okhttp:4.12.0' From 8932249d21f828e5947a5325fa7a4f8dbaeeecbe Mon Sep 17 00:00:00 2001 From: Wiebren Braakman Date: Thu, 24 Sep 2026 05:26:01 +0200 Subject: [PATCH 2/2] [dart] fix: explode object query parameters (#24868) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: [dart] explode object query parameters A query parameter whose schema is an object and whose style/explode are left at their defaults — style: form, explode: true — must go on the wire as one parameter per entry, keyed by the property name alone. The dart client handed the whole map to _queryParams, which stringified it with Map.toString() into a single parameter (filter={tld: com, createdDate:gte: 2023-01-01}). The generated api now iterates an exploded map entry by entry at the call site; _queryParams is left alone, since it never receives style or explode and is still the right fallback for every other parameter. A free-form object is typed Object in dart and needs a cast to Map; a declared map does not. deepObject and explode: false objects keep their previous wire format, byte for byte. The new test fixture covers the four style/explode combinations that decide the wire format; the test fails without the template change. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01CxDNCjqJycKTfzVWg2SeTJ * fix: [dart] repeat the key per element for a collection in an exploded object An exploded form-style object query parameter handed each entry to _queryParams with an empty collection format, which defaults to csv, so a list value went out comma joined (tld=com%2Cnet) instead of once per element (tld=com&tld=net). A Set went out as its toString(), since _queryParams only expands a List, and a null element went out as an empty value. Each entry is now passed with the 'multi' collection format, and an Iterable value is turned into a List with its null elements dropped first, so the key repeats once per non-null element and an empty collection adds nothing. The closure parameter is typed dynamic so the Iterable check still compiles for a map with a declared value type. Co-Authored-By: Claude Opus 5 (1M context) * chore: [dart] trim the exploded query comment The shipped comment is one line now, without the implementation note. Fix the fixture description, which claimed four style/explode combinations where it covers three, and retitle the test. Co-Authored-By: Claude Opus 5.5 (1M context) * test: [dart] keep the shared fixture byte-identical with the other ports Co-Authored-By: Claude Opus 5.5 (1M context) --------- Co-authored-by: Claude Fable 5 --- .../src/main/resources/dart2/api.mustache | 16 +++++++++++ .../codegen/dart/DartClientCodegenTest.java | 28 +++++++++++++++++++ .../lib/api/fake_api.dart | 3 +- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index 1c995009e018..015bfb9ac1bd 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -67,7 +67,23 @@ class {{{classname}}} { {{^required}} if ({{{paramName}}} != null) { {{/required}} + {{#isMap}} + {{#isExplode}} + {{^isDeepObject}} + // form style, explode: one query parameter per entry, keyed by the property name; a collection repeats the key per non-null element + {{#isFreeFormObject}}({{{paramName}}} as Map){{/isFreeFormObject}}{{^isFreeFormObject}}{{{paramName}}}{{/isFreeFormObject}}.forEach((entryKey, dynamic entryValue) => queryParams.addAll(_queryParams('multi', entryKey.toString(), entryValue is Iterable ? entryValue.where((e) => e != null).toList() : entryValue))); + {{/isDeepObject}} + {{#isDeepObject}} queryParams.addAll(_queryParams('{{{collectionFormat}}}', '{{{baseName}}}', {{{paramName}}})); + {{/isDeepObject}} + {{/isExplode}} + {{^isExplode}} + queryParams.addAll(_queryParams('{{{collectionFormat}}}', '{{{baseName}}}', {{{paramName}}})); + {{/isExplode}} + {{/isMap}} + {{^isMap}} + queryParams.addAll(_queryParams('{{{collectionFormat}}}', '{{{baseName}}}', {{{paramName}}})); + {{/isMap}} {{^required}} } {{/required}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientCodegenTest.java index 2215908d3d65..301193c8fa63 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/DartClientCodegenTest.java @@ -137,6 +137,34 @@ public void testObjectArrayDoesNotUseListFromJson() throws Exception { TestUtils.assertFileContains(modelFile.toPath(), "cast"); } + @Test(description = "Verify a form style, exploded map query parameter goes on the wire one entry per parameter") + public void testExplodedObjectQueryParameter() throws Exception { + List files = generateDartNativeFromSpec( + "src/test/resources/3_0/exploded-object-query-param.yaml"); + + File apiFile = files.stream() + .filter(f -> f.getName().equals("default_api.dart")) + .findFirst() + .orElseThrow(() -> new AssertionError("default_api.dart not found in generated files")); + + // form style with explode - the default - puts every entry on the wire under its own + // property name. Handing the whole map to _queryParams stringifies it with + // Map.toString(), which is what used to happen. A collection value repeats the key per + // non-null element ('multi'). + TestUtils.assertFileContains(apiFile.toPath(), + "(filter as Map).forEach((entryKey, dynamic entryValue) => queryParams.addAll(_queryParams('multi', entryKey.toString(), entryValue is Iterable ? entryValue.where((e) => e != null).toList() : entryValue)));"); + TestUtils.assertFileNotContains(apiFile.toPath(), "_queryParams('', 'filter', filter)"); + + // a declared map behaves the same way, and needs no cast + TestUtils.assertFileContains(apiFile.toPath(), + "typedFilter.forEach((entryKey, dynamic entryValue) => queryParams.addAll(_queryParams('multi', entryKey.toString(), entryValue is Iterable ? entryValue.where((e) => e != null).toList() : entryValue)));"); + + // deepObject and form without explode both keep a single parameter + TestUtils.assertFileContains(apiFile.toPath(), + "_queryParams('', 'deepFilter', deepFilter)", + "_queryParams('', 'flatFilter', flatFilter)"); + } + @Test(description = "Enum properties with defaults should emit enum constructor, not string literal") public void testEnumDefaultUsesEnumConstructor() throws Exception { List files = generateDartNativeFromSpec( diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index c61373a87937..ab0713d278f6 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -1382,7 +1382,8 @@ class FakeApi { queryParams.addAll(_queryParams('csv', 'url', url)); queryParams.addAll(_queryParams('multi', 'context', context)); if (language != null) { - queryParams.addAll(_queryParams('', 'language', language)); + // form style, explode: one query parameter per entry, keyed by the property name; a collection repeats the key per non-null element + language.forEach((entryKey, dynamic entryValue) => queryParams.addAll(_queryParams('multi', entryKey.toString(), entryValue is Iterable ? entryValue.where((e) => e != null).toList() : entryValue))); } queryParams.addAll(_queryParams('', 'allowEmpty', allowEmpty));