Skip to content

Commit

Permalink
Merge pull request #4026 from microsoft/bugfix/strings-error-mappings
Browse files Browse the repository at this point in the history
- fixes a bug where scalar error mappings would be generated even though it's not supported by the http request adapter
  • Loading branch information
baywet authored Jan 19, 2024
2 parents 9475e6e + 6c5f3cf commit 315d7b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed a bug where scalar error mappings would be generated even though it's not supported by the http request adapter. [#4018](https://github.com/microsoft/kiota/issues/4018)

## [1.10.1] - 2024-01-12

### Added
Expand Down
11 changes: 5 additions & 6 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,15 +1283,14 @@ private void AddErrorMappingToExecutorMethod(OpenApiUrlTreeNode currentNode, Ope
: modelsNamespace;
var errorType = CreateModelDeclarations(currentNode, errorSchema, operation, parentElement, $"{errorCode}Error", response: response);
if (errorType is CodeType codeType &&
codeType.TypeDefinition is CodeClass codeClass &&
!codeClass.IsErrorDefinition)
codeType.TypeDefinition is CodeClass codeClass)
{
codeClass.IsErrorDefinition = true;
if (!codeClass.IsErrorDefinition)
codeClass.IsErrorDefinition = true;
executorMethod.AddErrorMapping(errorCode, errorType);
}
if (errorType is null)
logger.LogWarning("Could not create error type for {Error} in {Operation}", errorCode, operation.OperationId);
else
executorMethod.AddErrorMapping(errorCode, errorType);
logger.LogWarning("Could not create error type for {Error} in {Operation}", errorCode, operation.OperationId);
}
}
private (CodeTypeBase?, CodeTypeBase?) GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass, OperationType operationType)
Expand Down
14 changes: 14 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,19 @@ public void AddsErrorMapping()
}
}
},
["402"] = new OpenApiResponse
{
Content =
{
["application/json"] = new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "string"
}
}
}
},
["401"] = new OpenApiResponse
{
Content =
Expand Down Expand Up @@ -2083,6 +2096,7 @@ public void AddsErrorMapping()
var keys = executorMethod.ErrorMappings.Select(x => x.Key).ToHashSet();
Assert.Contains("4XX", keys);
Assert.Contains("401", keys);
Assert.DoesNotContain("402", keys);
Assert.Contains("5XX", keys);
var errorType401 = codeModel.FindChildByName<CodeClass>("tasks401Error");
Assert.NotNull(errorType401);
Expand Down

0 comments on commit 315d7b0

Please sign in to comment.