Skip to content

Commit 8c77094

Browse files
Ensure no single quotes are added to URL path parameters of temporal type (#287)
* Do not add single quotes to URL Path parameters of temporal type * Update release notes * Add tests to ensure no single quotes are added to URL path parameters of temporal type Co-authored-by: Vincent Biret <[email protected]>
1 parent 9ccac16 commit 8c77094

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/EdmTypeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static bool ShouldPathParameterBeQuoted(this IEdmType edmType, OpenApiCon
2828
return edmType.TypeKind switch
2929
{
3030
EdmTypeKind.Enum => true,
31-
EdmTypeKind.Primitive when edmType.IsString() || edmType.IsTemporal() => true,
31+
EdmTypeKind.Primitive when edmType.IsString() => true,
3232
_ => false,
3333
};
3434
}

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.2.0-preview1</Version>
18+
<Version>1.2.0-preview2</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
2323
<PackageReleaseNotes>
2424
- Use convert setting to toggle between referencing @odata.count and @odata.nextLink #282
25+
- Fixes URL Path parameters of type datetime generated as strings with quotes #262
2526
</PackageReleaseNotes>
2627
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
2728
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.OData.Edm;
99
using Microsoft.OData.Edm.Csdl;
1010
using Microsoft.OpenApi.Extensions;
11+
using Microsoft.OpenApi.Models;
1112
using Microsoft.OpenApi.OData.Edm;
1213
using Microsoft.OpenApi.OData.Tests;
1314
using Xunit;
@@ -228,7 +229,7 @@ public void CreateOperationForEdmFunctionWithTypeCastReturnsCorrectOperationId(b
228229
new ODataKeySegment(customer),
229230
new ODataTypeCastSegment(vipCustomer),
230231
new ODataOperationSegment(function));
231-
232+
232233
// Act
233234
var operation = _operationHandler.CreateOperation(context, path);
234235

@@ -445,5 +446,38 @@ public void CreateOperationForEdmFunctionWithCollectionReturnTypeContainsXMsPage
445446
Assert.False(operation.Extensions.ContainsKey(Common.Constants.xMsPageable));
446447
}
447448
}
449+
450+
[Fact]
451+
public void CreateOperationForFunctionWithDateTimeParametersReturnsCorrectPathItemName()
452+
{
453+
// Arrange
454+
IEdmModel model = EdmModelHelper.GraphBetaModel;
455+
OpenApiConvertSettings settings = new()
456+
{
457+
AddSingleQuotesForStringParameters = true,
458+
};
459+
ODataContext context = new(model, settings);
460+
461+
IEdmFunction function = model.SchemaElements.OfType<IEdmFunction>()
462+
.FirstOrDefault(x => x.Name == "getPrinterUsageSummary");
463+
Assert.NotNull(function); // guard
464+
465+
IEdmEntityContainer container = model.SchemaElements.OfType<IEdmEntityContainer>().First();
466+
IEdmSingleton reports = container.FindSingleton("reports");
467+
468+
ODataPath path = new(new ODataNavigationSourceSegment(reports),
469+
new ODataOperationSegment(function));
470+
471+
// Act
472+
OpenApiOperation operation = _operationHandler.CreateOperation(context, path);
473+
string pathItemName = path.GetPathItemName();
474+
475+
// Assert
476+
Assert.NotNull(operation);
477+
Assert.Equal("/reports/microsoft.graph.getPrinterUsageSummary(printerId={printerId},periodStart={periodStart},periodEnd={periodEnd})", pathItemName);
478+
Assert.Equal("Usage: periodStart={periodStart}", operation.Parameters.First(x => x.Name == "periodStart").Description);
479+
Assert.Equal("Usage: periodEnd={periodEnd}", operation.Parameters.First(x => x.Name == "periodEnd").Description);
480+
481+
}
448482
}
449483
}

0 commit comments

Comments
 (0)