Skip to content

Commit

Permalink
Revert "Fix bug when additionalProperties has ref." (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik authored Oct 20, 2023
1 parent 0c8f359 commit 08dbe10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
3 changes: 0 additions & 3 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
## 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: 16 additions & 27 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,10 @@ class OpenApiParser {
(map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
(map[_additionalPropertiesConst] as Map<String, dynamic>)
.isNotEmpty &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(_refConst))) {
.isNotEmpty)) {
// false positive result
final (newName, description) = protectName(
// ignore: unnecessary_null_checks
final (newName!, description) = protectName(
name ?? additionalName,
uniqueIfNull: true,
description: map[_descriptionConst]?.toString(),
Expand Down Expand Up @@ -835,10 +834,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 @@ -850,7 +849,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 @@ -936,26 +935,16 @@ class OpenApiParser {
}
// Type or ref
else {
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;
}
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;

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

0 comments on commit 08dbe10

Please sign in to comment.