Skip to content
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

Fix RequestBodyFilterAnnotation and MultipleFromForm for MinimalApi #2963

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ private OpenApiOperation GenerateOpenApiOperationFromMetadata(ApiDescription api
foreach (var content in requestContentTypes)
{
var requestParameters = apiDescription.ParameterDescriptions.Where(desc => desc.IsFromBody() || desc.IsFromForm());
if (requestParameters is not null)
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
if (requestParameters.Any())
{
_ = requestParameters.SingleOrDefault(desc => desc.IsFromBody());
jgarciadelanoceda marked this conversation as resolved.
Show resolved Hide resolved
if (requestParameters.Count() == 1)
{
content.Schema = GenerateSchema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,6 @@
}
}
},
"/AsParameters": {
"get": {
"tags": [
"WebApi"
],
"parameters": [
{
"name": "PropertyOne",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "PropertyTwo",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/WithOpenApi/weatherforecast": {
"get": {
"tags": [
Expand All @@ -108,7 +71,7 @@
}
}
},
"/WithOpenApi/api/people-minimalapi": {
"/WithOpenApi/multipleForms": {
"post": {
"tags": [
"WithOpenApi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,6 @@
}
}
},
"/AsParameters": {
"get": {
"tags": [
"WebApi"
],
"parameters": [
{
"name": "PropertyOne",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "PropertyTwo",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/WithOpenApi/weatherforecast": {
"get": {
"tags": [
Expand All @@ -108,7 +71,7 @@
}
}
},
"/WithOpenApi/api/people-minimalapi": {
"/WithOpenApi/multipleForms": {
"post": {
"tags": [
"WithOpenApi"
Expand Down
6 changes: 1 addition & 5 deletions test/WebSites/WebApi/EndPoints/OpenApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ public static IEndpointRouteBuilder MapWithOpenApiEndpoints(this IEndpointRouteB
.WithName("GetWeatherForecast")
.WithOpenApi();

group.MapPost("/api/people-minimalapi", ([FromForm] Person person, [FromForm] Address address) =>
group.MapPost("/multipleForms", ([FromForm] Person person, [FromForm] Address address) =>
{
TypedResults.NoContent();
})
.WithOpenApi()
.DisableAntiforgery();



//group.MapGet("DateTimeKind", (DateTimeKind d) => d);

return app;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static IEndpointRouteBuilder MapAnnotationsEndpoints(this IEndpointRouteB
var group = app.MapGroup("/annotations").WithTags("Annotations");

group.MapPost("/fruit/{id}", CreateFruit);
app.MapGet("/kk/{id}", (int id) => id).WithGroupName("Wathever");

return app;
}
Expand Down
18 changes: 2 additions & 16 deletions test/WebSites/WebApi/EndPoints/XmlCommentsEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ public static IEndpointRouteBuilder MapXmlCommentsEndpoints(this IEndpointRouteB

group.MapGet("/Car/{id}", GetProduct);

app.MapGet("/AsParameters", ([AsParameters] AsParametersArgument request) => "Hello World!");

return app;
}
/// <summary>
/// Returns a specific product
/// </summary>
/// <param name="id" example="111">The product id</param>
/// <response code="200">A Product Id</response>
private static Product GetProduct(int id) => new Product { Id = id, Description = "A product" };
private static Product GetProduct(int id) => new() { Id = id, Description = "A product" };
}
/// <summary>
/// Represents a product
/// </summary>
public class Product
internal class Product
{
/// <summary>
/// Uniquely identifies the product
Expand All @@ -41,16 +39,4 @@ public class Product
/// </summary>
public string? Description { get; set; }
}
internal struct AsParametersArgument
{
/// <summary>
/// This is a property with the number one - This is nowhere in SwaggerUI
/// </summary>
public string PropertyOne { get; set; }

/// <summary>
/// This is a property with the number two - This is nowhere in SwaggerUI
/// </summary>
public string PropertyTwo { get; set; }
}
}
3 changes: 2 additions & 1 deletion test/WebSites/WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
c.IncludeXmlComments(Assembly.GetExecutingAssembly());
c.SwaggerDoc("v1", new() { Title = "WebApi", Version = "v1" });
});

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI();


app.UseHttpsRedirection();

var summaries = new[]
Expand Down
Loading