Skip to content

Commit efd523e

Browse files
Clean up examples
1 parent fbff2e0 commit efd523e

File tree

9 files changed

+20
-29
lines changed

9 files changed

+20
-29
lines changed

Diff for: examples/AspNetCore/WebApi/MinimalApiExample/appsettings.Development.json

-8
This file was deleted.

Diff for: examples/AspNetCore/WebApi/OpenApiExample/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
}
1818
},
19-
"SwaggerExample": {
19+
"OpenApiExample": {
2020
"commandName": "Project",
2121
"launchBrowser": true,
2222
"launchUrl": "http://localhost:5000/swagger",

Diff for: examples/AspNetCore/WebApi/OpenApiExample/Startup.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public void Configure( IApplicationBuilder app, IApiVersionDescriptionProvider p
9090
// build a swagger endpoint for each discovered API version
9191
foreach ( var description in provider.ApiVersionDescriptions )
9292
{
93-
options.SwaggerEndpoint( $"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant() );
93+
var url = $"/swagger/{description.GroupName}/swagger.json";
94+
var name = description.GroupName.ToUpperInvariant();
95+
options.SwaggerEndpoint( url, name );
9496
}
9597
} );
9698
}

Diff for: examples/AspNetCore/WebApi/OpenApiExample/SwaggerDefaultValues.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
namespace ApiVersioning.Examples;
22

33
using Microsoft.AspNetCore.Mvc.ApiExplorer;
4+
using Microsoft.AspNetCore.Mvc.ModelBinding;
45
using Microsoft.OpenApi.Models;
56
using Swashbuckle.AspNetCore.SwaggerGen;
67
using System.Text.Json;
78

89
/// <summary>
9-
/// Represents the OpenAPI/Swashbuckle operation filter used to document the implicit API version parameter.
10+
/// Represents the OpenAPI/Swashbuckle operation filter used to document information provided, but not used.
1011
/// </summary>
1112
/// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
1213
/// Once they are fixed and published, this class can be removed.</remarks>
1314
public class SwaggerDefaultValues : IOperationFilter
1415
{
15-
/// <summary>
16-
/// Applies the filter to the specified operation using the given context.
17-
/// </summary>
18-
/// <param name="operation">The operation to apply the filter to.</param>
19-
/// <param name="context">The current operation filter context.</param>
16+
/// <inheritdoc />
2017
public void Apply( OpenApiOperation operation, OperationFilterContext context )
2118
{
2219
var apiDescription = context.ApiDescription;
@@ -55,10 +52,13 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
5552
parameter.Description = description.ModelMetadata?.Description;
5653
}
5754

58-
if ( parameter.Schema.Default == null && description.DefaultValue != null )
55+
if ( parameter.Schema.Default == null &&
56+
description.DefaultValue != null &&
57+
description.DefaultValue is not DBNull &&
58+
description.ModelMetadata is ModelMetadata modelMetadata )
5959
{
6060
// REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
61-
var json = JsonSerializer.Serialize( description.DefaultValue, description.ModelMetadata.ModelType );
61+
var json = JsonSerializer.Serialize( description.DefaultValue, modelMetadata.ModelType );
6262
parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson( json );
6363
}
6464

Diff for: examples/AspNetCore/WebApi/OpenApiExample/V1/Controllers/OrdersController.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class OrdersController : ControllerBase
3434
/// <response code="400">The order is invalid.</response>
3535
[HttpPost]
3636
[MapToApiVersion( "1.0" )]
37-
[Produces( "application/json" )]
3837
[Consumes( "application/json" )]
38+
[Produces( "application/json" )]
3939
[ProducesResponseType( typeof( Order ), 201 )]
4040
[ProducesResponseType( 400 )]
4141
public IActionResult Post( [FromBody] Order order )
@@ -49,13 +49,12 @@ public IActionResult Post( [FromBody] Order order )
4949
/// </summary>
5050
/// <param name="id">The requested order identifier.</param>
5151
/// <param name="order">The order to update.</param>
52-
/// <returns>The created order.</returns>
52+
/// <returns>None.</returns>
5353
/// <response code="204">The order was successfully updated.</response>
5454
/// <response code="400">The order is invalid.</response>
5555
/// <response code="404">The order does not exist.</response>
5656
[MapToApiVersion( "1.0" )]
5757
[HttpPatch( "{id:int}" )]
58-
[Produces( "application/json" )]
5958
[Consumes( "application/json" )]
6059
[ProducesResponseType( 204 )]
6160
[ProducesResponseType( 400 )]

Diff for: examples/AspNetCore/WebApi/OpenApiExample/V1/Controllers/PeopleController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public IActionResult Get( int id ) =>
2828
{
2929
Id = id,
3030
FirstName = "John",
31-
LastName = "Doe"
31+
LastName = "Doe",
3232
} );
3333
}

