Skip to content

Instantly share code, notes, and snippets.

@rbdixon
Last active August 29, 2015 14:17
Show Gist options
  • Save rbdixon/21fa977e4af15e7a0da7 to your computer and use it in GitHub Desktop.
Save rbdixon/21fa977e4af15e7a0da7 to your computer and use it in GitHub Desktop.
Can't reuse reusable parameters
{
"swagger": "2.0",
"info": {
"version": "1.0.9-abcd",
"title": "Swagger Sample API",
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://helloreverb.com/terms/",
"contact": {
"name": "wordnik api team",
"url": "http://developer.wordnik.com"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
}
},
"host": "my.api.com",
"basePath": "/v1",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json",
"application/xml"
],
"paths": {
"/pets/{id}": {
"get": {
"description": "Returns pets based on ID",
"summary": "Find pets by ID",
"operationId": "getPetsById",
"parameters": [
{ "$ref": "#/parameters/skipParam" },
{ "$ref": "#/parameters/limitParam" }
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "error payload",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/dup_pets/{id}": {
"get": {
"description": "Returns pets based on ID",
"summary": "Find pets by ID",
"operationId": "dupGetPetsById",
"parameters": [
{ "$ref": "#/parameters/skipParam" },
{ "$ref": "#/parameters/limitParam" }
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "error payload",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
}
},
"parameters": {
"skipParam": {
"name": "skip",
"in": "query",
"description": "number of items to skip",
"required": true,
"type": "integer",
"format": "int32"
},
"limitParam": {
"name": "limit",
"in": "query",
"description": "max records to return",
"required": true,
"type": "integer",
"format": "int32"
}
},
"definitions": {
"Pet": {
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"ErrorModel": {
"required": [ "code", "message" ],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
$ java -DdebugSwagger -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar -i ./reusableParameters.json -l html -o reusableParameters > reuse.out 2>&1
$ cat reuse.out
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
reading from ./reusableParameters.json
{
"swagger" : "2.0",
"info" : {
"description" : "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
"version" : "1.0.9-abcd",
"title" : "Swagger Sample API",
"termsOfService" : "http://helloreverb.com/terms/",
"contact" : {
"name" : "wordnik api team",
"url" : "http://developer.wordnik.com"
},
"license" : {
"name" : "Creative Commons 4.0 International",
"url" : "http://creativecommons.org/licenses/by/4.0/"
}
},
"host" : "my.api.com",
"basePath" : "/v1",
"schemes" : [ "http", "https" ],
"consumes" : [ "application/json" ],
"produces" : [ "application/json", "application/xml" ],
"paths" : {
"/dup_pets/{id}" : {
"get" : {
"summary" : "Find pets by ID",
"description" : "Returns pets based on ID",
"operationId" : "dupGetPetsById",
"parameters" : [ {
"$ref" : "#/parameters/skipParam"
}, {
"$ref" : "#/parameters/limitParam"
} ],
"responses" : {
"200" : {
"description" : "pet response",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Pet"
}
}
},
"default" : {
"description" : "error payload",
"schema" : {
"$ref" : "#/definitions/ErrorModel"
}
}
}
}
},
"/pets/{id}" : {
"get" : {
"summary" : "Find pets by ID",
"description" : "Returns pets based on ID",
"operationId" : "getPetsById",
"parameters" : [ {
"name" : "skip",
"in" : "query",
"description" : "number of items to skip",
"required" : true,
"type" : "integer",
"format" : "int32"
}, {
"name" : "limit",
"in" : "query",
"description" : "max records to return",
"required" : true,
"type" : "integer",
"format" : "int32"
} ],
"responses" : {
"200" : {
"description" : "pet response",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Pet"
}
}
},
"default" : {
"description" : "error payload",
"schema" : {
"$ref" : "#/definitions/ErrorModel"
}
}
}
}
}
},
"definitions" : {
"Pet" : {
"required" : [ "name" ],
"properties" : {
"name" : {
"type" : "string"
},
"tag" : {
"type" : "string"
}
}
},
"ErrorModel" : {
"required" : [ "code", "message" ],
"properties" : {
"code" : {
"type" : "integer",
"format" : "int32"
},
"message" : {
"type" : "string"
}
}
}
},
"parameters" : {
"skipParam" : {
"name" : "skip",
"in" : "query",
"description" : "number of items to skip",
"required" : true,
"type" : "integer",
"format" : "int32"
},
"limitParam" : {
"name" : "limit",
"in" : "query",
"description" : "max records to return",
"required" : true,
"type" : "integer",
"format" : "int32"
}
}
}
java.lang.ClassCastException: com.wordnik.swagger.models.parameters.RefParameter cannot be cast to com.wordnik.swagger.models.parameters.BodyParameter
at com.wordnik.swagger.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:796)
at com.wordnik.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:688)
at com.wordnik.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:239)
at com.wordnik.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:220)
at com.wordnik.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:108)
at com.wordnik.swagger.codegen.Codegen.main(Codegen.java:99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment