diff --git a/swagger_parser/CHANGELOG.md b/swagger_parser/CHANGELOG.md index 562be08b..e42d251e 100644 --- a/swagger_parser/CHANGELOG.md +++ b/swagger_parser/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.10.4 +- Fix bug with `additionalProperties` ([#114](https://github.com/Carapacik/swagger_parser/issues/114)) + ## 1.10.3 - Add new config parameter `original_http_response`(only for dart) ([#115](https://github.com/Carapacik/swagger_parser/issues/115)) diff --git a/swagger_parser/lib/src/parser/parser.dart b/swagger_parser/lib/src/parser/parser.dart index 04c2fff1..441ea6d1 100644 --- a/swagger_parser/lib/src/parser/parser.dart +++ b/swagger_parser/lib/src/parser/parser.dart @@ -794,10 +794,11 @@ class OpenApiParser { (map.containsKey(_additionalPropertiesConst) && (map[_additionalPropertiesConst] is Map) && (map[_additionalPropertiesConst] as Map) - .isNotEmpty)) { + .isNotEmpty && + !(map[_additionalPropertiesConst] as Map) + .containsKey(_refConst))) { // false positive result - // ignore: unnecessary_null_checks - final (newName!, description) = protectName( + final (newName, description) = protectName( name ?? additionalName, uniqueIfNull: true, description: map[_descriptionConst]?.toString(), @@ -834,10 +835,10 @@ class OpenApiParser { ); } - if (_objectClasses.where((oc) => oc.name == newName.toPascal).isEmpty) { + if (_objectClasses.where((oc) => oc.name == newName!.toPascal).isEmpty) { _objectClasses.add( UniversalComponentClass( - name: newName.toPascal, + name: newName!.toPascal, imports: typeWithImports .where((e) => e.import != null) .map((e) => e.import!) @@ -849,7 +850,7 @@ class OpenApiParser { return ( type: UniversalType( - type: newName.toPascal, + type: newName!.toPascal, name: newName.toCamel, description: description, format: map.containsKey(_formatConst) @@ -935,16 +936,26 @@ class OpenApiParser { } // Type or ref else { - var type = map.containsKey(_typeConst) - ? map.containsKey(_refConst) && - map[_typeConst].toString() == _objectConst - ? _formatRef(map) - : map[_typeConst].toString() - : map.containsKey(_refConst) - ? _formatRef(map) - : _objectConst; - - var import = map.containsKey(_refConst) ? _formatRef(map) : null; + String? import; + String type; + + if (map.containsKey(_refConst)) { + import = _formatRef(map); + } else if (map.containsKey(_additionalPropertiesConst) && + map[_additionalPropertiesConst] is Map && + (map[_additionalPropertiesConst] as Map) + .containsKey(_refConst)) { + import = + _formatRef(map[_additionalPropertiesConst] as Map); + } + + if (map.containsKey(_typeConst)) { + type = import != null && map[_typeConst].toString() == _objectConst + ? import + : map[_typeConst].toString(); + } else { + type = import ?? _objectConst; + } if (import != null) { for (final replacementRule in _replacementRules) { diff --git a/swagger_parser/pubspec.yaml b/swagger_parser/pubspec.yaml index 93fa70d6..5a07a3e2 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.10.3 +version: 1.10.4 repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser homepage: https://omega-r.com topics: