Skip to content

Fix #24603 (anyOf serialization in dart-dio) - #24605

Open
bw-flagship wants to merge 2 commits into
OpenAPITools:masterfrom
FlagshipApps:feature/fix-anyof-dartdio
Open

Fix #24603 (anyOf serialization in dart-dio)#24605
bw-flagship wants to merge 2 commits into
OpenAPITools:masterfrom
FlagshipApps:feature/fix-anyof-dartdio

Conversation

@bw-flagship

@bw-flagship bw-flagship commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #24603

@jaumard @amondnet @sbu-WBT @kuhnroyal @agilob @ahmednfwela

Regenerating the samples introduced these blanklines. When I did not do that, the checks would fail. Not sure whether this is acceptable.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes anyOf serialization in dart-dio built_value by using declared types to build FullType parameters. Prevents RangeError when the selected variant is not the first.

  • Bug Fixes
    • Use anyOf.types instead of anyOf.valueTypes in class_serializer.mustache when building FullType(AnyOf, ...).
    • Add a regression test and a small anyOf primitive schema; regenerate dart-dio samples.

Written for commit 22f3fec. Summary will update on new commits.

Review in cubic

@bw-flagship
bw-flagship marked this pull request as ready for review August 4, 2026 10:59

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 84 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/dio/DartDioClientCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/dio/DartDioClientCodegenTest.java:246">
P3: The regression test does not exercise the reported RangeError path: it only checks generated source text, so it cannot verify that serializing the second anyOf variant succeeds at runtime. Adding a generated-Dart integration test that constructs the second variant and invokes the standard serializers would make the regression test cover the actual failure.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Path fieldValue = output.toPath().resolve("lib/src/model/field_value.dart");

TestUtils.assertFileContains(fieldValue,
"FullType(AnyOf, anyOf.types.map((type) => FullType(type)).toList())");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The regression test does not exercise the reported RangeError path: it only checks generated source text, so it cannot verify that serializing the second anyOf variant succeeds at runtime. Adding a generated-Dart integration test that constructs the second variant and invokes the standard serializers would make the regression test cover the actual failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/dio/DartDioClientCodegenTest.java, line 246:

<comment>The regression test does not exercise the reported RangeError path: it only checks generated source text, so it cannot verify that serializing the second anyOf variant succeeds at runtime. Adding a generated-Dart integration test that constructs the second variant and invokes the standard serializers would make the regression test cover the actual failure.</comment>

<file context>
@@ -215,6 +215,39 @@ public void testOptionalNonNullablePropertyDeserializesAsNullable() throws IOExc
+        Path fieldValue = output.toPath().resolve("lib/src/model/field_value.dart");
+
+        TestUtils.assertFileContains(fieldValue,
+                "FullType(AnyOf, anyOf.types.map((type) => FullType(type)).toList())");
+        TestUtils.assertFileNotContains(fieldValue,
+                "FullType(AnyOf, anyOf.valueTypes.map((type) => FullType(type)).toList())");
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Dart Dio] AnyOf serialization fails for non-zero value indexes

1 participant