Skip to content

Commit 7bf4eaf

Browse files
authored
Fixes paths for functions with structured or collection-valued parameters (#203)
* Update In property value for structured and col-valued func. params * Replace parameter alias for structured and col-valued func. params with braces * Remove comment * Add workflow_dispatch * PR feedback
1 parent 5c8ef30 commit 7bf4eaf

File tree

5 files changed

+10
-21
lines changed

5 files changed

+10
-21
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
branches: [ master ]
2020
schedule:
2121
- cron: '32 2 * * 6'
22+
workflow_dispatch:
2223

2324
jobs:
2425
analyze:

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,13 @@ private string FunctionName(IEdmFunction function, OpenApiConvertSettings settin
139139
functionName.Append(function.FullName());
140140
}
141141
functionName.Append("(");
142-
143-
// Structured or collection-valued parameters are represented as a parameter alias in the path template
144-
// and the parameters array contains a Parameter Object for the parameter alias as a query option of type string.
142+
145143
int skip = function.IsBound ? 1 : 0;
146-
functionName.Append(String.Join(",", function.Parameters.Skip(skip).Select(p =>
144+
functionName.Append(string.Join(",", function.Parameters.Skip(skip).Select(p =>
147145
{
148146
string uniqueName = Utils.GetUniqueName(p.Name, parameters);
149-
if (p.Type.IsStructured() || p.Type.IsCollection())
150-
{
151-
return p.Name + "=@" + uniqueName;
152-
}
153-
else
154-
{
155-
var quote = p.Type.Definition.ShouldPathParameterBeQuoted(settings) ? "'" : string.Empty;
156-
return p.Name + $"={quote}{{{uniqueName}}}{quote}";
157-
}
147+
var quote = p.Type.Definition.ShouldPathParameterBeQuoted(settings) ? "'" : string.Empty;
148+
return p.Name + $"={quote}{{{uniqueName}}}{quote}";
158149
})));
159150

160151
functionName.Append(")");

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,14 @@ public static IList<OpenApiParameter> CreateParameters(this ODataContext context
8181
}
8282
}
8383

84-
OpenApiParameter parameter;
85-
// Structured or collection-valued parameters are represented as a parameter alias
86-
// in the path template and the parameters array contains a Parameter Object for
87-
// the parameter alias as a query option of type string.
84+
OpenApiParameter parameter;
8885
if (edmParameter.Type.IsStructured() ||
8986
edmParameter.Type.IsCollection())
9087
{
9188
parameter = new OpenApiParameter
9289
{
9390
Name = parameterNameMapping == null ? edmParameter.Name : parameterNameMapping[edmParameter.Name],
94-
In = ParameterLocation.Query, // as query option
91+
In = ParameterLocation.Path,
9592
Required = true,
9693

9794
// Create schema in the Content property to indicate that the parameters are serialized as JSON

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo
7575

7676
[Theory]
7777
[InlineData(true, true, "MyFunction(param={param})")]
78-
[InlineData(true, false, "MyFunction(entity=@entity,param={param})")]
78+
[InlineData(true, false, "MyFunction(entity={entity},param={param})")]
7979
[InlineData(false, true, "NS.MyFunction(param={param})")]
80-
[InlineData(false, false, "NS.MyFunction(entity=@entity,param={param})")]
80+
[InlineData(false, false, "NS.MyFunction(entity={entity},param={param})")]
8181
public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected)
8282
{
8383
// Arrange & Act

test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public void CreateParametersWorks()
407407
string json1 = parameter1.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
408408
string expectedPayload1 = $@"{{
409409
""name"": ""ids"",
410-
""in"": ""query"",
410+
""in"": ""path"",
411411
""description"": ""The URL-encoded JSON object"",
412412
""required"": true,
413413
""content"": {{

0 commit comments

Comments
 (0)