-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Respect IModelNameProvider when matching OpenAPI parameters #64535
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
2831dc0
d6a6aaa
ee1593b
17db1f2
fdfaa69
be0a22f
ab15003
a2effff
1852060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ public class TestController : ControllerBase | |
| { | ||
| /// <param name="userId">The id of the user.</param> | ||
| [HttpGet("{userId}")] | ||
| public string Get() | ||
| public string Get(int userId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I should have given this test a better name. It's added to make sure the xml document generator works for the case where the parameter is omitted or added. See #63872
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry about that. Will revert and move to another test case. Should I rename it to something clearer?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine if you rename it. Or maybe we can just add a comment in the description of that controller, to keep the diff a bit smaller in regards to snapshots |
||
| { | ||
| return "Hello, World!"; | ||
| } | ||
|
|
@@ -141,4 +141,72 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => | |
| Assert.Equal("The id of the user.", path.Parameters[0].Description); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SupportsParametersWithCustomNamesFromControllers() | ||
| { | ||
| var source = | ||
| """ | ||
| using System.Collections.Generic; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(); | ||
|
|
||
| builder.Services | ||
| .AddControllers() | ||
| .AddApplicationPart(typeof(TestController).Assembly); | ||
| builder.Services.AddOpenApi(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapControllers(); | ||
|
|
||
| app.Run(); | ||
|
|
||
| [ApiController] | ||
| [Route("[controller]")] | ||
| public class TestController : ControllerBase | ||
| { | ||
| /// <param name="userId">The id of the user.</param> | ||
| [HttpGet("{user_id}")] | ||
| public string Get([FromRoute(Name = "user_id")] int userId) | ||
| { | ||
| return "Hello, World!"; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public IEnumerable<Person> Search(Query query) | ||
| { | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| public partial class Program {} | ||
|
|
||
| public record Person(int Id, string Name); | ||
|
|
||
| public class Query | ||
| { | ||
| /// <summary> | ||
| /// The full name of the person. | ||
| /// </summary> | ||
| [FromQuery(Name = "full_name")] | ||
| public string? Name { get; init; } | ||
| } | ||
| """; | ||
| var generator = new XmlCommentGenerator(); | ||
| await SnapshotTestHelper.Verify(source, generator, out var compilation); | ||
| await SnapshotTestHelper.VerifyOpenApi(compilation, document => | ||
| { | ||
| var getOperation = document.Paths["/Test/{user_id}"].Operations[HttpMethod.Get]; | ||
| Assert.Equal("user_id", getOperation.Parameters[0].Name); | ||
| Assert.Equal("The id of the user.", getOperation.Parameters[0].Description); | ||
|
|
||
| var searchOperation = document.Paths["/Test"].Operations[HttpMethod.Get]; | ||
| Assert.Equal("full_name", searchOperation.Parameters[0].Name); | ||
| Assert.Equal("The full name of the person.", searchOperation.Parameters[0].Description); | ||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.