1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . AspNetCore . Builder ;
4
5
using Microsoft . AspNetCore . Http . Json ;
5
6
using Microsoft . AspNetCore . OpenApi ;
6
7
using Microsoft . Extensions . ApiDescriptions ;
@@ -19,6 +20,14 @@ public static class OpenApiServiceCollectionExtensions
19
20
/// </summary>
20
21
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
21
22
/// <param name="documentName">The name of the OpenAPI document associated with registered services.</param>
23
+ /// <example>
24
+ /// This method is commonly used to add OpenAPI services to the <see cref="WebApplicationBuilder.Services"/>
25
+ /// of a <see cref="WebApplicationBuilder"/>, as shown in the following example:
26
+ /// <code>
27
+ /// var builder = WebApplication.CreateBuilder(args);
28
+ /// builder.Services.AddOpenApi("MyWebApi");
29
+ /// </code>
30
+ /// </example>
22
31
public static IServiceCollection AddOpenApi ( this IServiceCollection services , string documentName )
23
32
{
24
33
ArgumentNullException . ThrowIfNull ( services ) ;
@@ -32,6 +41,17 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, st
32
41
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
33
42
/// <param name="documentName">The name of the OpenAPI document associated with registered services.</param>
34
43
/// <param name="configureOptions">A delegate used to configure the target <see cref="OpenApiOptions"/>.</param>
44
+ /// <example>
45
+ /// This method is commonly used to add OpenAPI services to the <see cref="WebApplicationBuilder.Services"/>
46
+ /// of a <see cref="WebApplicationBuilder"/>, as shown in the following example:
47
+ /// <code>
48
+ /// var builder = WebApplication.CreateBuilder(args);
49
+ /// builder.Services.AddOpenApi("MyWebApi", options => {
50
+ /// // Add a custom schema transformer for decimal types
51
+ /// options.AddSchemaTransformer(DecimalTransformer.TransformAsync);
52
+ /// });
53
+ /// </code>
54
+ /// </example>
35
55
public static IServiceCollection AddOpenApi ( this IServiceCollection services , string documentName , Action < OpenApiOptions > configureOptions )
36
56
{
37
57
ArgumentNullException . ThrowIfNull ( services ) ;
@@ -51,13 +71,32 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, st
51
71
/// </summary>
52
72
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
53
73
/// <param name="configureOptions">A delegate used to configure the target <see cref="OpenApiOptions"/>.</param>
74
+ /// <example>
75
+ /// This method is commonly used to add OpenAPI services to the <see cref="WebApplicationBuilder.Services"/>
76
+ /// of a <see cref="WebApplicationBuilder"/>, as shown in the following example:
77
+ /// <code>
78
+ /// var builder = WebApplication.CreateBuilder(args);
79
+ /// builder.Services.AddOpenApi(options => {
80
+ /// // Add a custom schema transformer for decimal types
81
+ /// options.AddSchemaTransformer(DecimalTransformer.TransformAsync);
82
+ /// });
83
+ /// </code>
84
+ /// </example>
54
85
public static IServiceCollection AddOpenApi ( this IServiceCollection services , Action < OpenApiOptions > configureOptions )
55
86
=> services . AddOpenApi ( OpenApiConstants . DefaultDocumentName , configureOptions ) ;
56
87
57
88
/// <summary>
58
89
/// Adds OpenAPI services related to the default document to the specified <see cref="IServiceCollection"/>.
59
90
/// </summary>
60
91
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
92
+ /// <example>
93
+ /// This method is commonly used to add OpenAPI services to the <see cref="WebApplicationBuilder.Services"/>
94
+ /// of a <see cref="WebApplicationBuilder"/>, as shown in the following example:
95
+ /// <code>
96
+ /// var builder = WebApplication.CreateBuilder(args);
97
+ /// builder.Services.AddOpenApi();
98
+ /// </code>
99
+ /// </example>
61
100
public static IServiceCollection AddOpenApi ( this IServiceCollection services )
62
101
=> services . AddOpenApi ( OpenApiConstants . DefaultDocumentName ) ;
63
102
0 commit comments