Skip to content

chenjianjx/swagger2html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);