Skip to content

Commit 226173f

Browse files
author
Andrew Omondi
committed
fix: excessive path escaping
1 parent 9348dcd commit 226173f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Fixed a bug where TypeScript would not properly build URIs with uppercase first characters query parameter names.[#5382](https://github.com/microsoft/kiota/issues/5382)
2525
- Fixed a bug where the description special characters are encoded. [5286](https://github.com/microsoft/kiota/issues/5286)
2626
- Fixed a bug where python constructor parameters are being cast to strings leading to bugs as the types is unknown on graph call. [microsoftgraph/msgraph-sdk-python#165](https://github.com/microsoftgraph/msgraph-sdk-python/issues/165)
27+
- Fixed a bug where child path segment from single parameter path segment would be incorrectly escaped. [#4814](https://github.com/microsoft/kiota/issues/4814)
2728

2829
## [1.18.0] - 2024-09-05
2930

src/Kiota.Builder/KiotaBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ private void CreateRequestBuilderClass(CodeNamespace currentNamespace, OpenApiUr
634634
{
635635
var propIdentifier = child.GetNavigationPropertyName(config.StructuredMimeTypes);
636636
var propType = child.GetNavigationPropertyName(config.StructuredMimeTypes, child.DoesNodeBelongToItemSubnamespace() ? ItemRequestBuilderSuffix : RequestBuilderSuffix);
637-
if (child.Path.EndsWith(OpenApiUrlTreeNodeExtensions.ReservedItemName, StringComparison.OrdinalIgnoreCase))
637+
if (child.Segment.Equals(OpenApiUrlTreeNodeExtensions.ReservedItemName, StringComparison.OrdinalIgnoreCase) && !child.DoesNodeBelongToItemSubnamespace())
638638
propType = propType.Replace(OpenApiUrlTreeNodeExtensions.ReservedItemName, OpenApiUrlTreeNodeExtensions.ReservedItemNameEscaped, StringComparison.OrdinalIgnoreCase);
639639

640640
if (child.IsPathSegmentWithSingleSimpleParameter())

tests/Kiota.Builder.Tests/KiotaBuilderTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ await File.WriteAllTextAsync(tempFilePath, @$"openapi: 3.0.1
256256
application/json:
257257
schema:
258258
$ref: '#/components/schemas/MediaResponseModel'
259+
/media/item/{{id}}/nestedItem:
260+
get:
261+
parameters:
262+
- name: id
263+
in: path
264+
required: true
265+
schema:
266+
type: string
267+
responses:
268+
'200':
269+
content:
270+
application/json:
271+
schema:
272+
$ref: '#/components/schemas/MediaResponseModel'
259273
components:
260274
schemas:
261275
MediaResponseModel:
@@ -308,6 +322,10 @@ await File.WriteAllTextAsync(tempFilePath, @$"openapi: 3.0.1
308322
var modelsNS = codeModel.FindNamespaceByName("ApiSdk.models");
309323
Assert.NotNull(modelsNS);
310324
Assert.NotNull(modelsNS.FindChildByName<CodeClass>("MediaResponseModel", false));
325+
var nestedNestedItemProperty =
326+
nestedItemRequestBuilder.FindChildByName<CodeProperty>("NestedItem", false);
327+
Assert.NotNull(nestedNestedItemProperty);
328+
Assert.Equal("NestedItemRequestBuilder", nestedNestedItemProperty.Type.Name, StringComparer.OrdinalIgnoreCase);
311329
}
312330
private readonly HttpClient _httpClient = new();
313331
[Fact]

0 commit comments

Comments
 (0)