Skip to content

Commit

Permalink
Include verb in gRPC JSON transcoding swagger path (dotnet#47165)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Mar 13, 2023
1 parent 9b3e79d commit 09e9ed7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ private static string ResolvePath(HttpRoutePattern httpRoutePattern, Dictionary<
sb.Append(httpRoutePattern.Segments[i]);
}
}
if (httpRoutePattern.Verb != null)
{
sb.Append(':');
sb.Append(httpRoutePattern.Verb);
}
return sb.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,27 @@ public void KnownTypes_AllQueryFields()
Assert.Equal("integer", operation.Parameters[2].Schema.Type);
Assert.Equal("int32", operation.Parameters[2].Schema.Format);
}

[Fact]
public void Verb()
{
// Arrange & Act
var swagger = OpenApiTestHelpers.GetOpenApiDocument<ParametersService>(_testOutputHelper);

// Assert
var path1 = swagger.Paths["/v1/parameters10/{parameterInt}:one"];
AssertParams(path1);
var path2 = swagger.Paths["/v1/parameters10/{parameterInt}:two"];
AssertParams(path2);

static void AssertParams(OpenApiPathItem path)
{
Assert.True(path.Operations.TryGetValue(OperationType.Get, out var operation));
Assert.Equal(2, operation.Parameters.Count);
Assert.Equal(ParameterLocation.Path, operation.Parameters[0].In);
Assert.Equal("parameterInt", operation.Parameters[0].Name);
Assert.Equal(ParameterLocation.Query, operation.Parameters[1].In);
Assert.Equal("parameterString", operation.Parameters[1].Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ service Parameters {
get: "/v1/parameters9"
};
}

rpc DemoParametersTenOne (RequestOne) returns (ParamResponse) {
option (google.api.http) = {
get: "/v1/parameters10/{parameter_int}:one"
};
}

rpc DemoParametersTenTwo (RequestOne) returns (ParamResponse) {
option (google.api.http) = {
get: "/v1/parameters10/{parameter_int}:two"
};
}
}

message RequestOne {
Expand Down

0 comments on commit 09e9ed7

Please sign in to comment.