Swagger code generator online

6,710 views
Skip to first unread message

tony tam

unread,
Feb 24, 2015, 12:14:16 PM2/24/15
to swagger-sw...@googlegroups.com
Hi all, thought you might enjoy this.  You can now generate both clients and servers online using our online generator:


This allows you to post a configuration up to the server and allows for a download of the client or server directly from our server.  You can pass a URL:

or a swagger spec directly:

{
 
"spec": {
   
"swagger": "2.0",
   
"title": "Petstore Sample API",
   
...
 
}
}

The input arguments are defined in the swagger spec for the online generator:


And... drumroll... you can actually generate clients and servers now via cURL!

For objective-c:

curl -X POST -H "accept:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/clients/objc

for java:

curl -X POST -H "accept:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/clients/java


for nodejs (a server:

curl -X POST -H "accept:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/servers/nodejs


This works for any of the client or server languages supported (there's an API for that!)


If that isn't cool, tell me what is.  Try it out, grab the source from swagger-codegen

Please send feedback, issues, etc.  Happy 'gening.

a bird

unread,
Feb 25, 2015, 4:19:07 PM2/25/15
to swagger-sw...@googlegroups.com
I'm getting a HTTP 415 response when curl-ing

curl -sX POST -H "accept:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' "http://generator.swagger.io/api/gen/clients/java" | python -mjson.tool
{
   
"code": 415,
   
"message": "HTTP 415 Unsupported Media Type",
   
"type": "unknown"
}



Tony Tam

unread,
Feb 25, 2015, 4:21:21 PM2/25/15
to swagger-sw...@googlegroups.com
Oops. My example should be "content-type:application/json". Can you please try with that?


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

a bird

unread,
Feb 25, 2015, 4:24:52 PM2/25/15
to swagger-sw...@googlegroups.com
Nice! That did the trick.

Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Julian Lyndon-Smith

unread,
Dec 4, 2015, 11:02:28 AM12/4/15
to Swagger
Hi Tony - I need to be able to use the online generator for one of my apis, but unfortunately it is behind a firewall so the url is not reachable outside the corporate network

Is it possible to get access to the source for this project so I can build and run the server on premise ?

Thanks

tony tam

unread,
Dec 4, 2015, 11:03:33 AM12/4/15
to swagger-sw...@googlegroups.com
You bet!


See build instructions at the top of the project.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Julian Lyndon-Smith

unread,
Dec 4, 2015, 1:44:24 PM12/4/15
to Swagger
wow. ok, so now I *really* do feel like an idiot - wtf do I do once I've built this ?

I have a working docker container, and can spit things out from the command line - but how do I start the server part and keep it running ? 

please go easy. it's friday. it's been a long week. I'm old and tired ;)

thanks

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

tony tam

unread,
Dec 4, 2015, 1:55:01 PM12/4/15
to swagger-sw...@googlegroups.com
I’m old and tired too :)  But no problem!

You can run with “mvn package jetty:run” and it’ll be running locally on port 8001.  And if you want to run it as a service, by running “mvn package” you’ll see a war file in the target folder.  That can be dropped into any container such as jetty, tomcat, etc.

When it’s running locally:


Will show you what you’re looking for.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Julian Lyndon-Smith

unread,
Dec 4, 2015, 2:12:57 PM12/4/15
to Swagger
yeah ... well ... I've got the same errors that I had before - I thought at first it was my mistake .. but ..

so the standalone generator works just fine (java -jar etc)

however, when I try and run with the mvn thing, I get the errors below

the command line was

docker run swagger-codegen mvn package jetty:run

#1 I built the docker image using the dockerFile that's in the main directory - why is it trying to download more stuff when I run (I obviously don't want to be doing this every time I start the container, so it needs to be done in the docker file 
#2 the build failure does not look good .. but I have not a clue on what's gone wrong or why

Julian
 

tony tam

unread,
Dec 4, 2015, 3:01:44 PM12/4/15
to swagger-sw...@googlegroups.com
Can you please run mvn clean package from the top-level project?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Julian Lyndon-Smith

unread,
Dec 4, 2015, 3:26:00 PM12/4/15
to Swagger
sorry, not sure what you mean - this is running in a docker container, so the only thing that has been done is

git clone repo
then run docker build .

where the Dockerfile contains:

ADD . /opt/swagger-codegen

RUN cd /opt/swagger-codegen && mvn package

so, it's already a clean build from the base source - do you want me to make that

RUN cd /opt/swagger-codegen && mv clean && mvn package

thanks

Julian Lyndon-Smith

unread,
Dec 5, 2015, 7:00:15 AM12/5/15
to Swagger
ok, finally figured out that maven is a build tool and jetty is a web server. Serves me right for trying to use this java stuff ;)

but .. 

running with this command

java -jar /opt/swagger-codegen/modules/swagger-codegen-cli/target/lib/jetty-runner.jar /opt/swagger-codegen/modules/swagger-generator/target/swagger-generator-*.war

brings up this

which kinda looks nothing like this http://generator.swagger.io/ :)


in a nutshell - has *anyone* managed to get an on-premise version of swagger-codegen running ? What steps do you need to do ?

and - more importantly - has anyone got a comple Dockerfile for producing a swagger-codegen container ?

thanks!

tony tam

unread,
Dec 7, 2015, 12:41:46 AM12/7/15
to swagger-sw...@googlegroups.com
A war file is not an executable jar.  You’ll have to drop it into a servlet container.

I’ve suggested two different approaches:

1) Run with mvn jetty:run.  This will both build and run jetty with the web app locally.  You can see that it works by going to http://localhost:8001/?url=http://localhost:8001/api/swagger.json.

2) Download any modern servlet container and drop the war file in the web apps folder.  For example:



To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Julian Lyndon-Smith

unread,
Dec 7, 2015, 4:14:56 AM12/7/15
to Swagger
Hi Tony, as mentioned in my previous post, I managed to get the war file deployed and running in a jetty container - but it doesn't work well, as you can see from the screenshot

I was now wondering what else I am missing

thanks
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

tony tam

unread,
Dec 7, 2015, 9:30:50 AM12/7/15
to swagger-sw...@googlegroups.com
It seems like you want to do it differently, and it is leaving you on your own, so it’s not really easy to help you.

From your command line and screen shot, it looks like you should be opening port 8080, not port 80.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

sprin...@gmail.com

unread,
Jun 4, 2018, 2:18:33 AM6/4/18
to Swagger
curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' http://generator.swagger.io/api/gen/clients/csharp

consistently throws:

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

But I really can't see what's incorrect. Both URIs resolve, options look good, no weird characters ...

sprin...@gmail.com

unread,
Jun 4, 2018, 11:29:29 PM6/4/18
to Swagger
This is seems to be related to escaping quotes and quote type.

This worked:

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

Note singled quotes replaced by double and inner double quotes escaped with "\".

This is the kid of thing that happens to us lowly Windows people when Linux, et al, developers are ensconced in their wood-sheds too long ...


Reply all
Reply to author
Forward
0 new messages