Skip to content

Instantly share code, notes, and snippets.

# process for creating a scala library for a swagger-enabled server
# build the codegen
ant
# generate the client library with the default (empty) api_key
./bin/generate-scala-lib.sh http://api.wordnik.com/v4 "" com.wordnik.client generated
# copy the sample build script
cp conf/scala/sample/* generated/
package com.wordnik.client
import com.wordnik.client.api._
import com.wordnik.client.model._
import com.wordnik.swagger.runtime.common._
object Test {
def main(args: Array[String]) = {
val securityHandler = new ApiKeyAuthTokenBasedSecurityHandler("{YOUR_KEY}", null)
@GET
@Path("/findByStatus")
@ApiOperation(value = "Finds Pets by status",
notes = "Multiple status values can be provided with comma seperated strings",
responseClass = "com.wordnik.swagger.sample.model.Pet", multiValueResponse = true)
@ApiErrors(Array(
new ApiError(code = 400, reason = "Invalid status value")))
def findPetsByStatus(
@ApiParam(value = "Status values that need to be considered for filter", required = true, defaultValue = "available",
allowableValues = "available,pending,sold", allowMultiple = true)@QueryParam("status") status: String) = {
override def onMessage(s: String) {
val objs = deserializers.filter(d => matchd(l, d))
objs.size match {
case 0 => //oops, nothing can do it
case _ => objs(0).deserialize(s)
}
}
@fehguy
fehguy / gist:4191861
Created December 3, 2012 00:45
Json4s + salat sample
import java.util.Date
// define some classes
case class Child (name: String, birthdate: Date)
case class Spouse (name: String, birthdate: Date)
case class Address (address1: String,
address2: String,
city: String,
state: String,
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs.json",
apiKeyName:"apikey",
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
DocumentationObject obj = new DocumentationObject();
obj.setName("Manual");
obj.addField(new DocumentationParameter(
"fieldA", // attribute name
"The field of Manual", // description, optional
"Notes", // notes about this field, optional
"String", // the attribute type
null, // default value, null if none
null, // allowable values, null if none
@fehguy
fehguy / gist:5304290
Last active December 15, 2015 18:29
Creating a custom config reader in java
/*
in your web.xml, specify this as a custom reader
<init-param>
<param-name>swagger.config.reader</param-name>
<param-value>com.wordnik.swagger.sample.CustomConfigReader</param-value>
</init-param>
*/
@fehguy
fehguy / gist:5400909
Created April 17, 2013 00:50
Creating client libs for subtledata api
git clone git@github.com:wordnik/swagger-codegen.git
./sbt assembly
# generate java library in generated-code/java
scala -cp target/swagger-codegen-assembly-2.0.2-SNAPSHOT.jar com.wordnik.swagger.codegen.BasicJavaGenerator http://developers.subtledata.com/swagger/api-docs.json
# build the library
cd generated-code/java
mvn package
@fehguy
fehguy / gist:5955214
Created July 9, 2013 06:52
Calling your API in javascript with swagger
// install the swagger-client
npm install swagger-client
// start the node repl
node
> var swagger = require("swagger-client");
> var s = new swagger.SwaggerApi("http://petstore.swagger.wordnik.com/api/api-docs.json");
// build the swagger client
> s.build();