Skip to content

Commit

Permalink
Modified OpenAPI annotations via a better use of Produces
Browse files Browse the repository at this point in the history
  • Loading branch information
AKlaus committed Aug 17, 2022
1 parent 8d8e3de commit b80818a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions samples/WebApiMinimal/Routes/200OkResponses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public static void MapSuccessResponses(this IEndpointRouteBuilder app)

app.MapGet("200OkWithNumber", () => service.GetSuccessWithNumericValue().ToResult())
.WithTags("Success: 200 Ok")
.Produces(StatusCodes.Status200OK, typeof(int));
.Produces<int>();

app.MapGet("Get200OkWithNumberTask", () => service.GetSuccessWithNumericValueTask().ToResult())
.WithTags("Success: 200 Ok")
.Produces(StatusCodes.Status200OK, typeof(int));
.Produces<int>();

app.MapGet("Get200OkTupleWithNumber", () => service.GetSuccessWithNumericValueTuple().ToResult())
.WithTags("Success: 200 Ok")
.Produces(StatusCodes.Status200OK, typeof(int));
.Produces<int>();

app.MapGet("Get200OkTupleWithNumberTask", () => service.GetSuccessWithNumericValueTupleTask().ToResult())
.WithTags("Success: 200 Ok")
.Produces(StatusCodes.Status200OK, typeof(int));
.Produces<int>();
}
}
18 changes: 10 additions & 8 deletions samples/WebApiMinimal/Routes/201CreatedResponses.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using DomainResults.Examples.Domain;
using System.Net.Mime;

using DomainResults.Examples.Domain;
using DomainResults.Mvc;

using Microsoft.AspNetCore.Builder;
Expand All @@ -22,35 +24,35 @@ public static void MapSuccessCreatedResponses(this IEndpointRouteBuilder app)
.ToCustomResult(val => Results.CreatedAtRoute("GetById", new { id = val }, val))
)
.WithTags("Success: 201 Created")
.Produces(StatusCodes.Status201Created, typeof(int));
.Produces<int>(StatusCodes.Status201Created);

app.MapPost("Post201CreatedFromTupleTask",
() => service
.GetSuccessWithNumericValueTupleTask()
.ToCustomResult(val => Results.CreatedAtRoute("GetById", new { id = val }, val))
)
.WithTags("Success: 201 Created")
.Produces(StatusCodes.Status201Created, typeof(int));
.Produces<int>(StatusCodes.Status201Created);

app.MapPost("Post201Created",
() => service
.GetSuccessWithNumericValue()
.ToCustomResult(val => Results.CreatedAtRoute("GetById", new { id = val }, val))
)
.WithTags("Success: 201 Created")
.Produces(StatusCodes.Status201Created, typeof(int));
.Produces<int>(StatusCodes.Status201Created);

app.MapPost("Post201CreatedTask",
() => service
.GetSuccessWithNumericValueTask()
.ToCustomResult(val => Results.CreatedAtRoute("GetById", new { id = val }, val))
)
.WithTags("Success: 201 Created")
.Produces(StatusCodes.Status201Created, typeof(int));
.Produces<int>(StatusCodes.Status201Created);

app.MapGet("{id}", (int id) => Results.Ok(new { id }))
app.MapGet("{id}", (int id) => Results.Ok($"Sample properties of #{id} record"))
.WithTags("Success: 201 Created")
.WithMetadata(new RouteNameMetadata("GetById"))
.Produces(StatusCodes.Status200OK, typeof(int));
.WithName("GetById")
.Produces<string>(StatusCodes.Status200OK, MediaTypeNames.Text.Plain);
}
}

0 comments on commit b80818a

Please sign in to comment.