Swagger custom documentation - java

Is there a way to generate a README.md file from swagger? I would like to put similar details that would be found in swagger web page plus some custom comments.
Also, is there a way to make a aggregator swagger web page? I want to have the all swagger web pages from all micro services also in a single place. This could enable me to take higher picture notion of my system and maybe do some queries like "how
many ways certain entity can get this another entity?".

Regarding README.md file - not sure what information you want to include in it, but you can write your own method which will do it using Swagger Parser in order to get required information from Swagger specification.
Regarding aggregated swagger - you can use Swagger-aggregate for this purpose.

Related

How can I add HTML and CSS specs to this simple Spring project?

I've been playing around with some Spring Boot tutorials (most importantly Building A Restful Service). I am getting output as JSON in my browser.
I would like to know how I can read the JSON into HTML & CSS to make it look nice. My three java files are 'Application.java' 'Greeting.java' and 'GreetingController.java'.
I don't want to overload with my code, but basically I made it so that when I enter
localhost:8080/greetings/add?name=User ('User' can be whatever)
it adds the user to an Arraylist, and then at localhost:8080/greetings it prints out all the greetings, like this:
How do I get it to be read into HTML & CSS, so I could get something like this (different content of course, but just a table that takes in the JSON)?
Here's the github link if interested: https://github.com/josephmalisov/SpringBootGreetings
The Spring guide "Serving Web Content with Spring MVC" provides an answer. In your controller, add your object to your model and then return the name of a template page. e.g.
model.addAttribute("name",name);
Loops in Thymeleaf are an easy way to build your table. Include your github repo and I'll send you a pull request (maybe).

Generating HTML documentation with Swagger 2.x via Maven

I am looking at generating some API documentation, hopefully using Swagger, in a few different projects of mine. Having never used Swagger, I am trying to find a very simple solution to generating HTML documents via Maven.
The underlying REST framework being used in these projects is Jersey. I found documentation from Swagger but it doesn't seem to have any examples of simply producing HTML files. Most of their examples seem to embed the API documentation into the actual service itself.
So my questions are:
How can I generate HTML documentation with Swagger via Maven?
Is attaching the documentation along with the service normal to do with REST applications?
You will need to use swagger-codegen to generate an HTML.
https://github.com/swagger-api/swagger-codegen#generating-static-html-api-documentation
To generate the HTML doc with swagger-codegen, you will first need to generate an OpenAPI documentation. Since you are already using Jersey as your REST framework, it is probably the easiest to pull in swagger as a dependency into your project and annotate all your API servlets. Doing so, will tell swagger to read all your code and generate an OpenAPI spec. You can follow the steps in https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration to get started.
Good luck!

swagger codegen keyword additions

