yahehe / Nancy.Swagger

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

Ignoring parameters in documentation #95

Closed theHurc closed 7 years ago

theHurc commented 7 years ago

A Nancy route that operates async is defined like this:

Get("/", async (args, ct) => await GetSomethingAsync(args, ct));

Not including args didn't seem to work for me. Anyway...

When using Nancy.Swagger.Annotations the args and ct above show up in the swagger documentation even if they are unused and show up as undocumented. The cancellation token in particular is kind of annoying and clutters things up because it's not actually part of a webapi call, it's a cancellation token used by Nancy to cancel an operation during a disconnection, etc. As far as I could tell it's impossible to set a parameter to ignore. To demonstrate what I mean, if the definition of GetSomethingAsync was defined as:

private SomethingObject GetSomethingAsync(
                  [RouteParam(ParameterIn.IgnoreInDocumentation)] dynamic args,
                  [RouteParam(ParameterIn.IgnoreInDocumentation)] CancellationToken cancel)
{
  return new SomthingObject();
} 

That would be cool. Is there a work around for this issue?

yahehe commented 7 years ago

Hmm interesting, yeah I can look into that. This raises another question about what to do for async methods like this where you still want to document what the payload should look like. Maybe instead of doing it on a parameter basis we could have an annotation that allows the user to replace the schema for a given response

theHurc commented 7 years ago

I'm not sure I follow:

where you still want to document what the payload should look like.

Can you give an example?

jnallard commented 7 years ago

I thought if you don't add annotations to the params, they don't show up at all? Am I mistaken?

On Apr 12, 2017 6:00 PM, "Jake Baldwin" notifications@github.com wrote:

I'm not sure I follow:

where you still want to document what the payload should look like.

Can you give an example?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yahehe/Nancy.Swagger/issues/95#issuecomment-293719970, or mute the thread https://github.com/notifications/unsubscribe-auth/AGqvnalKBq-XqLrjSoPKplzgNO9UQ4rhks5rvUlsgaJpZM4M7_ev .

yahehe commented 7 years ago

I'll have to take a more in-depth look at annotations this weekend, I haven't really used it at all since adopting the package

theHurc commented 7 years ago

If you don't add annotations to the params they show up with the message "Warning: no annotation found for this parameter" To demonstrate, in the annotation sample project I removed the parameter annotation from the POST /user route and it shows up in the Swagger UI like this:

image

jnallard commented 7 years ago

@yahehe Can you push the latest nuget package so that we can close this issue? (Feel free to wait until the other PR is resolved though)

yahehe commented 7 years ago

Pushed