Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Dart] Nullable values are still in required list, and fail on assertion in the serializer #20296

Open
3 of 5 tasks
isaac-merkos opened this issue Dec 11, 2024 · 1 comment

Comments

@isaac-merkos
Copy link

isaac-merkos commented Dec 11, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

I am expecting nullable fields to allow values, my spec allows for nullable values in certain fields but when I actually run the queries I am getting an assertion error

@uchijo
Copy link

uchijo commented Dec 22, 2024

Hi, I'm facing exactly same issue.
After seeing the generated code, I figured out that it might be caused by required but nullable value as you mention.
The tool generates code like this in fromJson method:

      assert(() {
        requiredKeys.forEach((key) {
          assert(json.containsKey(key), 'Required key "SomeModel[$key]" is missing from JSON.');
          assert(json[key] != null, 'Required key "SomeModel[$key]" has a null value in JSON.'); // this code is not good. it ignores exisitence of required but nullable value.
        });
        return true;
      }());

I will look into generator code and see if I can fix it.

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

No branches or pull requests

2 participants