Skip to content

Commit

Permalink
Fixed error with path-level parameters cause crash. (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
pattobrien authored Dec 12, 2023
1 parent 668c7b1 commit 5ad6271
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 23 additions & 2 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,21 @@ class OpenApiParser {
}
(_definitionFileContent[_pathsConst] as Map<String, dynamic>)
.forEach((path, pathValue) {
(pathValue as Map<String, dynamic>).forEach((key, requestPath) {
final pathValueMap = pathValue as Map<String, dynamic>;

// global parameters are defined at the path level (i.e. /users/{id})
final globalParameters = <UniversalRequestType>[];

if (pathValueMap.containsKey(_parametersConst)) {
final params = _version == OAS.v2
? parametersV2(pathValue)
: parametersV3(pathValue);
globalParameters.addAll(params);
}

pathValue.forEach((key, requestPath) {
// `servers` contains List<dynamic>
if (key == _serversConst) {
if (key == _serversConst || key == _parametersConst) {
return;
}

Expand All @@ -494,6 +506,15 @@ class OpenApiParser {
? parametersV2(requestPath)
: parametersV3(requestPath);

// Add global parameters that have not been overridden by local parameters
// defined at the request level.
parameters.addAll(
globalParameters.where(
(e) =>
parameters.every((p) => p.name != e.name && p.type != e.type),
),
);

// Build full description
final summary = requestPath[_summaryConst]?.toString().trim();
var description = requestPath[_descriptionConst]?.toString().trim();
Expand Down
1 change: 1 addition & 0 deletions swagger_parser/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ topics:
- codegen
- api
- json

environment:
sdk: ^3.0.0

Expand Down

0 comments on commit 5ad6271

Please sign in to comment.