Skip to content

Fixes paths for functions with structured or collection-valued parameters #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
branches: [ master ]
schedule:
- cron: '32 2 * * 6'
workflow_dispatch:

jobs:
analyze:
Expand Down
17 changes: 4 additions & 13 deletions src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,13 @@ private string FunctionName(IEdmFunction function, OpenApiConvertSettings settin
functionName.Append(function.FullName());
}
functionName.Append("(");

// Structured or collection-valued parameters are represented as a parameter alias in the path template
// and the parameters array contains a Parameter Object for the parameter alias as a query option of type string.

int skip = function.IsBound ? 1 : 0;
functionName.Append(String.Join(",", function.Parameters.Skip(skip).Select(p =>
functionName.Append(string.Join(",", function.Parameters.Skip(skip).Select(p =>
{
string uniqueName = Utils.GetUniqueName(p.Name, parameters);
if (p.Type.IsStructured() || p.Type.IsCollection())
{
return p.Name + "=@" + uniqueName;
}
else
{
var quote = p.Type.Definition.ShouldPathParameterBeQuoted(settings) ? "'" : string.Empty;
return p.Name + $"={quote}{{{uniqueName}}}{quote}";
}
var quote = p.Type.Definition.ShouldPathParameterBeQuoted(settings) ? "'" : string.Empty;
return p.Name + $"={quote}{{{uniqueName}}}{quote}";
})));

functionName.Append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,14 @@ public static IList<OpenApiParameter> CreateParameters(this ODataContext context
}
}

OpenApiParameter parameter;
// Structured or collection-valued parameters are represented as a parameter alias
// in the path template and the parameters array contains a Parameter Object for
// the parameter alias as a query option of type string.
OpenApiParameter parameter;
if (edmParameter.Type.IsStructured() ||
edmParameter.Type.IsCollection())
{
parameter = new OpenApiParameter
{
Name = parameterNameMapping == null ? edmParameter.Name : parameterNameMapping[edmParameter.Name],
In = ParameterLocation.Query, // as query option
In = ParameterLocation.Path,
Required = true,

// Create schema in the Content property to indicate that the parameters are serialized as JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo

[Theory]
[InlineData(true, true, "MyFunction(param={param})")]
[InlineData(true, false, "MyFunction(entity=@entity,param={param})")]
[InlineData(true, false, "MyFunction(entity={entity},param={param})")]
[InlineData(false, true, "NS.MyFunction(param={param})")]
[InlineData(false, false, "NS.MyFunction(entity=@entity,param={param})")]
[InlineData(false, false, "NS.MyFunction(entity={entity},param={param})")]
public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected)
{
// Arrange & Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public void CreateParametersWorks()
string json1 = parameter1.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
string expectedPayload1 = $@"{{
""name"": ""ids"",
""in"": ""query"",
""in"": ""path"",
""description"": ""The URL-encoded JSON object"",
""required"": true,
""content"": {{
Expand Down