Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/openapi-generator/src/main/resources/dart2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ public void testObjectArrayDoesNotUseListFromJson() throws Exception {
TestUtils.assertFileContains(modelFile.toPath(), "cast<Object>");
}

@Test(description = "Verify a form style, exploded map query parameter goes on the wire one entry per parameter")
public void testExplodedObjectQueryParameter() throws Exception {
List<File> 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<File> files = generateDartNativeFromSpec(
Expand Down
8 changes: 4 additions & 4 deletions samples/client/wildcard-accept-header/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Loading