All Projects → chenjianjx → swagger2html

chenjianjx / swagger2html

Licence: Apache-2.0 license
swagger json => html doc readable by everybody

Programming Languages

java
68154 projects - #9 most used programming language
FreeMarker
481 projects
HTML
75241 projects
shell
77523 projects
Batchfile
5799 projects

swagger2html

Converts swagger jsons to html documents which are readable by everybody.

Swagger-Codegen already has a tool to generate html documents. However, it seems ugly and in lack of information.

petstore-by-swagger-cg


swagger2html produces a neat one:

petstore-by-s2h

Check the full html here.

How to run

Run as a command line tool

mvn clean package 
unzip target/swagger2html*jarset.zip -d /path/to/your/dir
cd /path/to/your/dir/swagger2html*
./s2h.sh http://petstore.swagger.io/v2/swagger.json /path/to/your/result/doc/file.html
# or s2h.bat for windows

Run it inside your application

In your pom.xml, add the following:

	<dependencies>
		...	
		<dependency>
			<groupId>com.github.chenjianjx</groupId>
			<artifactId>swagger2html</artifactId>
			<version>2.0.3</version>
		</dependency>
		...
	</dependencies>	
	Swagger2Html s2h = new Swagger2Html();
	Writer writer = new FileWriter("someFile.html");
	s2h.toHtml("http://petstore.swagger.io/v2/swagger.json", writer);

Customization of CSS

./s2h.sh http://petstore.swagger.io/v2/swagger.json \ 
    /path/to/your/html/doc/file.html -css /path/to/your/css/with/html/tag.html");  

A css template can be found at here. It's not a css file but css snippets and/or external css links in an html file.

In java program, you can

	String cssToInclude = FileUtils.toString("/path/to/your/css/with/html/tag.html");  
	Swagger2Html s2h = new Swagger2Html();
	s2h.toHtml("http://petstore.swagger.io/v2/swagger.json", cssToInclude , writer);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].