yahehe / Nancy.Swagger

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

Thinking about the swagger-ui #98

Open catcherwong opened 7 years ago

catcherwong commented 7 years ago

Hi guys,

After I use this project for some months , I have a questions here:

Why not includes the static resources of the swagger-ui ?

I find out that the demos use Response.AsRedirect($"http://petstore.swagger.io/?url=http://localhost:{port}/api-docs") to work. It's also a good way ! But sometimes it's vary slow when I open this url .Cost lots of time to wait!!

So I want to ask if there are somethings other you are considering for this?

And here is my point :

Including the static resources and add a new route which returns a html page (the document) will make our project run and debug more easier and spend less time to wait the response of the website.

For my own solution, I always include the static resource when creating a new project, and make them as the Embedded resource , and it can make me spend less time to wait the response.

The module code:

Get("/swagger-ui",_=>
{
    var url = $"{Request.Url.BasePath}/api-docs";
    return View["doc", url];
 });

The javascript code:

window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
      url: "@Model",
    dom_id: '#swagger-ui',
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}

And it works fine for me. image

jnallard commented 7 years ago

Only the examples directly call the petstore, not the Nancy.Swagger library itself. We changed it so that the person using Nancy.Swagger has the choice of who hosts the swagger page.

The examples use the petstore because it allows us not to store Swagger-UI code in this repo. The projects I use at work host their own swagger page, because it is faster and it allows us to customize the page. All we have to do is have these pages point at the /api-docs or /swagger.json routes. This should work for your projects too.

Nancy.Swagger, (to me at least), is just responsible for creating the Swagger Document so that Swagger-UI or some other Swagger parser can present the data.

catcherwong commented 7 years ago

I know what you mean , Nancy.Swagger just return the data which swagger ui needs , and we can customize the swagger page by ourselves.

And what I think is from this project https://github.com/domaindrivendev/Swashbuckle.AspNetCore

It provides a default page and we can customize as well.

yahehe commented 7 years ago

We don't include the swagger-ui by default because that's a totally separate project. We could probably pull it in as a subtree (I think that's the right terminology/way), I'll have to look into what that would mean for this library though (not sure how I feel about static resources being compiled and distributed in the nupkg)

catcherwong commented 7 years ago

Separation is easy to manage the projects . subtree may be a great way to solve confused about this. Thanks for your comments! @jnallard @yahehe