The best way to generate JSONs from Spring MVC for offline usage

2,683 views
Skip to first unread message

Marcin Zajączkowski

unread,
Dec 30, 2013, 9:04:18 AM12/30/13
to swagger-sw...@googlegroups.com
Hi. I have a Spring MVC based application with swagger-springmvc used to generate REST API documentation. I would like to have documentation served by Swagger-UI on some HTTP front server. I just need JSON files (which are generated from Spring MVC and Swagger annotations).

I could configure my CI server to setup Tomcat/Jetty with minimal Spring context, download online JSON files and put them on the HTTP server, but I wonder is there a simpler way to generate Swagger JSON files from Spring MVC application?

Marcin

--
http://blog.solidsoft.info/ - Solid Soft - Working code is not enough

tony tam

unread,
Dec 30, 2013, 1:12:35 PM12/30/13
to swagger-sw...@googlegroups.com
Hi, it really depends on what you're after.  If you want pure static documentation, look here:


If you want to simply create json files and from dynamic (server-generated) code, you might look at these tools:

Marcin Zajączkowski

unread,
Dec 30, 2013, 6:07:55 PM12/30/13
to swagger-sw...@googlegroups.com
On 2013-12-30 19:12, tony tam wrote:
> Hi, it really depends on what you're after. If you want pure static
> documentation, look here:
>
> https://github.com/wordnik/swagger-codegen#generating-static-api-documentation
>
> If you want to simply create json files and from dynamic (server-generated)
> code, you might look at these tools:
>
> https://github.com/wordnik/swagger-core/wiki/Java-Integrations#other-integrations

Thanks for your reply.

I am new to Swagger and maybe I don't understand it right, but after
reading documentation I see two stages:
- JSON documents describing the API (generated with swagger-spring-web
or any other Java integration or written manually)
- (Web) GUI presenting API (static generated pages based on
existing/generated JSON documents or more dynamic pages feeding with
JSON documents using Swagger UI)

In the second step I see a few interesting options, but the first step
is more problematic for me.

As I use Spring MVC (and its annotation) which are mostly supported by
swagger-springmvc (or swagger4spring-web) the only sensible way I see
(without manual writing JSON documents) is to setup mini Spring context
(just with controllers) and fetch generated JSONs to further usage.

Is it possible (supported) to generate JSON documents (for Spring MVC
application) just using static code parsing (without the need to run the
application)?

Marcin


> On Monday, December 30, 2013 6:04:18 AM UTC-8, Marcin Zajączkowski wrote:
>>
>> Hi. I have a Spring MVC based application with swagger-springmvc used to
>> generate REST API documentation. I would like to have documentation served
>> by Swagger-UI on some HTTP front server. I just need JSON files (which are
>> generated from Spring MVC and Swagger annotations).
>>
>> I could configure my CI server to setup Tomcat/Jetty with minimal Spring
>> context, download online JSON files and put them on the HTTP server, but I
>> wonder is there a simpler way to generate Swagger JSON files from Spring
>> MVC application?
>>
>> Marcin
>>
>> --
>> http://blog.solidsoft.info/ - Solid Soft - Working code is not enough
>>
>>
>


--
http://blog.solidsoft.info/ - Working code is not enough

Ron R

unread,
Jan 1, 2014, 8:29:19 AM1/1/14
to swagger-sw...@googlegroups.com
Marcin,

If you want to generate your code during your CI build, and assuming you use maven (or other build systems that can run maven plugins), you can use https://github.com/kongchen/swagger-maven-plugin to generate your json files during build and then deploy them to your HTTP server.
You always have the choice of directing your Swagger-UI to read the generated JSON files directly from your application though, which would make the deployment process simpler.
Reply all
Reply to author
Forward
0 new messages