@@ -55,7 +55,7 @@ public async Task<OpenApiDocument> GetOpenApiDocumentAsync(CancellationToken can
55
55
var document = new OpenApiDocument
56
56
{
57
57
Info = GetOpenApiInfo ( ) ,
58
- Paths = GetOpenApiPaths ( capturedTags ) ,
58
+ Paths = await GetOpenApiPathsAsync ( capturedTags , cancellationToken ) ,
59
59
Tags = [ .. capturedTags ]
60
60
} ;
61
61
await ApplyTransformersAsync ( document , cancellationToken ) ;
@@ -99,7 +99,7 @@ internal OpenApiInfo GetOpenApiInfo()
99
99
/// the object to support filtering each
100
100
/// description instance into its appropriate document.
101
101
/// </remarks>
102
- private OpenApiPaths GetOpenApiPaths ( HashSet < OpenApiTag > capturedTags )
102
+ private async Task < OpenApiPaths > GetOpenApiPathsAsync ( HashSet < OpenApiTag > capturedTags , CancellationToken cancellationToken )
103
103
{
104
104
var descriptionsByPath = apiDescriptionGroupCollectionProvider . ApiDescriptionGroups . Items
105
105
. SelectMany ( group => group . Items )
@@ -109,17 +109,17 @@ private OpenApiPaths GetOpenApiPaths(HashSet<OpenApiTag> capturedTags)
109
109
foreach ( var descriptions in descriptionsByPath )
110
110
{
111
111
Debug . Assert ( descriptions . Key != null , "Relative path mapped to OpenApiPath key cannot be null." ) ;
112
- paths . Add ( descriptions . Key , new OpenApiPathItem { Operations = GetOperations ( descriptions , capturedTags ) } ) ;
112
+ paths . Add ( descriptions . Key , new OpenApiPathItem { Operations = await GetOperationsAsync ( descriptions , capturedTags , cancellationToken ) } ) ;
113
113
}
114
114
return paths ;
115
115
}
116
116
117
- private Dictionary < OperationType , OpenApiOperation > GetOperations ( IGrouping < string ? , ApiDescription > descriptions , HashSet < OpenApiTag > capturedTags )
117
+ private async Task < Dictionary < OperationType , OpenApiOperation > > GetOperationsAsync ( IGrouping < string ? , ApiDescription > descriptions , HashSet < OpenApiTag > capturedTags , CancellationToken cancellationToken )
118
118
{
119
119
var operations = new Dictionary < OperationType , OpenApiOperation > ( ) ;
120
120
foreach ( var description in descriptions )
121
121
{
122
- var operation = GetOperation ( description , capturedTags ) ;
122
+ var operation = await GetOperationAsync ( description , capturedTags , cancellationToken ) ;
123
123
operation . Extensions . Add ( OpenApiConstants . DescriptionId , new OpenApiString ( description . ActionDescriptor . Id ) ) ;
124
124
_operationTransformerContextCache . TryAdd ( description . ActionDescriptor . Id , new OpenApiOperationTransformerContext
125
125
{
@@ -132,7 +132,7 @@ private Dictionary<OperationType, OpenApiOperation> GetOperations(IGrouping<stri
132
132
return operations ;
133
133
}
134
134
135
- private OpenApiOperation GetOperation ( ApiDescription description , HashSet < OpenApiTag > capturedTags )
135
+ private async Task < OpenApiOperation > GetOperationAsync ( ApiDescription description , HashSet < OpenApiTag > capturedTags , CancellationToken cancellationToken )
136
136
{
137
137
var tags = GetTags ( description ) ;
138
138
if ( tags != null )
@@ -147,9 +147,9 @@ private OpenApiOperation GetOperation(ApiDescription description, HashSet<OpenAp
147
147
OperationId = GetOperationId ( description ) ,
148
148
Summary = GetSummary ( description ) ,
149
149
Description = GetDescription ( description ) ,
150
- Responses = GetResponses ( description ) ,
151
- Parameters = GetParameters ( description ) ,
152
- RequestBody = GetRequestBody ( description ) ,
150
+ Responses = await GetResponsesAsync ( description , cancellationToken ) ,
151
+ Parameters = await GetParametersAsync ( description , cancellationToken ) ,
152
+ RequestBody = await GetRequestBodyAsync ( description , cancellationToken ) ,
153
153
Tags = tags ,
154
154
} ;
155
155
return operation ;
@@ -177,7 +177,7 @@ private OpenApiOperation GetOperation(ApiDescription description, HashSet<OpenAp
177
177
return [ new OpenApiTag { Name = description . ActionDescriptor . RouteValues [ "controller" ] } ] ;
178
178
}
179
179
180
- private OpenApiResponses GetResponses ( ApiDescription description )
180
+ private async Task < OpenApiResponses > GetResponsesAsync ( ApiDescription description , CancellationToken cancellationToken )
181
181
{
182
182
// OpenAPI requires that each operation have a response, usually a successful one.
183
183
// if there are no response types defined, we assume a successful 200 OK response
@@ -186,7 +186,7 @@ private OpenApiResponses GetResponses(ApiDescription description)
186
186
{
187
187
return new OpenApiResponses
188
188
{
189
- [ "200" ] = GetResponse ( description , StatusCodes . Status200OK , _defaultApiResponseType )
189
+ [ "200" ] = await GetResponseAsync ( description , StatusCodes . Status200OK , _defaultApiResponseType , cancellationToken )
190
190
} ;
191
191
}
192
192
@@ -200,12 +200,12 @@ private OpenApiResponses GetResponses(ApiDescription description)
200
200
var responseKey = responseType . IsDefaultResponse
201
201
? OpenApiConstants . DefaultOpenApiResponseKey
202
202
: responseType . StatusCode . ToString ( CultureInfo . InvariantCulture ) ;
203
- responses . Add ( responseKey , GetResponse ( description , responseType . StatusCode , responseType ) ) ;
203
+ responses . Add ( responseKey , await GetResponseAsync ( description , responseType . StatusCode , responseType , cancellationToken ) ) ;
204
204
}
205
205
return responses ;
206
206
}
207
207
208
- private OpenApiResponse GetResponse ( ApiDescription apiDescription , int statusCode , ApiResponseType apiResponseType )
208
+ private async Task < OpenApiResponse > GetResponseAsync ( ApiDescription apiDescription , int statusCode , ApiResponseType apiResponseType , CancellationToken cancellationToken )
209
209
{
210
210
var description = ReasonPhrases . GetReasonPhrase ( statusCode ) ;
211
211
var response = new OpenApiResponse
@@ -222,7 +222,7 @@ private OpenApiResponse GetResponse(ApiDescription apiDescription, int statusCod
222
222
. Select ( responseFormat => responseFormat . MediaType ) ;
223
223
foreach ( var contentType in apiResponseFormatContentTypes )
224
224
{
225
- var schema = apiResponseType . Type is { } type ? _componentService . GetOrCreateSchema ( type ) : new OpenApiSchema ( ) ;
225
+ var schema = apiResponseType . Type is { } type ? await _componentService . GetOrCreateSchemaAsync ( type , null , cancellationToken ) : new OpenApiSchema ( ) ;
226
226
response . Content [ contentType ] = new OpenApiMediaType { Schema = schema } ;
227
227
}
228
228
@@ -240,7 +240,7 @@ private OpenApiResponse GetResponse(ApiDescription apiDescription, int statusCod
240
240
return response ;
241
241
}
242
242
243
- private List < OpenApiParameter > ? GetParameters ( ApiDescription description )
243
+ private async Task < List < OpenApiParameter > ? > GetParametersAsync ( ApiDescription description , CancellationToken cancellationToken )
244
244
{
245
245
List < OpenApiParameter > ? parameters = null ;
246
246
foreach ( var parameter in description . ParameterDescriptions )
@@ -265,32 +265,32 @@ private OpenApiResponse GetResponse(ApiDescription apiDescription, int statusCod
265
265
// Per the OpenAPI specification, parameters that are sourced from the path
266
266
// are always required, regardless of the requiredness status of the parameter.
267
267
Required = parameter . Source == BindingSource . Path || parameter . IsRequired ,
268
- Schema = _componentService . GetOrCreateSchema ( parameter . Type , parameter ) ,
268
+ Schema = await _componentService . GetOrCreateSchemaAsync ( parameter . Type , parameter , cancellationToken ) ,
269
269
} ;
270
270
parameters ??= [ ] ;
271
271
parameters . Add ( openApiParameter ) ;
272
272
}
273
273
return parameters ;
274
274
}
275
275
276
- private OpenApiRequestBody ? GetRequestBody ( ApiDescription description )
276
+ private async Task < OpenApiRequestBody ? > GetRequestBodyAsync ( ApiDescription description , CancellationToken cancellationToken )
277
277
{
278
278
// Only one parameter can be bound from the body in each request.
279
279
if ( description . TryGetBodyParameter ( out var bodyParameter ) )
280
280
{
281
- return GetJsonRequestBody ( description . SupportedRequestFormats , bodyParameter ) ;
281
+ return await GetJsonRequestBody ( description . SupportedRequestFormats , bodyParameter , cancellationToken ) ;
282
282
}
283
283
// If there are no body parameters, check for form parameters.
284
284
// Note: Form parameters and body parameters cannot exist simultaneously
285
285
// in the same endpoint.
286
286
if ( description . TryGetFormParameters ( out var formParameters ) )
287
287
{
288
- return GetFormRequestBody ( description . SupportedRequestFormats , formParameters ) ;
288
+ return await GetFormRequestBody ( description . SupportedRequestFormats , formParameters , cancellationToken ) ;
289
289
}
290
290
return null ;
291
291
}
292
292
293
- private OpenApiRequestBody GetFormRequestBody ( IList < ApiRequestFormat > supportedRequestFormats , IEnumerable < ApiParameterDescription > formParameters )
293
+ private async Task < OpenApiRequestBody > GetFormRequestBody ( IList < ApiRequestFormat > supportedRequestFormats , IEnumerable < ApiParameterDescription > formParameters , CancellationToken cancellationToken )
294
294
{
295
295
if ( supportedRequestFormats . Count == 0 )
296
296
{
@@ -325,7 +325,7 @@ private OpenApiRequestBody GetFormRequestBody(IList<ApiRequestFormat> supportedR
325
325
if ( parameter . All ( parameter => parameter . ModelMetadata . ContainerType is null ) )
326
326
{
327
327
var description = parameter . Single ( ) ;
328
- var parameterSchema = _componentService . GetOrCreateSchema ( description . Type ) ;
328
+ var parameterSchema = await _componentService . GetOrCreateSchemaAsync ( description . Type , null , cancellationToken ) ;
329
329
// Form files are keyed by their parameter name so we must capture the parameter name
330
330
// as a property in the schema.
331
331
if ( description . Type == typeof ( IFormFile ) || description . Type == typeof ( IFormFileCollection ) )
@@ -388,15 +388,15 @@ private OpenApiRequestBody GetFormRequestBody(IList<ApiRequestFormat> supportedR
388
388
var propertySchema = new OpenApiSchema { Type = "object" , Properties = new Dictionary < string , OpenApiSchema > ( ) } ;
389
389
foreach ( var description in parameter )
390
390
{
391
- propertySchema . Properties [ description . Name ] = _componentService . GetOrCreateSchema ( description . Type ) ;
391
+ propertySchema . Properties [ description . Name ] = await _componentService . GetOrCreateSchemaAsync ( description . Type , null , cancellationToken ) ;
392
392
}
393
393
schema . AllOf . Add ( propertySchema ) ;
394
394
}
395
395
else
396
396
{
397
397
foreach ( var description in parameter )
398
398
{
399
- schema . Properties [ description . Name ] = _componentService . GetOrCreateSchema ( description . Type ) ;
399
+ schema . Properties [ description . Name ] = await _componentService . GetOrCreateSchemaAsync ( description . Type , null , cancellationToken ) ;
400
400
}
401
401
}
402
402
}
@@ -415,7 +415,7 @@ private OpenApiRequestBody GetFormRequestBody(IList<ApiRequestFormat> supportedR
415
415
return requestBody ;
416
416
}
417
417
418
- private OpenApiRequestBody GetJsonRequestBody ( IList < ApiRequestFormat > supportedRequestFormats , ApiParameterDescription bodyParameter )
418
+ private async Task < OpenApiRequestBody > GetJsonRequestBody ( IList < ApiRequestFormat > supportedRequestFormats , ApiParameterDescription bodyParameter , CancellationToken cancellationToken )
419
419
{
420
420
if ( supportedRequestFormats . Count == 0 )
421
421
{
@@ -442,7 +442,7 @@ private OpenApiRequestBody GetJsonRequestBody(IList<ApiRequestFormat> supportedR
442
442
foreach ( var requestForm in supportedRequestFormats )
443
443
{
444
444
var contentType = requestForm . MediaType ;
445
- requestBody . Content [ contentType ] = new OpenApiMediaType { Schema = _componentService . GetOrCreateSchema ( bodyParameter . Type ) } ;
445
+ requestBody . Content [ contentType ] = new OpenApiMediaType { Schema = await _componentService . GetOrCreateSchemaAsync ( bodyParameter . Type , bodyParameter , cancellationToken ) } ;
446
446
}
447
447
448
448
return requestBody ;
0 commit comments