Diff for: examples/AspNetCore/WebApi/OpenApiExample/V2/Controllers/OrdersController.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public IActionResult Get()
4242
[HttpGet( "{id:int}" )]
4343
[Produces( "application/json" )]
4444
[ProducesResponseType( typeof( Order ), 200 )]
45-
[ProducesResponseType( 400 )]
4645
[ProducesResponseType( 404 )]
4746
public IActionResult Get( int id ) => Ok( new Order() { Id = id, Customer = "John Doe" } );
4847

@@ -54,6 +53,7 @@ public IActionResult Get()
5453
/// <response code="201">The order was successfully placed.</response>
5554
/// <response code="400">The order is invalid.</response>
5655
[HttpPost]
56+
[Consumes( "application/json" )]
5757
[Produces( "application/json" )]
5858
[ProducesResponseType( typeof( Order ), 201 )]
5959
[ProducesResponseType( 400 )]
@@ -68,12 +68,11 @@ public IActionResult Post( [FromBody] Order order )
6868
/// </summary>
6969
/// <param name="id">The requested order identifier.</param>
7070
/// <param name="order">The order to update.</param>
71-
/// <returns>The created order.</returns>
71+
/// <returns>None.</returns>
7272
/// <response code="204">The order was successfully updated.</response>
7373
/// <response code="400">The order is invalid.</response>
7474
/// <response code="404">The order does not exist.</response>
7575
[HttpPatch( "{id:int}" )]
76-
[Produces( "application/json" )]
7776
[Consumes( "application/json" )]
7877
[ProducesResponseType( Status204NoContent )]
7978
[ProducesResponseType( Status400BadRequest )]

Diff for: examples/AspNetCore/WebApi/OpenApiExample/V3/Controllers/OrdersController.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ public class OrdersController : ControllerBase
1616
/// </summary>
1717
/// <returns>All available orders.</returns>
1818
/// <response code="200">Orders successfully retrieved.</response>
19-
/// <response code="400">The order is invalid.</response>
2019
[HttpGet]
2120
[Produces( "application/json" )]
2221
[ProducesResponseType( typeof( IEnumerable<Order> ), 200 )]
23-
[ProducesResponseType( 400 )]
2422
public IActionResult Get()
2523
{
2624
var orders = new Order[]
2725
{
2826
new(){ Id = 1, Customer = "John Doe" },
29-
new(){ Id = 2, Customer = "John Doe" },
27+
new(){ Id = 2, Customer = "Bob Smith" },
3028
new(){ Id = 3, Customer = "Jane Doe", EffectiveDate = DateTimeOffset.UtcNow.AddDays( 7d ) },
3129
};
3230

@@ -43,7 +41,6 @@ public IActionResult Get()
4341
[HttpGet( "{id:int}" )]
4442
[Produces( "application/json" )]
4543
[ProducesResponseType( typeof( Order ), 200 )]
46-
[ProducesResponseType( 400 )]
4744
[ProducesResponseType( 404 )]
4845
public IActionResult Get( int id ) => Ok( new Order() { Id = id, Customer = "John Doe" } );
4946

@@ -55,6 +52,7 @@ public IActionResult Get()
5552
/// <response code="201">The order was successfully placed.</response>
5653
/// <response code="400">The order is invalid.</response>
5754
[HttpPost]
55+
[Consumes( "application/json" )]
5856
[Produces( "application/json" )]
5957
[ProducesResponseType( typeof( Order ), 201 )]
6058
[ProducesResponseType( 400 )]

Diff for: examples/AspNetCore/WebApi/OpenApiExample/V3/Controllers/PeopleController.cs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public IActionResult Get( int id ) =>
8282
/// <response code="201">The person was successfully created.</response>
8383
/// <response code="400">The person was invalid.</response>
8484
[HttpPost]
85+
[Consumes( "application/json" )]
8586
[Produces( "application/json" )]
8687
[ProducesResponseType( typeof( Person ), 201 )]
8788
[ProducesResponseType( 400 )]

0 commit comments

Comments
 (0)