yahehe / Nancy.Swagger

Nancy plugin for generated API documentation in Swagger format.
MIT License
133 stars 60 forks source link

Adding security requirement to operation #176

Closed hopla closed 4 years ago

hopla commented 4 years ago

I have added a RouteSecurityAttribute which allows for adding a security requirement to an operation. Also see #170

foxkiong commented 4 years ago

I was looking for the security requirement as well, but I wanted it to be at the global level. Seems like nancy.swagger did not include this.

hopla commented 4 years ago

I think Swagger 2.0 (the version Nancy.Swagger uses) on supports Security Requirements on operations. However it is possible to add Security Defenitions, which are global. e.g. SwaggerMetadataProvider.SetSecuritySchemeBuilder(new BasicSecuritySchemeBuilder(), "Basic");

foxkiong commented 4 years ago

Ya you are right, I did use the SwaggerMetadataProvider provides SecuritySchema, but eventually I need to add in SecurityRequirement at the global level (in the resulted swagger.json) to make it work, I think it missed something like SetSecurityRequirementBuilder() .

hopla commented 4 years ago

@jnallard Hi, I added a basic-authentication requirement in the Nancy.Swagger.Annotations.Demo sample project. I also fixed the merge conflict that was caused by merging in pull request #175