Skip to content

Commit c6dc1a8

Browse files
committed
Add examples to AddOpenApi extension method/overloads
1 parent 7f62ae6 commit c6dc1a8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/OpenApi/src/Extensions/OpenApiServiceCollectionExtensions.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ public static class OpenApiServiceCollectionExtensions
1919
/// </summary>
2020
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
2121
/// <param name="documentName">The name of the OpenAPI document associated with registered services.</param>
22+
/// <example>
23+
/// This method is commonly used to add OpenAPI services to the service collection of a
24+
/// <see cref="WebApplicationBuilder"/>, as shown in the following example:
25+
/// <code>
26+
/// var builder = WebApplication.CreateBuilder(args);
27+
/// builder.Services.AddOpenApi("MyWebApi");
28+
/// </code>
29+
/// </example>
2230
public static IServiceCollection AddOpenApi(this IServiceCollection services, string documentName)
2331
{
2432
ArgumentNullException.ThrowIfNull(services);
@@ -32,6 +40,17 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, st
3240
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
3341
/// <param name="documentName">The name of the OpenAPI document associated with registered services.</param>
3442
/// <param name="configureOptions">A delegate used to configure the target <see cref="OpenApiOptions"/>.</param>
43+
/// <example>
44+
/// This method is commonly used to add OpenAPI services to the service collection of a
45+
/// <see cref="WebApplicationBuilder"/>, as shown in the following example:
46+
/// <code>
47+
/// var builder = WebApplication.CreateBuilder(args);
48+
/// builder.Services.AddOpenApi("MyWebApi", options => {
49+
/// // Add a custom schema transformer for decimal types
50+
/// options.AddSchemaTransformer(DecimalTransformer.TransformAsync);
51+
/// });
52+
/// </code>
53+
/// </example>
3554
public static IServiceCollection AddOpenApi(this IServiceCollection services, string documentName, Action<OpenApiOptions> configureOptions)
3655
{
3756
ArgumentNullException.ThrowIfNull(services);
@@ -51,13 +70,32 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, st
5170
/// </summary>
5271
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
5372
/// <param name="configureOptions">A delegate used to configure the target <see cref="OpenApiOptions"/>.</param>
73+
/// <example>
74+
/// This method is commonly used to add OpenAPI services to the service collection of a
75+
/// <see cref="WebApplicationBuilder"/>, as shown in the following example:
76+
/// <code>
77+
/// var builder = WebApplication.CreateBuilder(args);
78+
/// builder.Services.AddOpenApi(options => {
79+
/// // Add a custom schema transformer for decimal types
80+
/// options.AddSchemaTransformer(DecimalTransformer.TransformAsync);
81+
/// });
82+
/// </code>
83+
/// </example>
5484
public static IServiceCollection AddOpenApi(this IServiceCollection services, Action<OpenApiOptions> configureOptions)
5585
=> services.AddOpenApi(OpenApiConstants.DefaultDocumentName, configureOptions);
5686

5787
/// <summary>
5888
/// Adds OpenAPI services related to the default document to the specified <see cref="IServiceCollection"/>.
5989
/// </summary>
6090
/// <param name="services">The <see cref="IServiceCollection"/> to register services onto.</param>
91+
/// <example>
92+
/// This method is commonly used to add OpenAPI services to the service collection of a
93+
/// <see cref="WebApplicationBuilder"/>, as shown in the following example:
94+
/// <code>
95+
/// var builder = WebApplication.CreateBuilder(args);
96+
/// builder.Services.AddOpenApi();
97+
/// </code>
98+
/// </example>
6199
public static IServiceCollection AddOpenApi(this IServiceCollection services)
62100
=> services.AddOpenApi(OpenApiConstants.DefaultDocumentName);
63101

0 commit comments

Comments
 (0)