Skip to content

Commit

Permalink
excess import removed (#130)
Browse files Browse the repository at this point in the history
Co-authored-by: George <[email protected]>
  • Loading branch information
Sancene and Sancene2 authored Oct 27, 2023
1 parent 502e414 commit be172ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.11.1
- Fixed ref component being wrongly labeled as map
- Fixed map components being assigned an import despite not needing one

## 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))
Expand Down
12 changes: 9 additions & 3 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,10 @@ class OpenApiParser {

// To detect is this entity is map or not
final mapType = map[_typeConst].toString() == _objectConst &&
map.containsKey(_additionalPropertiesConst)
map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(r'$ref')
? 'string'
: null;
if (map.containsKey(_propertiesConst)) {
Expand Down Expand Up @@ -860,7 +863,7 @@ class OpenApiParser {
nullable: map[_nullableConst].toString().toBool(),
isRequired: isRequired,
),
import: newName.toPascal,
import: null,
);
}

Expand Down Expand Up @@ -994,7 +997,10 @@ class OpenApiParser {

// To detect is this entity is map or not
final mapType = map[_typeConst].toString() == _objectConst &&
map.containsKey(_additionalPropertiesConst)
map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(r'$ref')
? '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.11.0
version: 1.11.1
repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser
homepage: https://omega-r.com
topics:
Expand Down
8 changes: 6 additions & 2 deletions swagger_parser/test/parser/data_classses_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,19 @@ void main() {
test('additionalProperties entity that should not parse to object test',
() async {
final schemaPath = p.join(
'test', 'parser', 'schemas', 'additional_properties_class.3.0.json');
'test',
'parser',
'schemas',
'additional_properties_class.3.0.json',
);
final configFile = schemaFile(schemaPath);
final schemaContent = configFile!.readAsStringSync();
final parser = OpenApiParser(schemaContent);
final dataClasses = parser.parseDataClasses().toList();
final expectedDataClasses = <UniversalDataClass>[
const UniversalComponentClass(
name: 'Example',
imports: {'Data'},
imports: {},
parameters: [
UniversalType(
type: 'object',
Expand Down

0 comments on commit be172ac

Please sign in to comment.