Skip to content

Instantly share code, notes, and snippets.

commons-lang-2.4.jar
dom4j-1.6.1.jar
guava-11.0.2.jar
jackson-annotations-2.1.5.jar
jackson-core-2.1.5.jar
jackson-databind-2.1.5.jar
jackson-jaxrs-json-provider-2.0.0.jar
jackson-module-jaxb-annotations-2.0.0.jar
jackson-module-jsonSchema-2.1.0.jar
jackson-module-scala_2.10-2.1.5.jar
@fehguy
fehguy / gist:6645523
Last active December 23, 2015 13:59
validating your swagger spec

build.sbt

name := "swagger-validator"

libraryDependencies ++= Seq(
  "com.github.fge" % "json-schema-validator" % "2.1.7"
)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<name>test</name>
<version>1.0.0-SNAPSHOT</version>
<prerequisites>
<maven>2.2.0</maven>
@fehguy
fehguy / gist:7571252
Created November 20, 2013 21:20
Using swagger-js to create objects
var client = require("swagger-client");
client.authorizations.add("key", new client.ApiKeyAuthorization("api_key", "special-key", "query"))
var swagger = new client.SwaggerApi({
url: "http://petstore.swagger.wordnik.com/api/api-docs",
success: function() {
if(swagger.ready === true) {
var json = JSON.stringify({
"id": 1,
@fehguy
fehguy / wordnik-swagger
Created December 6, 2013 23:43
Calling wordnik api with swagger-js
var client = require("swagger-client");
client.authorizations.add("key", new client.ApiKeyAuthorization("api_key", "YOUR_KEY", "header"))
var swagger = new client.SwaggerApi({
url: "https://api.wordnik.com/v4/resources.json",
success: function() {
if(swagger.ready === true) {
swagger.apis.word.getDefinitions({word:"cat"},
function(data) {
@fehguy
fehguy / gist:8461152
Last active January 3, 2016 12:09
input vs. output models described with subtypes
apiVersion: 1.0.0
swaggerVersion: "1.2"
basePath: "http://localhost:8002/api"
resourcePath: /pet
produces:
- application/json
- application/xml
- text/plain
- text/html
apis:
@fehguy
fehguy / gist:10599043
Created April 13, 2014 19:37
Swagger 1.2 transition

==========

Not to be confused with the swagger framework versioning, the swagger specification itself is versioned for compatibility. You can see information about previous versions in the wiki.

Philosophically, any changes to the spec are absorbed into the tools for one-version backwards compatibility. So the swagger-ui will work with both swagger-spec 1.1 and 1.2. It is not tested against older versions (prior to 1.1). Changing a specification typically causes some heartache and pain, so the changes introduced are usually not just for fun--they have a history of issues or confusion behind them, which mandates the change.

You can use the swagger-codegen to migrate your swagger 1.1 spec! Please see HERE for details.

That said, here's a transition guide for the 1.2 specification.

def listing(docRoot: String, app: Application, sc: ServletConfig): Option[Map[String, ApiListing]] = {
var _cache: Option[Map[String, ApiListing]] = None
_cache.orElse{
LOGGER.debug("loading cache")
ClassReaders.reader.map{reader =>
ScannerFactory.scanner.map(scanner => {
val classes = scanner match {
case scanner: JaxrsScanner => scanner.asInstanceOf[JaxrsScanner].classesFromContext(app, null)
case _ => List()
fehguy:swagger-core-master tony$ git status .
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
fehguy:swagger-core-master tony$ mvn clean install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.wordnik:swagger-utils_2.10:jar:1.3.5
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.reflections:reflections:jar -> duplicate declaration of version 0.9.8 @ line 57, column 17
@fehguy
fehguy / gist:c100e957219336e5f3c0
Last active August 29, 2015 14:01
Calling wordnik API
window.authorizations.add("api_key", new ApiKeyAuthorization("api_key", "YOUR_KEY", "header"));
var args = {word: "cat"};
wordnik = new SwaggerApi({
url: "https://api.wordnik.com/v4/resources.json",
success: function() {
if(wordnik.ready === true) {
wordnik.word.getDefinitions(args, function(data){
var definitions = data.obj; console.log(definitions[0].word);