aws / aws-lambda-dotnet

Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Apache License 2.0
1.57k stars 479 forks source link

Parameters to lambda functions named `request` cause source generators to fail #1157

Closed PeterKneale closed 2 years ago

PeterKneale commented 2 years ago

Describe the bug

When naming a parameter to a lambda function request, the source generators fail. request is such common name for a single request parameter that others are bound to hit this issue.

Expected Behavior

I expect the below signature to be valid

    [LambdaFunction]
    [HttpApi(LambdaHttpMethod.Post, "/stores")]
    public async Task<StoreDto> Execute([FromBody] CreateStoreRequest request, ILambdaContext context)

Current Behavior

Using this signature results in an error when compiling

    [LambdaFunction]
    [HttpApi(LambdaHttpMethod.Post, "/stores")]
    public async Task<StoreDto> Execute([FromBody] CreateStoreRequest request, ILambdaContext context)

1>........\Stores\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\CreateStore_Execute_Generated.g.cs(40,106): Error CS1061 : 'CreateStoreRequest' does not contain a definition for 'Body' and no accessible extension method 'Body' accepting a first argument of type 'CreateStoreRequest' could be found (are you missing a using directive or an assembly reference?)

1>........\Stores\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\CreateStore_Execute_Generated.g.cs(44,55): Error CS1061 : 'CreateStoreRequest' does not contain a definition for 'Body' and no accessible extension method 'Body' accepting a first argument of type 'CreateStoreRequest' could be found (are you missing a using directive or an assembly reference?)

1>------- Finished building project: Stores. Succeeded: False. Errors: 3.



### Reproduction Steps

Rename a lambda function parameter to `request` and attempt to build

### Possible Solution

Use something less common in the source generator? I dont know what a recommended strategy is for preventing clashes

### Additional Information/Context
- Clicking on the errorr in the "build failed" tab fails to navigate  anywhere causing confusion . Presumably because the error is occuring in the generator, not the solution

### AWS .NET SDK and/or Package version used

Amazon.Lambda.Annotations

### Targeted .NET Platform

.net 6

### Operating System and version

windows 10 (Visual Studio + Rider)
normj commented 2 years ago

Good catch, you are right request is too common and we should avoid collisions.

normj commented 2 years ago

PR is merged and will go out in the next release. Thanks for the great feedback!

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

PeterKneale commented 2 years ago

@normj tested in 0.5.1-preview - working nicely