[swagger-springmvc + swagger-codegen] generate plain html

435 views
Skip to first unread message

Michał Witkowski

unread,
Feb 17, 2015, 6:20:49 PM2/17/15
to swagger-sw...@googlegroups.com
Hello

I have a problem with generating html docs based on json provided by swagger-springmvc. Everything looks great in Swagger-UI, but i have to send my documentation in html offline document so...

I'm running application (http://127.0.0.1:8080/core/api-docs) which returning this one...
{
apiVersion: "1.0",
apis: [
{
description: "Action request interface for admin",
path: "/default/action-request-admin",
position: 0
},
{
description: "Action request interface for dashboard",
path: "/default/action-request-dashboard",
position: 0
},
{
description: "X Domain Controller",
path: "/default/x-domain-controller",
position: 0
}
],
authorizations: { },
info: {
contact: "xx...@xxxx.pl",
description: "This is reference document for the REST API.",
license: "Licencja...",
licenseUrl: "http://www.xxxx.pl",
termsOfServiceUrl: "My Apps API terms of service",
title: "XXXX REST API 1.0"
},
swaggerVersion: "1.2"
}

Now i would like to generate html based on returning json so i tried to run codegen 
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar -i http://127.0.0.1:8080/core/api-docs -l html -o test/

but then i get error 

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

reading from http://127.0.0.1:8080/core/api-docs

reading from http://127.0.0.1:8080/core/api-docs

java.lang.RuntimeException: missing swagger input or config!

at com.wordnik.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:31)

at com.wordnik.swagger.codegen.Codegen.main(Codegen.java:99)


What could be wrong? I would be greatfull for any hint :)
 

tony tam

unread,
Feb 17, 2015, 6:32:27 PM2/17/15
to swagger-sw...@googlegroups.com
Hi Michal, there must be something unsupported in the JSON generated by swagger-springmvc.  I'd suggest the following:

1) Point the codegen at individual api declarations.  This can help determine which one is invalid--specifically try this:


repeat for each of your `path` items from the resource listing that you posted

2) save the files locally into a single folder and point the generator directly to those files.  That gives you the ability to change whatever is invalid in them.

Without seeing the individual api declarations, it's hard to say what's not valid in them.  You can of course post more details if you like

Michał Witkowski

unread,
Feb 17, 2015, 6:44:48 PM2/17/15
to swagger-sw...@googlegroups.com
I also tried to generate html from sample file unfortunately with same result









java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar -i /Users/rastabandita/Documents/swagger-codegen/modules/swagger-codegen/src/test/resources/1_2/petstore-1.2/api-docs -l html -o test/


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".


SLF4J: Defaulting to no-operation (NOP) logger implementation


SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.


reading from /Users/rastabandita/Documents/swagger-codegen/modules/swagger-codegen/src/test/resources/1_2/petstore-1.2/api-docs


reading from /Users/rastabandita/Documents/swagger-codegen/modules/swagger-codegen/src/test/resources/1_2/petstore-1.2/api-docs


java.lang.RuntimeException: missing swagger input or config!


        at com.wordnik.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:31)


        at com.wordnik.swagger.codegen.Codegen.main(Codegen.java:99)


Please take a look on swaggerVersion. While i tring to generate files with swaggerVersion 1.2 it doesn't work, but sample based on swaggerVersion 2.0 works great.  I think i have two choices :
1) Change swaggerVersion to 2.0 in swagger - springmvs (don't know how)
2) Force codegen to works with swaggerVersion 1.2 (don't know how) :(

tony tam

unread,
Feb 17, 2015, 7:26:36 PM2/17/15
to swagger-sw...@googlegroups.com
Looks like an issue in the assembly task, it must be losing one of the service descriptors.

In the mean time, you can run it like such:

$ java -cp modules/swagger-codegen/target/*:modules/swagger-codegen/target/lib/* com.wordnik.swagger.codegen.Codegen -i modules/swagger-codegen/src/test/resources/1_2/petstore-1.2/api-docs -l html -o tmp

The only difference with doing this is, each of the libraries is kept separately as opposed to being smashed into an uber jar.

See issue here:  https://github.com/swagger-api/swagger-codegen/issues/437

tony tam

unread,
Feb 17, 2015, 7:45:25 PM2/17/15
to swagger-sw...@googlegroups.com
Also... you can just use our online codegen as follows:

curl -X POST -H "content-type:application/json" -d '{"swaggerUrl" : "http://petstore.swagger.io/api/api-docs"}' http://generator.swagger.io/api/gen/clients/html

Note that this is pointing to a swagger 1.2 version.  It will give you a download link to grab the generated html file.


Michał Witkowski

unread,
Feb 18, 2015, 4:12:37 AM2/18/15
to swagger-sw...@googlegroups.com
Thank you Tony for your help, everything works now beautifully

tony tam

unread,
Feb 18, 2015, 8:34:59 AM2/18/15
to swagger-sw...@googlegroups.com
Great! Also there has been a patch release of 2.1.1-M1 to address the underlying issue that you discovered
Reply all
Reply to author
Forward
0 new messages