How do I use swagger-ui? - swagger

I'm using the Swashbuckle NuGet package in my web api project and I was trying to replace the default Swagger UI with this one
https://github.com/jensoleg/swagger-ui
but I keep getting this error message
<?xml version="1.0" encoding="ISO-8859-1"?>
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Embedded resource not found - ReportsAPI.swagger-ui.Index.html</ExceptionMessage>
<ExceptionType>Swashbuckle.SwaggerUi.AssetNotFound</ExceptionType>
<StackTrace> at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, String rootUrl) at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetAsset(String rootUrl, String path) at Swashbuckle.Application.SwaggerUiHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</StackTrace>
</Error>
I followed the advice from this post
Replace Swashbuckle UI completely
But was unable to get it to work
I have a basic ASP.Net Web API 2 (simple rest api with no website or index html)
So I downloaded the zip file from the GitHub page of swagger-ui and copied the dist folder to my project and included it as (tried both Content and Embedded resource) - and renamed dist folder to swagger-ui
So my root project folder now looks like
Then I changed my Swagger config to add the following
c.CustomAsset("index", thisAssembly, "ReportsAPI.swagger-ui.Index.html");
Is that correct? I'm not sure where to go from here
Do I have to include all other files as Embedded resource? Or just the Index.html? What do I mark the other files as, Content? Copy always?

Here is an alternative that does not require you to embed anything into your project:
https://raw.githack.com/jensoleg/swagger-ui/master/dist/index.html?url=https://swagger-net-test.azurewebsites.net/swagger/docs/V1
As you can see my swagger spec is provided with in the url parameter.
You could use that raw.githack.com or just copy the dist folder to a more convenient location.
Now I would like to point out that is a very old version of swagger-ui and does not look to be well maintained, maybe you should take a look at: ReDoc https://github.com/Rebilly/ReDoc/blob/master/README.md

Related

Integrate the swagger ui into hammock

I am building up a CDI/REST Environment as basis for several projects by using hammock. What I would like to have besides CDI and REST is also json schema for generating payload classes and an automatically generated REST API documentation via swagger ui.
I am now at the point where everything works (Weld3, Resteasy, Undertow, Swagger Core, Json Schema). The only thing missing is the integration of swagger UI into my hammock stack.
In another project I already worked with swagger UI. As far as I know it is based on HTML + JS with an entry point index.hml. How do I integrate this into my hammock stack. How to tell the undertow that there is a index.html and where to find it ?
I think my question is not only related to swagger, but to the idea to have the hammock stack with additional static html content.
John Ament has added a swagger module for Swagger 2.0-rc3 to Hammock 2.1-SNAPHOT (will be released as part of Hammock 2.1):
https://github.com/hammock-project/hammock/tree/master/swagger
As for hosting Swagger UI inside a Hammock app, you can add a few files from swagger-ui/dist/* to Hammock's static resources path:
https://github.com/hammock-project/hammock/wiki/Native-Filters#static-resources

TypeScript function is not firing on .net core

I created an Asp.Net Core MVC application and I was trying to play around with TypeScript. I created a .ts file and add the following line.
(() => { alert("Made with TypeScript"); })();
According to the example this suppose to show an message dialog on the page load.
When I build the project it successfully created the .js file according to the TypeScript config file and I have already added the resulting .js file in the HTML page.
But when I run the program and visit the corresponding page I don't get the message dialog.
I tried couple of examples but the result was same.
My environment:
Visual Studio 2017 Community Edition
.Net Core 1.1.1
File Structure:
View:
Startup.cs
NOTE:
I added a plain .html page (without using .cshtml) and included the .js file which compiled by .ts and it works! I think the problem is with the MVC view.
You should put any served static files in the wwwroot folder of your web application. Anything outside of this folder is not accessible for webclients.
When you call ~/scripts/appscript1.js you are really referring to a file that should be in wwwroot/script/appscript1.js, so try copying the resulting .js file there.
wwwroot is also called the "web root" folder, while the project directory seen in visual studio is called the "content root".
See https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files for more information
To prevent always having to manually copy static files from your project structure to the wwwroot folder, consider using a task runner (Grunt, Gulp) or packager (Webpack) to do this for you.

Web API Help Pages not loading documentation XML

I'm trying to set up the ASP.NET Help Pages to run in an existing MVC project, though pointing towards the documentation file from a Web API project in the same solution. Convention has the Help Pages running inside the Web API that it's documenting but in this case I want it in a sibling MVC project.
The Web API project outputs its documentation XML file in a folder within the MVC project.
I've installed the Microsoft.AspNet.WebApi.HelpPage NuGet package in the MVC project. This creates a class \Areas\HelpPage\App_Start\HelpPageConfig.cs, and within this class's Register method I've passed the XmlDocumentationProvider the path to the Web API's documentation file.
But when I load the page, it's empty, aside from a title and a placeholder description.
Upon debugging the HelpController.Index method, I can see in the returned IApiExplorer that the _apiDescriptions are empty.
However, if I install the Help Pages directly into the Web API project and debug the same method, I can see that the _apiDescriptions are now present.
Can anyone explain what the Web API project is doing or has configured which the MVC project isn't doing or hasn't configured?
Just set this up myself, and I think I ran into a similar issue, if i'm reading what you're saying correctly.
Try the following:
Go to Areas\HelpPage\App_Start\HelpPageConfig.cs. Around line 36, you'll want to make sure you uncommented the line as below:
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/ApiDocumentation.xml")));
And make sure the path is correct. I happened to put my xml file in the App_Data directory.
Go to Project=>Properties=>Build. Under Output, make sure the "XML documentation file" box is checked, and point it to App_Data\ApiDocumentation.XML (assuming you put it in the same place i did above.
If i remember correctly, i had to make sure i added the .xml file to the project- i had some problems when i tried publishing it to our test server at work and it said the file couldn't be found. After you build, simply go to App_Data, right click on the folder, and add existing item. navigate to App_Data in your file system and select the xml file.
This will hopefully fix your problem!
I'm not sure if this will help anyone else that stumbles across this, I had started with a blank template from VS and added the help files via the Nuget package.
Because it was a blank template and I had no areas set up, it was missing the following from the global.asax
AreaRegistration.RegisterAllAreas();
This prevented the HelpPageConfig.Register from being called and thus, the Xml Documentation provider was never set.

Neo4J front end for movie example

I am looking at the Neo4J example here :
https://github.com/neo4j-examples/movies-java-spring-data-neo4j-4
This only contains .java source files.
Where is the code for the front end? Is it in a jar?
The frontend is a simple static HTML page that uses jQuery and d3. It is part of the Github repository in the src/main/resources/static directory. Specifically, this file.
More information about this example project is available on the Neo4j Developer Resources site

Using Swashbuckle to Host an Existing Swagger.JSON file

I have an existing Swagger.json file for a .NET WebApi site which I would like to integrate with my developer site (which is at a different url) running Swashbuckle.
Can I simply copy this swagger.json file to the mvc site (content or app_data folder and do this?)
If I can, where is the best place to put it.
How do I make this the default swagger file served up by the host?
The EnableSwagger method has two signatures, in one of them you can specify the route template to your files, so you can really serve it from wherever you want, just make sure your template matches the location of your json file. Take a look here: http://pastebin.com/MDfWNpUs

Resources