Skip to content

Commit

Permalink
Fixed error with ref in a case other than PascalCase #139
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Nov 17, 2023
1 parent 66d21c6 commit 24a22b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 1.12.1
- Fixed error with `ref` in a case other than PascalCase ([#139](https://github.com/Carapacik/swagger_parser/issues/139))

## 1.12.0
- Add new config parameter `export_file`

## 1.11.3
- Fix: annotating client methods with the first specified content type header in OpenAPI V2 schemas if the specified one is not the default.
- Fixed error with annotating client methods with the first specified content type header in OpenAPI V2 schemas if the specified one is not the default.

## 1.11.2
- Add description of request parameters to the code docs
Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dev_dependencies:
# build_runner: ^2.4.6
# freezed: ^2.4.5 # for freezed
# json_serializable: ^6.7.1
# retrofit_generator: ^8.0.2
# retrofit_generator: ^8.0.4
swagger_parser:
```
Expand Down
16 changes: 8 additions & 8 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class OpenApiParser {
}

if (value.containsKey(_allOfConst)) {
for (final map in value[_allOfConst] as List) {
for (final map in value[_allOfConst] as List<dynamic>) {
if ((map as Map<String, dynamic>).containsKey(_refConst)) {
var ref = _formatRef(map);
for (final replacementRule in _replacementRules) {
Expand Down Expand Up @@ -716,13 +716,12 @@ class OpenApiParser {
: 'client';

/// Format `$ref` type
String _formatRef(Map<String, dynamic> map, {bool useSchema = false}) => p
.basename(
String _formatRef(Map<String, dynamic> map, {bool useSchema = false}) =>
p.basename(
useSchema
? (map[_schemaConst] as Map<String, dynamic>)[_refConst].toString()
: map[_refConst].toString(),
)
.toPascal;
);

/// Find type of map
({UniversalType type, String? import}) _findType(
Expand Down Expand Up @@ -991,13 +990,14 @@ class OpenApiParser {
String? import;
String type;
if (map.containsKey(_refConst)) {
import = _formatRef(map);
import = _formatRef(map).toPascal;
} 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>);
_formatRef(map[_additionalPropertiesConst] as Map<String, dynamic>)
.toPascal;
}

if (map.containsKey(_typeConst)) {
Expand All @@ -1019,7 +1019,7 @@ class OpenApiParser {
map.containsKey(_additionalPropertiesConst) &&
(map[_additionalPropertiesConst] is Map<String, dynamic>) &&
!(map[_additionalPropertiesConst] as Map<String, dynamic>)
.containsKey(r'$ref')
.containsKey(_refConst)
? '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.12.0
version: 1.12.1
repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser
homepage: https://omega-r.com
topics:
Expand Down

0 comments on commit 24a22b3

Please sign in to comment.