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] Arrays of unspecified subtype default to non-nullable "Object" #498

Closed
point-source opened this issue Nov 14, 2022 · 1 comment · Fixed by #500
Closed

[BUG] Arrays of unspecified subtype default to non-nullable "Object" #498

point-source opened this issue Nov 14, 2022 · 1 comment · Fixed by #500
Assignees
Labels
bug Something isn't working Triage needed

Comments

@point-source
Copy link

Describe the bug
When generating code for a model with an array property which does not specify its subtype, the generated type is List<Object> which excludes null. Here is an example of a model definition:

      "MyModel": {
        "title": "MyModel",
        "type": "object",
        "properties": {
          "Rows": {
            "type": "array",
            "items": {
              "type": "array",
              "items": { }
            },
            "nullable": true
          }
        }
      }

here is the code that gets generated:

*.swagger.dart:

  @JsonKey(name: 'Rows', includeIfNull: false, defaultValue: <List<Object>>[])
  final List<List<Object>>? rows;

*.swagger.g.dart:

      rows: (json['Rows'] as List<dynamic>?)
              ?.map(
                  (e) => (e as List<dynamic>).map((e) => e as Object).toList())
              .toList() ??
          [],

To Reproduce
Please attach swagger and code snippet of generated value

Expected behavior
Since the api spec does not specify the subtype, it should probably be either dynamic or Object? like so:

*.swagger.dart:

  @JsonKey(name: 'Rows', includeIfNull: false, defaultValue: <List<Object?>>[])
  final List<List<Object?>>? rows;

*.swagger.g.dart:

      rows: (json['Rows'] as List<dynamic>?)
              ?.map(
                  (e) => (e as List<dynamic>).map((e) => e as Object?).toList())
              .toList() ??
          [],

OR

*.swagger.dart:

  @JsonKey(name: 'Rows', includeIfNull: false, defaultValue: <List<dynamic>>[])
  final List<List<dynamic>>? rows;

*.swagger.g.dart:

      rows: (json['Rows'] as List<dynamic>?)
              ?.map(
                  (e) => (e as List<dynamic>).toList())
              .toList() ??
          [],

Swagger specification link
See model example above

Library version used:
2.8.5

@Vovanella95
Copy link
Collaborator

@point-source make sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Triage needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants