11// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
3+ #pragma warning disable IDE0079 // Remove unnecessary suppression
4+ #pragma warning disable ASP0018 // Unused route parameter
5+
36namespace Asp . Versioning . Http ;
47
58using Asp . Versioning . Conventions ;
@@ -11,24 +14,16 @@ public class MinimalApiFixture : HttpServerFixture
1114{
1215 protected override void OnConfigureEndpoints ( IEndpointRouteBuilder endpoints )
1316 {
17+ endpoints . MapGet ( "api/ping" , ( ) => Results . NoContent ( ) )
18+ . WithApiVersionSet ( endpoints . NewApiVersionSet ( ) . Build ( ) )
19+ . IsApiVersionNeutral ( ) ;
20+
1421 var values = endpoints . NewApiVersionSet ( "Values" )
1522 . HasApiVersion ( 1.0 )
1623 . HasApiVersion ( 2.0 )
1724 . ReportApiVersions ( )
1825 . Build ( ) ;
1926
20- var helloWorld = endpoints . NewApiVersionSet ( "Hello World" )
21- . HasApiVersion ( 1.0 )
22- . HasApiVersion ( 2.0 )
23- . ReportApiVersions ( )
24- . Build ( ) ;
25-
26- var orders = endpoints . NewApiVersionSet ( "Orders" ) . Build ( ) ;
27-
28- endpoints . MapGet ( "api/ping" , ( ) => Results . NoContent ( ) )
29- . WithApiVersionSet ( endpoints . NewApiVersionSet ( ) . Build ( ) )
30- . IsApiVersionNeutral ( ) ;
31-
3227 endpoints . MapGet ( "api/values" , ( ) => "Value 1" )
3328 . WithApiVersionSet ( values )
3429 . MapToApiVersion ( 1.0 ) ;
@@ -37,44 +32,27 @@ protected override void OnConfigureEndpoints( IEndpointRouteBuilder endpoints )
3732 . WithApiVersionSet ( values )
3833 . MapToApiVersion ( 2.0 ) ;
3934
40- endpoints . MapGet ( "api/v{version:apiVersion}/hello" , ( ) => "Hello world!" )
41- . WithApiVersionSet ( helloWorld )
42- . MapToApiVersion ( 1.0 ) ;
43-
44- endpoints . MapGet ( "api/v{version:apiVersion}/hello/{text}" , ( string text ) => text )
45- . WithApiVersionSet ( helloWorld )
46- . MapToApiVersion ( 1.0 ) ;
47-
48- endpoints . MapGet ( "api/v{version:apiVersion}/hello" , ( ) => "Hello world! (v2)" )
49- . WithApiVersionSet ( helloWorld )
50- . MapToApiVersion ( 2.0 ) ;
51-
52- endpoints . MapGet ( "api/v{version:apiVersion}/hello/{text}" , ( string text ) => text + " (v2)" )
53- . WithApiVersionSet ( helloWorld )
54- . MapToApiVersion ( 2.0 ) ;
55-
56- endpoints . MapPost ( "api/v{version:apiVersion}/hello" , ( ) => { } )
57- . WithApiVersionSet ( helloWorld ) ;
58-
59- endpoints . MapGet ( "api/order" , ( ) => { } )
60- . WithApiVersionSet ( orders )
61- . HasApiVersion ( 1.0 )
62- . HasApiVersion ( 2.0 ) ;
35+ var orders = endpoints . NewVersionedApi ( "Orders" )
36+ . MapGroup ( "api/order" )
37+ . HasApiVersion ( 1.0 )
38+ . HasApiVersion ( 2.0 ) ;
6339
64- endpoints . MapGet ( "api/order/{id}" , ( int id ) => { } )
65- . WithApiVersionSet ( orders )
66- . HasDeprecatedApiVersion ( 0.9 )
67- . HasApiVersion ( 1.0 )
68- . HasApiVersion ( 2.0 ) ;
40+ orders . MapGet ( "/" , ( ) => Results . Ok ( ) ) ;
41+ orders . MapGet ( "/{id}" , ( int id ) => Results . Ok ( ) ) . HasDeprecatedApiVersion ( 0.9 ) ;
42+ orders . MapPost ( "/" , ( ) => Results . Created ( ) ) ;
43+ orders . MapDelete ( "/{id}" , ( int id ) => Results . NoContent ( ) ) . IsApiVersionNeutral ( ) ;
6944
70- endpoints . MapPost ( "api/order" , ( ) => { } )
71- . WithApiVersionSet ( orders )
72- . HasApiVersion ( 1.0 )
73- . HasApiVersion ( 2.0 ) ;
45+ var helloWorld = endpoints . NewVersionedApi ( "Orders" )
46+ . MapGroup ( "api/v{version:apiVersion}/hello" )
47+ . HasApiVersion ( 1.0 )
48+ . HasApiVersion ( 2.0 )
49+ . ReportApiVersions ( ) ;
7450
75- endpoints . MapDelete ( "api/order/{id}" , ( int id ) => { } )
76- . WithApiVersionSet ( orders )
77- . IsApiVersionNeutral ( ) ;
51+ helloWorld . MapGet ( "/" , ( ) => "Hello world!" ) . MapToApiVersion ( 1.0 ) ;
52+ helloWorld . MapGet ( "/{text}" , ( string text ) => text ) . MapToApiVersion ( 1.0 ) ;
53+ helloWorld . MapGet ( "/" , ( ) => "Hello world! (v2)" ) . MapToApiVersion ( 2.0 ) ;
54+ helloWorld . MapGet ( "/{text}" , ( string text ) => text + " (v2)" ) . MapToApiVersion ( 2.0 ) ;
55+ helloWorld . MapPost ( "/" , ( ) => { } ) ;
7856 }
7957
8058 protected override void OnAddApiVersioning ( ApiVersioningOptions options )
0 commit comments