Trying to develop a consumer for the Myfox API, I realised that the API documentation had been generated by Swagger. As the Swagger website states, "Swagger™ is a specification and complete framework implementation for describing, producing, consuming, and visualising RESTful web services."
"Consuming" ? Hmmm, it might be interesting to dig a bit… So, I dug.
First, I had to “install” Swagger-codegen to be able to generate the client code.
And it’s been a bit more challenging than anticipated.
Here are the steps I followed and the issues I ran into.
First, install Java 1.7. You can grab the JDK on the Oracle website :
Once downloaded, install it like any other mac app.
Next, install maven :
brew install maven31
Yes I use Homebrew. You should too.
Then Scala :
brew install scala210
Clone the Swagger-codegen repo :
git clone https://github.com/wordnik/swagger-codegen
And run :
cd swagger-codegen; ./sbt assembly
You’re all set ! Now you should be able to generate code with a command like this one :
./bin/runscala.sh com.wordnik.swagger.codegen.BasicPHPGenerator http://www.myfox-swagger.loc
As I said, I ran into several issues. Here they are, with their resolution.
The first time I ran the generation command above, I got this error :
java.net.UnknownHostException: laurents-mbp: laurents-mbp: nodename nor servname provided, or not known
This one was easy to solve by adding a line to my /etc/hosts file :
sudo echo "127.0.0.1 laurents-mbp" >> /etc/hosts
At first try, following the installation guide from the official repo, I had install scala 2.9.3. Which gave me the following error :
sbt.ResolveException: unresolved dependency: org.scalatest#scalatest_2.9.3;2.1.7: not found
Resolution : Uninstall scala 2.9 and install scala 2.10
brew uninstall scala29
brew install scala 210
But if was not finished. I still had this error :
Please set scalaVersion := "2.10.4" in build.sbt and run ./sbt assembly
Even if it was already the case…
It turned out that the following command solved this last issue :
mv target/scala-2.10 target/scala-2.10.4