Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swashbuckle.AspNetCoreの調査 #15

Open
f7q opened this issue Aug 11, 2017 · 1 comment
Open

Swashbuckle.AspNetCoreの調査 #15

f7q opened this issue Aug 11, 2017 · 1 comment

Comments

@f7q
Copy link
Owner

f7q commented Aug 11, 2017

仕様変更箇所の確認

swagger/ui/index.html
⬇️
swagger/index.html

@f7q
Copy link
Owner Author

f7q commented Aug 11, 2017

特定のコントローラ/アクションのドキュメントを出力する or しない

using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddSwaggerGen(option =>
        {
            option.DocInclusionPredicate((name, apiDescription) =>
            {
                var controllerActionDescription = apiDescription.ActionDescriptor as ControllerActionDescriptor;

                // コントローラ名に Api が含まれていたらSwaggerの対象にする
                return controllerActionDescription?.ControllerName.Contains("Api") ?? false;
            });
            option.SwaggerDoc("orders", new Title { Name = "Order APIs", Version = "v1" });
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant