Skip to content

Commit

Permalink
Fix bug when additionalProperties has ref. (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sancene authored Oct 20, 2023
2 parents e2c82ee + 0b392eb commit 0c8f359
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
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.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))

Expand Down
43 changes: 27 additions & 16 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,11 @@ class OpenApiParser {
(map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
(map[_additionalPropertiesConst] as Map<String, dynamic>)
.isNotEmpty)) {
.isNotEmpty &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.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(),
Expand Down Expand Up @@ -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!)
Expand All @@ -849,7 +850,7 @@ class OpenApiParser {

return (
type: UniversalType(
type: newName.toPascal,
type: newName!.toPascal,
name: newName.toCamel,
description: description,
format: map.containsKey(_formatConst)
Expand Down Expand Up @@ -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<String, dynamic> &&
(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(_refConst)) {
import =
_formatRef(map[_additionalPropertiesConst] as Map<String, dynamic>);
}

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) {
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.10.3
version: 1.10.4
repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser
homepage: https://omega-r.com
topics:
Expand Down

0 comments on commit 0c8f359

Please sign in to comment.