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

Fix/map additional properties ref #153

Merged

Conversation

elenaferr0
Copy link
Contributor

This pull request solves an issue with generating maps. I have this json swagger v2: restapi.json which has a WrapperClass. As a property WrapperClass has a Map<String, ValueClass>, which is defined with this syntax. What was previosly generated was:

@JsonSerializable()
class WrapperClass {
  const WrapperClass({
    required this.map,
  });
  
  factory WrapperClass.fromJson(Map<String, Object?> json) => _$WrapperClassFromJson(json);
  
  final ValueClass map;

  Map<String, Object?> toJson() => _$WrapperClassToJson(this);
}

while the correct generated code is

@JsonSerializable()
class WrapperClass {
  const WrapperClass({
    required this.map,
  });
  
  factory WrapperClass.fromJson(Map<String, Object?> json) => _$WrapperClassFromJson(json);
  
  final Map<String, ValueClass> map;

  Map<String, Object?> toJson() => _$WrapperClassToJson(this);
}

@@ -158,6 +158,7 @@ extension UniversalTypeX on UniversalType {
if (nullable || (!isRequired && defaultValue == null)) {
sb.write('?');
}
print(sb.toString());
Copy link
Owner

Choose a reason for hiding this comment

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

Remove print

@Carapacik Carapacik added the bug Something isn't working label Jan 10, 2024
@Carapacik Carapacik self-requested a review January 10, 2024 13:11
@@ -487,6 +487,7 @@ void main() {
description: 'data',
jsonKey: 'data',
isRequired: false,
mapType: 'string',
Copy link
Owner

Choose a reason for hiding this comment

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

Write a separate test for this if it's not difficult

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added my json sample and wrote a test for swagger v2 additional properties

@Carapacik Carapacik self-requested a review January 11, 2024 09:31
@Carapacik Carapacik merged commit dd13676 into Carapacik:main Jan 11, 2024
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants