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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.14.1
- Removed check that would avoid generating a map when additional properties has a `$ref` value

## 1.14.0
- Fixed error with empty content type
- Fixed retrofit template
Expand Down
3 changes: 2 additions & 1 deletion swagger_parser/lib/src/generator/models/universal_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class UniversalType {

@override
String toString() =>
'UniversalType(\ntype: $type,\nname: $name,\ndescription: $description,\nformat: $format,\njsonKey: $jsonKey,\ndefaultValue: $defaultValue,\nisRequired: $isRequired,\nenumType: $enumType,\narrayDepth: $arrayDepth,\nnullable: $nullable\n)';
'UniversalType(\ntype: $type,\nname: $name,\ndescription: $description,\nformat: $format,\njsonKey: $jsonKey,\ndefaultValue: $defaultValue,\nisRequired: $isRequired,\nenumType: $enumType,\narrayDepth: $arrayDepth,\nnullable: $nullable\n, mapType: $mapType\n)';
}

/// Converts [UniversalType] to type from specified language
Expand All @@ -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

return sb.toString();
}

Expand Down
4 changes: 1 addition & 3 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,7 @@ class OpenApiParser {
// To detect is this entity is map or not
final mapType = map[_typeConst].toString() == _objectConst &&
map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(_refConst)
(map[_additionalPropertiesConst] is Map<String, dynamic>)
? 'string'
: null;
final defaultValue = map[_defaultConst]?.toString();
Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: swagger_parser
description: Package that generates REST clients and data classes from OpenApi definition file
version: 1.14.0
version: 1.14.1
repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser
homepage: https://omega-r.com
topics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

),
],
),
Expand Down