Closed m-wild closed 3 years ago
I'll take this one as well. I was going to attempt to bring in the asyncapi/html-template package and generate the UI dynamically.
I don't really have a preference for how to do this one. Using the official asyncapi template seems like a great idea! Ideally this all gets packaged up nicely in the NuGet package, and from the users perspective they just add 1 line of code and get a nice UI out of it.
Not sure how you're getting on with this one, but I had an idea which is kind of a hack/cheating, but would be very simple.
AsyncAPI Playground (https://playground.asyncapi.io/) accepts a query parameter load
, which is the URL of an asyncapi document to load.
In our case, linking to https://playground.asyncapi.io/?load=http://localhost:5000/asyncapi/asyncapi.json
will load the document from our API and render it successfully.
If dynamically building the UI turns out to be too complex, this would be an acceptable compromise.
I actually started by implementing this approach, so I'll revert my work since that working commit, add some tests and issue a PR. I'll also add some documentation about the dependency on the AsyncAPI Playground.
I'll make the extension method app.UseAsyncApiUI()
default to the public AsyncAPI Playground, and also provide a app.UseAsyncApiUI(playgroundBaseUri)
for those that want to run their services internally in a firewall and limit external internet access for security reasons.
I wouldn't call it a 'hack' as much as I'd say it's following a microservice architecture to keep the library thin :wink:
I'm making progress on this, though I've run into a bit of a headache in terms of serving the css/js for index.html. I'm able to effectively proxy the request to a running instance of playground (I'm actually making an API call to the http://playground/html/generate
method call which returns a full html page), and that renders the doc without styles/javascript (subsequent calls from the browser fails).
My first attempt at solving this issue is to try and match on http://localhost:5000/asyncapi/ui/**/*
and just proxy those requests to http://playground/**/*
. This in my mind would be the ideal so that if the html is updated with new styles, it'll automatically be served.
Similar to Swachbuckle.AspNetCore which provides
app.UseSwaggerUI()
it would be nice to have anapp.UseAsyncApiUI()