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-dio] Generated ToJson methods for models throws exception for json_serializable #20181

Open
3 of 6 tasks
Lymdun opened this issue Nov 25, 2024 · 0 comments
Open
3 of 6 tasks

Comments

@Lymdun
Copy link

Lymdun commented Nov 25, 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The generator produces invalid Dart code for nullable Map properties, causing compilation errors in serialization methods (ToJson) when using json_serializable.

openapi-generator version

7.10.0

OpenAPI declaration file content or url
type: object
required:
  - subject
properties:
  subject:
    type: string
  data:
    type: object
    additionalProperties:
      type: string
Steps to reproduce

Generated model ToJson code will look like that, while getting the following compilation error:

Error: Expected ')' before this.
      if (instance.data case final value?) 'data': value,
                        ^^^^
Map<String, dynamic> _$UsersMobileNotificationToJson(
        UsersMobileNotification instance) =>
    <String, dynamic>{
      'subject': instance.subject,
      if (instance.data case final value?) 'data': value,
    };
Suggest a fix

Looks like it is caused by latest update of json_serializable since its version isn't enforced.

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

1 participant