From be172ac8c65081f7adc3a2cea86380f4ceaeffbc Mon Sep 17 00:00:00 2001 From: Sancene <56795876+Sancene@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:08:51 +0300 Subject: [PATCH] excess import removed (#130) Co-authored-by: George --- swagger_parser/CHANGELOG.md | 4 ++++ swagger_parser/lib/src/parser/parser.dart | 12 +++++++++--- swagger_parser/pubspec.yaml | 2 +- swagger_parser/test/parser/data_classses_test.dart | 8 ++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/swagger_parser/CHANGELOG.md b/swagger_parser/CHANGELOG.md index 5571d31e..706e00ea 100644 --- a/swagger_parser/CHANGELOG.md +++ b/swagger_parser/CHANGELOG.md @@ -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)) diff --git a/swagger_parser/lib/src/parser/parser.dart b/swagger_parser/lib/src/parser/parser.dart index bb3a8dce..01e4d166 100644 --- a/swagger_parser/lib/src/parser/parser.dart +++ b/swagger_parser/lib/src/parser/parser.dart @@ -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) && + !(map[_additionalPropertiesConst] as Map) + .containsKey(r'$ref') ? 'string' : null; if (map.containsKey(_propertiesConst)) { @@ -860,7 +863,7 @@ class OpenApiParser { nullable: map[_nullableConst].toString().toBool(), isRequired: isRequired, ), - import: newName.toPascal, + import: null, ); } @@ -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) && + !(map[_additionalPropertiesConst] as Map) + .containsKey(r'$ref') ? 'string' : null; final defaultValue = map[_defaultConst]?.toString(); diff --git a/swagger_parser/pubspec.yaml b/swagger_parser/pubspec.yaml index 59133a1a..4ed11430 100644 --- a/swagger_parser/pubspec.yaml +++ b/swagger_parser/pubspec.yaml @@ -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: diff --git a/swagger_parser/test/parser/data_classses_test.dart b/swagger_parser/test/parser/data_classses_test.dart index 7663a390..800f95e7 100644 --- a/swagger_parser/test/parser/data_classses_test.dart +++ b/swagger_parser/test/parser/data_classses_test.dart @@ -453,7 +453,11 @@ 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); @@ -461,7 +465,7 @@ void main() { final expectedDataClasses = [ const UniversalComponentClass( name: 'Example', - imports: {'Data'}, + imports: {}, parameters: [ UniversalType( type: 'object',