Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
StarProxima committed Oct 25, 2023
1 parent 1d01d01 commit 86f1775
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.11.0
- Added unknown value to all enums to maintain backwards compatibility when adding new values on the backend
- Add new config parameter `unknown_enum_value` (dart only) ([#106](https://github.com/Carapacik/swagger_parser/issues/106))
- Support String values with spaces for enums ([#127](https://github.com/Carapacik/swagger_parser/issues/127))

## 1.10.6
- Fixed map objects parsing as separate entities ([#124](https://github.com/Carapacik/swagger_parser/issues/124))
Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/lib/src/utils/type_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ String uniqueName({bool isEnum = false}) {
return name;
}

final _enumNameRegExp = RegExp(r'^[a-zA-Z\d_-]*$');
final _enumNameRegExp = RegExp(r'^[a-zA-Z\d_-\s]*$');
final _startWithNumberRegExp = RegExp(r'^-?\d+');

/// Protect default enum value from incorrect symbols, keywords, etc.
Expand Down
11 changes: 9 additions & 2 deletions swagger_parser/test/generator/data_classes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ class ClassName with _$ClassName {
'3item_three',
'4ITEM-FOUR',
'5иллегалчарактер',
'6 item six',
},
),
),
Expand Down Expand Up @@ -1178,7 +1179,10 @@ enum EnumNameStringWithLeadingNumbers {
/// Incorrect name has been replaced. Original name: `5иллегалчарактер`.
@JsonValue('5иллегалчарактер')
undefined0;
undefined0,
@JsonValue('6 item six')
value6ItemSix;
}
''';

Expand Down Expand Up @@ -1357,7 +1361,7 @@ enum KeywordsName {
name: 'EnumNameString',
type: 'string',
items: UniversalEnumItem.listFromNames(
{'itemOne', 'ItemTwo', 'item_three', 'ITEM-FOUR'},
{'itemOne', 'ItemTwo', 'item_three', 'ITEM-FOUR', 'Item five'},
),
),
];
Expand Down Expand Up @@ -1414,6 +1418,9 @@ enum EnumNameString {
@JsonValue('ITEM-FOUR')
itemFour('ITEM-FOUR'),
@JsonValue('Item five')
itemFive('Item five'),
/// Default value for all unparsed values, allows backward compatibility when adding new values on the backend.
$unknown(null);
Expand Down

0 comments on commit 86f1775

Please sign in to comment.