Home OpenApiServiceCollectionExtensions Class
OpenApiServiceCollectionExtensions Class
Cancel

OpenApiServiceCollectionExtensions Class

Namespace: Json.Schema.Api.OpenApi

Inheritance: OpenApiServiceCollectionExtensions 🡒 object

Provides registration for OpenAPI description generation.

Methods

AddOpenApi(this IServiceCollection services, Action<OpenApiOptions> configure)

Describes the application’s API surface in OpenAPI, and publishes the description.

Declaration

1
public static IServiceCollection AddOpenApi(this IServiceCollection services, Action<OpenApiOptions> configure)
ParameterTypeDescription
servicesIServiceCollectionThe service collection.
configureAction<OpenApiOptions>An optional delegate that configures the description and how it is published.

Returns

The same Microsoft.Extensions.DependencyInjection.IServiceCollection, so calls can be chained.

Remarks

The description is assembled from the fragments each assembly registers as it loads, so controllers declared in a class library are included without that library knowing about the host.

Examples

1
2
3
4
5
6
7
8
            builder.Services.AddOpenApi(c =&gt;
            {
                c.Document.Info.Description = "The pet store API.";
                c.DocumentPath = "/openapi";
                c.InteractivePath = "/openapi/reference";
            });
            

AddOpenApi(this IServiceCollection services, string name, Action<OpenApiOptions> configure)

Describes the endpoints placed in a named description, and publishes it.

Declaration

1
public static IServiceCollection AddOpenApi(this IServiceCollection services, string name, Action<OpenApiOptions> configure)
ParameterTypeDescription
servicesIServiceCollectionThe service collection.
namestringThe description’s name, matching a name given to Json.Schema.Api.OpenApi.OpenApiDocumentAttribute on a controller. To configure the default description — the one holding every controller without that attribute — use the overload that takes no name.
configureAction<OpenApiOptions>An optional delegate that configures the description and how it is published.

Returns

The same Microsoft.Extensions.DependencyInjection.IServiceCollection, so calls can be chained.

Remarks

Call this once per description. A named description defaults to serving under its own name — /openapi/admin.json and /openapi/admin/reference — so several can be published without configuring paths.

Examples

1
2
3
4
5
6
7
            builder.Services.AddOpenApi();
            builder.Services.AddOpenApi("admin", c =&gt;
            {
                c.Document.Info.Title = "Admin API";
            });
            
Contents