33using Microsoft . AspNetCore . Diagnostics . HealthChecks ;
44using Microsoft . AspNetCore . Mvc ;
55using Microsoft . Extensions . Hosting ;
6- using Swashbuckle . AspNetCore . SwaggerUI ;
76using ugrc . api . Features . Converting ;
87using ugrc . api . Features . Geocoding ;
98using ugrc . api . Features . Health ;
1211using ugrc . api . Features . Searching ;
1312using ugrc . api . Middleware ;
1413using ugrc . api . Models . ResponseContracts ;
14+ using Microsoft . OpenApi ;
1515
1616namespace ugrc . api . Extensions ;
17+
1718public static class WebApplicationExtensions {
1819 public static void MapRoutes ( this WebApplication app ) {
1920 if ( app . Environment . IsDevelopment ( ) ) {
@@ -52,11 +53,15 @@ public static void MapRoutes(this WebApplication app) {
5253 . AddEndpointFilter < GeocodeQuery . ValidationFilter > ( )
5354 . HasApiVersion ( 1 )
5455 . HasApiVersion ( 2 )
55- . WithOpenApi ( operation => new ( operation ) {
56- OperationId = "Geocode" ,
57- Summary = "Single address geocoding" ,
58- Description = "Extract the x, y location from a street address and zone" ,
59- Tags = [ new ( ) { Name = "Address Geocoding" } ] ,
56+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
57+ operation . OperationId = "Geocode" ;
58+ operation . Summary = "Single address geocoding" ;
59+ operation . Description = "Extract the x, y location from a street address and zone" ;
60+ operation . Tags = new HashSet < OpenApiTagReference > {
61+ new ( "Address Geocoding" )
62+ } ;
63+
64+ return Task . CompletedTask ;
6065 } )
6166 . Produces < ApiResponseContract < SingleGeocodeResponseContract > > ( StatusCodes . Status200OK )
6267 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -77,11 +82,15 @@ public static void MapRoutes(this WebApplication app) {
7782 } )
7883 . HasApiVersion ( 1 )
7984 . HasApiVersion ( 2 )
80- . WithOpenApi ( operation => new ( operation ) {
81- OperationId = "ReverseGeocode" ,
82- Summary = "Reverse Geocoding" ,
83- Description = "Extract the x, y location from a street address and zone" ,
84- Tags = [ new ( ) { Name = "Address Geocoding" } ] ,
85+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
86+ operation . OperationId = "ReverseGeocode" ;
87+ operation . Summary = "Reverse Geocoding" ;
88+ operation . Description = "Extract the x, y location from a street address and zone" ;
89+ operation . Tags = new HashSet < OpenApiTagReference > {
90+ new ( "Address Geocoding" )
91+ } ;
92+
93+ return Task . CompletedTask ;
8594 } )
8695 . Produces < ApiResponseContract < ReverseGeocodeResponseContract > > ( StatusCodes . Status200OK )
8796 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -103,11 +112,15 @@ public static void MapRoutes(this WebApplication app) {
103112 . AddEndpointFilter < RouteMilepostQuery . ValidationFilter > ( )
104113 . HasApiVersion ( 1 )
105114 . HasApiVersion ( 2 )
106- . WithOpenApi ( operation => new ( operation ) {
107- OperationId = "MilepostGeocode" ,
108- Summary = "Milepost Geocoding" ,
109- Description = "Extract the x, y location from a milepost along a route" ,
110- Tags = [ new ( ) { Name = "Milepost Geocoding" } ] ,
115+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
116+ operation . OperationId = "MilepostGeocode" ;
117+ operation . Summary = "Milepost Geocoding" ;
118+ operation . Description = "Extract the x, y location from a milepost along a route" ;
119+ operation . Tags = new HashSet < OpenApiTagReference > {
120+ new ( "Milepost Geocoding" )
121+ } ;
122+
123+ return Task . CompletedTask ;
111124 } )
112125 . Produces < ApiResponseContract < RouteMilepostResponseContract > > ( StatusCodes . Status200OK )
113126 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -128,11 +141,15 @@ public static void MapRoutes(this WebApplication app) {
128141 } )
129142 . HasApiVersion ( 1 )
130143 . HasApiVersion ( 2 )
131- . WithOpenApi ( operation => new ( operation ) {
132- OperationId = "ReverseMilepostGeocode" ,
133- Summary = "Reverse Milepost Geocoding" ,
134- Description = "Extract the x, y, and measure from a milepost (measure) along a route" ,
135- Tags = [ new ( ) { Name = "Milepost Geocoding" } ] ,
144+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
145+ operation . OperationId = "ReverseMilepostGeocode" ;
146+ operation . Summary = "Reverse Milepost Geocoding" ;
147+ operation . Description = "Extract the x, y, and measure from a milepost (measure) along a route" ;
148+ operation . Tags = new HashSet < OpenApiTagReference > {
149+ new ( "Milepost Geocoding" )
150+ } ;
151+
152+ return Task . CompletedTask ;
136153 } )
137154 . Produces < ApiResponseContract < RouteMilepostResponseContract > > ( StatusCodes . Status200OK )
138155 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -154,18 +171,22 @@ public static void MapRoutes(this WebApplication app) {
154171 . AddEndpointFilter < SearchQuery . ValidationFilter > ( )
155172 . HasApiVersion ( 1 )
156173 . HasApiVersion ( 2 )
157- . WithOpenApi ( operation => new ( operation ) {
158- OperationId = "Search" ,
159- Summary = "Search the Open SGID" ,
160- Description = "Search tables and attributes within the SGID" ,
161- Tags = [ new ( ) { Name = "Searching" } ] ,
174+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
175+ operation . OperationId = "Search" ;
176+ operation . Summary = "Search the Open SGID" ;
177+ operation . Description = "Search tables and attributes within the SGID" ;
178+ operation . Tags = new HashSet < OpenApiTagReference > {
179+ new ( "Searching" )
180+ } ;
181+
182+ return Task . CompletedTask ;
162183 } )
163184 . Produces < ApiResponseContract < SearchResponseContract > > ( StatusCodes . Status200OK )
164185 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
165186 . Produces < ApiResponseContract > ( StatusCodes . Status404NotFound )
166187 . Produces < ApiResponseContract > ( StatusCodes . Status500InternalServerError ) ;
167188
168- info . MapGet ( "/featureclassnames" , async (
189+ _ = info . MapGet ( "/featureclassnames" , async (
169190 InformationRequestOptionsContract options ,
170191 [ FromServices ] IMediator mediator ,
171192 [ FromServices ] IJsonSerializerOptionsFactory factory ,
@@ -178,11 +199,15 @@ public static void MapRoutes(this WebApplication app) {
178199 . AddEndpointFilter < SqlSchemaQuery . ValidationFilter > ( )
179200 . HasApiVersion ( 1 )
180201 . HasApiVersion ( 2 )
181- . WithOpenApi ( operation => new ( operation ) {
182- OperationId = "FeatureClassNames" ,
183- Summary = "Get all feature classes for a SGID category" ,
184- Description = "Discover SGID data by viewing all available feature classes for a given category" ,
185- Tags = [ new ( ) { Name = "Info" } ] ,
202+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
203+ operation . OperationId = "FeatureClassNames" ;
204+ operation . Summary = "Get all feature classes for a SGID category" ;
205+ operation . Description = "Discover SGID data by viewing all available feature classes for a given category" ;
206+ operation . Tags = new HashSet < OpenApiTagReference > {
207+ new ( "Info" )
208+ } ;
209+
210+ return Task . CompletedTask ;
186211 } )
187212 . Produces < ApiResponseContract < IReadOnlyCollection < string > > > ( StatusCodes . Status200OK )
188213 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -203,11 +228,15 @@ public static void MapRoutes(this WebApplication app) {
203228 . AddEndpointFilter < SqlAttributeQuery . ValidationFilter > ( )
204229 . HasApiVersion ( 1 )
205230 . HasApiVersion ( 2 )
206- . WithOpenApi ( operation => new ( operation ) {
207- OperationId = "FeatureClassAttributeNames" ,
208- Summary = "Get all attributes for a SGID feature class" ,
209- Description = "Understand SGID table available fields by viewing all of the searchable attributes" ,
210- Tags = [ new ( ) { Name = "Info" } ] ,
231+ . AddOpenApiOperationTransformer ( ( operation , context , ct ) => {
232+ operation . OperationId = "FeatureClassAttributeNames" ;
233+ operation . Summary = "Get all attributes for a SGID feature class" ;
234+ operation . Description = "Understand SGID table available fields by viewing all of the searchable attributes" ;
235+ operation . Tags = new HashSet < OpenApiTagReference > {
236+ new ( "Info" )
237+ } ;
238+
239+ return Task . CompletedTask ;
211240 } )
212241 . Produces < ApiResponseContract < IReadOnlyCollection < string > > > ( StatusCodes . Status200OK )
213242 . Produces < ApiResponseContract > ( StatusCodes . Status400BadRequest )
@@ -229,16 +258,6 @@ public static void MapHealthChecks(this WebApplication app) {
229258 ResponseWriter = StartupHealthCheckResponseWriter . WriteText
230259 } ) ;
231260 }
232- public static void MapOpenApi ( this WebApplication app ) {
233- app . UseSwagger ( c => c . RouteTemplate = "openapi/{documentName}/api.json" ) ;
234- app . UseSwaggerUI ( c => {
235- c . DocumentTitle = "UGRC API OpenAPI Documentation" ;
236- c . RoutePrefix = "openapi" ;
237- c . SwaggerEndpoint ( "/openapi/v1/api.json" , "v1" ) ;
238- c . SwaggerEndpoint ( "/openapi/v2/api.json" , "v2" ) ;
239- c . SupportedSubmitMethods ( ) ;
240- c . EnableDeepLinking ( ) ;
241- c . DocExpansion ( DocExpansion . List ) ;
242- } ) ;
243- }
261+ public static void MapOpenApi ( this WebApplication app )
262+ => app . MapOpenApi ( "/openapi/{documentName}/api.json" ) ;
244263}
0 commit comments