Aspnetcore.docs: Changes in NSwag v12

Created on 18 Nov 2018  ·  14Comments  ·  Source: dotnet/AspNetCore.Docs

Hi, There are some breaking changes in NSwag v12.
Many methods were marked as obsolete.
https://github.com/RSuter/NSwag/releases

Basic setup to make it work now looks like that:

// in ConfigureServices()

services.AddSwaggerDocument(
configure =>
{
configure.PostProcess = (document) =>
{
document.Info.Version = "v1";
document.Info.Title = "My API";
document.Info.Description = "ASP.NET Core Web API";
};
});

// in Configure()

app.UseSwagger();
app.UseSwaggerUi3();

UPDATE Code above is updated as per suggestion from @RSuter


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P1 Source - Docs.ms

Most helpful comment

Hey, @scottaddie, want me to take this?

All 14 comments

Can confirm the above config is working flawlessly.

The same for me. It works like charm.
Thanks a lot for sharing that as I couldn't figure out where or how to use "AddSwaggerDocument();" as the inline documentation stated because it didn't explain that it was from "Services".
Many thanks.

Hi everyone, I'm the develop or NSwag. I know that this tutorial needs to be updated.

Please check out this wiki page: https://github.com/RSuter/NSwag/wiki/AspNetCore-Middleware

The PostProcess in UseSwagger should be only used to transform the document based on the request, nothing other because this post process is not called via CLI, please always use PostProcess in AddSwaggerDocument() if possible:

// in ConfigureServices()

services.AddSwaggerDocument(configure =>
{
    configure.PostProcess = document =>
    {
        document.Info.Version = "v1";
        document.Info.Title = "My API";
        document.Info.Description = "ASP.NET Core Web API";
    };
});

// in Configure()

app.UseSwagger();
app.UseSwaggerUi3();

/cc @MadKonst Can you please try this and update your OP?

Hi @RSuter
Thanks, it works fine. Updated my OP.

@scottaddie can you fix?

Hi @RSuter

The example of Enable OAuth2 authorization in the following link, doesn't work.
https://github.com/RSuter/NSwag/wiki/AspNetCore-Middleware

document.OAuth2Client - doesn't have this property. I am using V12.0.4

app.AddOpenApiDocument(document =>
{
    **document.OAuth2Client** = new OAuth2ClientSettings
    {

    };
}

How to enable OAuth2 authorization in the latest version?

Thanks
Lei

@LiangLNZ this config is in UseSwaggerUi3 - I've updated the wiki (it was wrong).

But we might have a problem with auth in Swagger UI 3, please report if this is also a problem for you: https://github.com/RSuter/NSwag/issues/1304

Hey, @scottaddie, want me to take this?

@daveabrock Yes, please.

Hey @RSuter - updating this as my last open-source contribution before the holidays (and no rush on a response).

Say, what is the difference between:

“NSwag.CodeGeneration.CSharp” is the nuget package which contains the SwaggerToCsharpClientGenerator class

I am wondering why I am unable to find AddSwaggerDocument in 2.2. Shouldn't including NSwag.AspNetCore be enough?

Works for me:

image

So yes, NSwag.AspNetCore should be enough for the middleware extension methods.

When I added the package from the Package Manager Console, it looks like it installed 11.0.9. I did a manual update to 12, and of course it works.

And @RSuter, thanks for the warnings about deprecated functions. I'll use those to clean up more code examples.

Was this page helpful?
0 / 5 - 0 ratings