I am currently battling a swagger configuration for my spring MVC RESTful services project. I decided to follow the swagger-spring but I fail to understand if the UI part of swagger should be a totally different project or should it reside in the same context on the container?
The swagger json from my spring mvc based RESTFul services is showing up correctly on a link like: http://<server>:<port>/<context>/api-docs but whenever I put in the swagger UI components in the application(JSP, CSS and JS files), I cannot access the swagger UI, which should look like this.
You need to update index.html that came with swagger-ui. Update below line to your webapp URL.
url: "http://petstore.swagger.wordnik.com/api/api-docs",
Related
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
We have a .NET solution with 2 projects:
ASP.NET MVC Portal project
OWIN Host API project (with custom
controller selector)
We are trying to expose a public documentation to a few API controllers in the OWIN-based API project
We would like to show the Swagger UI from the Portal project for controllers in the API project
So far, all attempts have not been successful. When adding Swagger UI to the Portal project, it only wants to show documentation about controllers in the Portal project, not from the API project.
When adding Swagger UI to the API project (not preferred solution), it doesn't work at all, probably because of the custom controller selector
However, I think I'm missing something obvious as this feels like a very basic configuration setting that we're missing
Swagger UI is only a set a static file rendering OpenAPI (fka. Swagger) Specification files. These specification files can be produced by an application or simply manually written.
You could modify the original Swagger UI to create your own version and replace the URL field (on top near the Authorize button) by a drop list pointing to your 2 different applications producing OpenAPI (fka. Swagger) specification.
I have created a new WEB API project integrating Swashbuckle and Swagger UI.
I am able to access Swagger web page via http://localhost:port/swagger/ui/index#/
However, where is the view/index.html/index.cshtml for this page?
I am a newbie to MVC, please help.
The swagger-ui is served by the swashbuckle assembly. The source is not available in your project. You can, however, retrieve the source from github and inject it in swashbuckle as described in the swashbuckle documentation
I have a Dropwizard application with Swagger annotated Java resource classes. I'm also creating programatic REST resources which, of course, don't end up in the generated Swagger JSON. Is it possible to programmatically add operations via the Java Swagger API such that they end up in the generated JSON along with the annotated resources?
I tried using DefaultJaxrsApiReader.appendOperation but it had no effect.
I'm using com.wordnik:swagger-jaxrs_2.10:1.3.12
EDIT
I ended up just writing a Servlet filter to update the Swagger JSON response. It would be great to get #fehguy's suggestions working somehow. I think that swagger-jaxrs_2.10:1.3.12 isn't new enough to support those POJOs.
as of swagger-core-1.5.1-M1, you can build a swagger POJO which simply needs to be returned by your web application. That means, you can programmatically create the Swagger object and serve it up as JSON from your web service.
For examples of how to build a swagger pojo you can look at the source or an example (test) of building one.
You can also mutate the generated swagger object in your application. That means you can dynamically generate / modify swagger at runtime. There is an example in the swagger-codegen project, where the online code generator (swagger-generator) will detect what languages are enabled in the code generation logic via SPI, and update the swagger spec accordingly with the options:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/DynamicSwaggerConfig.java
I'm creating an application with a .Net Web Api project wanting to use pure AngularJS as the client side. Since Web Api is built on top of MVC, it creates MVC specific and default items that I feel is not needed. These items include the HomeController, _ViewStart.cshtml, _layout.cshtml, etc. I tried removing them but it comes up with errors. Has anyone tried to remove the MVC stuff out of the web api project and used separate client side front-end? Is it even possible to remove the MVC items without errors?
Remove RouteConfig.cs from App_Start, remove the Views directory and all sub-directories including the Views internal web.config file. Comment out or delete all the lines in the Global.asax.cs Application_Start method except GlobalConfiguration.Configure(WebApiConfig.Register). Remove the HomeController, add an index.html and any needed Angular scripts and go at it. I also added solution folders to organize my views as reusing the existing Views folders did not work. I'm using VS 2015 but is should work for 2013 also. PWE
Web API is not built on top of MVC.
The default templates bring in MVC for the sake of supporting a help page, but you don't need to use it.
You can start with an empty web project and just check Web API.
The routing piece is server routing and it's part of what maps the URL to Controllers+Actions, it has nothing to do with Angular routing.
As Mike Cheel alluded to, there are no dependencies between MVC and Web API. However, if you use the built-in templates, it's easy to get the impression that the 2 are linked. They include a lot of stuff in these templates because they can't anticipate where you want to go with your project... so they try to cover all the bases.
For your purposes, you would probably be better off to start with an empty project and add only the components that you actually need. For this approach, some of the best tutorials and starter projects are from Taiseer Joudeh's "Bit of Technology" blog. His tutorials helped me to build an "MVC Free" web application from scratch that uses JSON Web Tokens and AngularJS Interceptors for security and Web API 2 and Entity Framework to serve up the data.
He has many tutorials on his website... but you might want to start with "AngularJS Token Authentication using ASP.NET Web API 2, Owin, and Identity". What what.. you didn't ask about security? Well... security is an issue that you will need to confront at some point anyway... and Taiseer presents a nice solution for securing an Angular/Web API application.