I have to maintain a project that uses Swagger to codegen the api interface. Looking at the model.mustache, I see this:
{{#models}}
{{#model}}{{#description}}
/**
* {{description}}
**/{{/description}}
and a bunch of other keywords like enum, defaultValue, vars, package, etc. Where do these come from? I've been scouring the internet trying to find swagger documentation on this but I cannot find anything. Lots of the links that refer to swagger info on github return 404 pages. In the end, what I want to be able to do is to have a property exist in my actual .json file that swagger is using to generate the interfaces and models to conditionally generate code. I saw that there is the
{{#property}}{{/property}}
{{^property}}{{/property}}
notation for if/else statements, but it doesn’t work on any property of my own .json. For example, in my json I have an id field. So if I wanted to do a contrived example
{{#id}}System.out.println(“test test”);{{/id}}
won’t work because swagger does not recognize the id tag. So my question is, can I add these tags?
there are lots of tools to help out. If you see broken links, please submit issues to the swagger-codegen project.
As of 2.1.x-M1, swagger-codegen has a very helpful "debug" mode which lets you list all the possible values for your environment. You can invoke it as follows:
java -DdebugModels -jar {path-to}/swagger-codegen-cli.jar generate {opts}
The supported debug flags are:
-DdebugModels: outputs the variables for each model discovered by codegen
-DdebugOperations: outputs the variables for each operation
-DdebugSupportingFiles: shows supporting file data (anything but models or operations)
-DdebugSwagger: shows the parsed swagger representation
I do see that these are missing from the README. Will make sure they get added.

Java or JavaScript library to generate HTML from Swagger, RAML or API Blueprint

Problem:
I am searching for a library in Java or JavaScript (or maybe Scala) which is able to generate an HTML representation of Swagger, RAML or API Blueprint input.
Background:
The idea is to use it as a part of a (Play Framework) web app serving as an API catalog. API specifications would be added by users of the API catalog and resulting HTML representations would be generated/displayed.
It would give extra value if a API specification stub also is possible to create using a Java API. The API catalog web app has a data model which I would like to use when generating the API stubs.
Furthermore, it would give extra value if the same (or related another) library provided a nice HTML editor of the API specification language (Swagger, RAML, API Blueprint etc) supporting the user while editing.
Swagger offers a set of tools to do it.
Swagger-Core will enable you to produce Swagger documentation from your Play code. This is done at runtime and will change as your application changes.
Swagger-UI will read such docs and display them in an HTML format. It also allows you to execute the operations and has integration with security mechanisms if needed. The UI can be customized to have the look-and-feel of your application (like many have done so far).
Swagger-Editor allows for direct editing of Swagger documentation with interactive side-by-side view of the docs in an HTML format.
Swagger-Codegen can take such a documentation and generate both client and server code. You can customize the templates to suit your needs.
There are several tools for for generating HTML from an API Blueprint, one of which is in Coffeescript and is called Aglio. You can see all of the tools here:
http://apiblueprint.org/
Also, Apiary is a service that uses API Blueprint and can be used for editing and hosting generated documentation, hooking up with Github to auto-generate from commits, providing some mocking APIs and some other cool stuff for teams and enterprises. You could check it out if you're wanting a solid service for your API documentation.
For RAML you have:
- https://github.com/kevinrenskers/raml2html
- https://github.com/mikestowe/php-raml2html
Give those a try ;)

Adding content to Liferay via API

I am starting using Liferay Portal and I have two basic needs which I would like to achieve with Liferay.
Is there a posibility to add content to CMS through API level? I would like to insert some data "from code".
More important. How to achieve such situation that for every created user there will be its own homepage generated with some predefined template elements on it?
I have tried to Google something so far, but I did not find it helpful. Maybe some keywords?
After some analysis of documentation devoted to services and ServiceBuilder I realized that it is not what I want.
Let me show an example based on Websphere.
In Websphere we have bunch of EJB components available to perform some actions, exchange information with portal, easy to use. Isn't there any similar mechanism in Liferay not involving web services?
My recommendation for this kind of question is to take a look at the sevencogs-hook sourcecode. The structure of this hook is basically just a long script that runs once, setting up a complete demo site with users, sites, pages, content etc. The code runs once (after the first deployment) and then never again. There are no (obvious) conditionals, no context to understand etc.
You can basically just step through everything and - in that process - understand how content (and pages, images, blog posts, etc.) are created and positioned on pages in Liferay.
This hook accesses the Java API, a very similar API is available through Webservices. Basically all of Liferay's portlets also use the same API to do their business.
Edit: Additional information to keep this answer valuable/current: Sevencogs is discontinued, but still available in old releases (source & binary). The API has slightly changed, so compiling/running it will need a bit of work. James Falkner has blogged about the leftovers and lessons learnt - those snippets are extracted from sevencogs and contain the relevant code pieces to work with the API.
Looking at this page from the documentation: It smells like a SOAP interface (they mention some sort of document uploader service and I've read axis).
You'll find some url examples that should give a list of available webservices.
For number 1, you can use the one of the:
JournalArticleLocalServiceUtil.addArticle()
methods to programmatically add Liferay Web Content from a portlet. If you download the Liferay Portal Source you can see the structure of these methods.
For number 2, can create page templates with preconfigured portlets on them (through the Plugins-SDK), and then use the API to programmatically create the pages using one of the:
LayoutLocalServiceUtil.addLayout()
methods.
If you have any more speific questions about these comment back, and I hope this helps!

Categories