question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[dart-dio][client] Generated code for property that is array type with default value does not compile

See original GitHub issue

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?
Description

Support for default values was added in #8201 by @kuhnroyal. Now when array type with default value which is an empty array [] is in the spec, dart code that does not compile is generated:

pets:
  type: array
  items:
    $ref: '#/components/schemas/Pet'
  default: []

Error as follows:

A value of type 'List<dynamic>' can't be assigned to a variable of type 'ListBuilder<Pet>'.

Snippet of generated code causing the issue:

@nullable
@BuiltValueField(wireName: r'pets')
BuiltList<Pet> get pets;

static void _initializeBuilder(OrderBuilder b) => b
    ..pets = [] // <-- line causing error
    ..complete = false;
openapi-generator version

master

Steps to reproduce

You can reproduce the issue by running the dart-dio generator for this modified petstore example here

Related issues/PRs

#8201 by @kuhnroyal is where the issue appears to be introduced

@swipesight (2018/09) @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
adg-mhcommented, Jan 4, 2021

@kuhnroyal That was the petstore example I just cobbled in the extra bits to see how it would act. I don’t actually need that functionality now, I was just checking to see if it validated.

Haven’t tested yet but it looks like the fixes in your PR cover my case.

0reactions
kuhnroyalcommented, Jan 2, 2021

@adg-mh Where is this config from that you have there?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error message. "Props with type Object/Array must use a ...
There was no problem with the performance but I got a console error. [Vue warn]: Invalid default value for prop "multiselectKey": Props with ......
Read more >
Is Display the default property value in the class diagram ...
Is it possible to display the default property value ( true in my case) ... it would show up in the diagram but...
Read more >
Default Sizes and Values of Arrays - NI - National Instruments
Configuring an Array Control for Use in a VI. An array shell without a data object is undefined and has no data type....
Read more >
Features of setting the default value
Note: If the type of default value is not appropriate for the field type, the project will be generated but will not be...
Read more >
C# Guide: Automatic Default Values for Variables - Pluralsight
Variable Categories. There are three distinct types of variables that are automatically initialized with a default value based on their type.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found