Skip to content

Commit

Permalink
Merge pull request OAI#114 from fehguy/master
Browse files Browse the repository at this point in the history
added support for models and parameters in `#/definitions` section
  • Loading branch information
fehguy committed Aug 29, 2014
2 parents 3ba56ac + 3b9fa2a commit e581516
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 85 deletions.
105 changes: 105 additions & 0 deletions fixtures/v2.0/json/resources/reusableParameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"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": "Pet"
}
}
},
"default": {
"description": "error payload",
"schema": {
"$ref": "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"
}
}
}
}
}
183 changes: 98 additions & 85 deletions schemas/v2.0/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,90 @@

"type": "object",
"required": [ "swagger", "info", "paths" ],

"additionalProperties": false,
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
},
"properties": {
"swagger": {
"type": "number",
"enum": [ 2.0 ],
"description": "The Swagger version of this document."
},
"info": {
"$ref": "#/definitions/info"
},
"externalDocs": {
"$ref": "#/definitions/externalDocs"
},
"host": {
"type": "string",
"format": "uri",
"pattern": "^((?!\\:\/\/).)*$",
"description": "The fully qualified URI to the host of the API."
},
"basePath": {
"type": "string",
"pattern": "^/",
"description": "The base path to the API. Example: '/api'."
},
"schemes": {
"type": "array",
"description": "The transfer protocol of the API.",
"items": {
"type": "string",
"enum": [ "http", "https", "ws", "wss" ]
}
},
"consumes": {
"type": "array",
"description": "A list of MIME types accepted by the API.",
"items": {
"$ref": "#/definitions/mimeType"
}
},
"produces": {
"type": "array",
"description": "A list of MIME types the API can produce.",
"items": {
"$ref": "#/definitions/mimeType"
}
},
"paths": {
"type": "object",
"description": "Relative paths to the individual endpoints. They must be relative to the 'basePath'.",
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
},
"^/.*[^\/]$": {
"$ref": "#/definitions/pathItem"
}
},
"additionalProperties": false
},
"definitions": {
"type": "object",
"description": "One or more JSON objects describing the schemas being consumed and produced by the API.",
"additionalProperties": { "$ref": "#/definitions/schema" }
},
"parameters": {
"type": "object",
"description": "One or more JSON representations for parameters",
"additionalProperties": { "$ref": "#/definitions/parameter" }
},
"security": {
"$ref": "#/definitions/security"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/tag"
}
}
},
"definitions": {
"externalDocs": {
"type": "object",
Expand Down Expand Up @@ -151,7 +234,18 @@
"minItems": 1,
"additionalItems": false,
"items": {
"$ref": "#/definitions/parameter"
"oneOf": [
{ "$ref": "#/definitions/parameter" },
{
"type": "object",
"additionalProperties": false,
"properties": {
"$ref": {
"type": "string"
}
}
}
]
}
},
"responses": {
Expand Down Expand Up @@ -251,7 +345,7 @@
"properties": {
"type": {
"type": "string",
"enum": [ "string", "number", "boolean", "integer", "array" ]
"enum": [ "string", "number", "boolean", "integer", "array", "file" ]
},
"format": {
"type": "string"
Expand Down Expand Up @@ -299,7 +393,7 @@
},
"type": {
"type": "string",
"enum": [ "string", "number", "boolean", "integer", "array", "file" ]
"enum": [ "string", "number", "boolean", "integer", "array" ]
},
"format": {
"type": "string"
Expand Down Expand Up @@ -437,86 +531,5 @@
}
}
}
},
"additionalProperties": false,
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
},
"properties": {
"swagger": {
"type": "number",
"enum": [ 2.0 ],
"description": "The Swagger version of this document."
},
"info": {
"$ref": "#/definitions/info"
},
"externalDocs": {
"$ref": "#/definitions/externalDocs"
},
"host": {
"type": "string",
"format": "uri",
"pattern": "^((?!\\:\/\/).)*$",
"description": "The fully qualified URI to the host of the API."
},
"basePath": {
"type": "string",
"pattern": "^/",
"description": "The base path to the API. Example: '/api'."
},
"schemes": {
"type": "array",
"description": "The transfer protocol of the API.",
"items": {
"type": "string",
"enum": [ "http", "https", "ws", "wss" ]
}
},
"consumes": {
"type": "array",
"description": "A list of MIME types accepted by the API.",
"items": {
"$ref": "#/definitions/mimeType"
}
},
"produces": {
"type": "array",
"description": "A list of MIME types the API can produce.",
"items": {
"$ref": "#/definitions/mimeType"
}
},
"paths": {
"type": "object",
"description": "Relative paths to the individual endpoints. They must be relative to the 'basePath'.",
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
},
"^/.*[^\/]$": {
"$ref": "#/definitions/pathItem"
}
},
"additionalProperties": false
},
"definitions": {
"type": "object",
"description": "One or more JSON objects describing the schemas being consumed and produced by the API.",
"additionalProperties": {
"$ref": "#/definitions/schema"
}
},
"security": {
"$ref": "#/definitions/security"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/tag"
}
}
}
}
9 changes: 9 additions & 0 deletions src/test/scala/ResourcesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ class ResourcesTest extends FlatSpec with ShouldMatchers with TestBase {
report.isSuccess should be (true)
}

it should "validate a spec with reusable parameters" in {
val json = Source.fromFile("fixtures/v2.0/json/resources/reusableParameters.json").mkString
val data = JsonLoader.fromString(json)
val report = jsonSchema.validate(data)
if(report.isSuccess == false)
println(report)
report.isSuccess should be (true)
}

it should "validate the wordnik petstore" in {
val json = Source.fromFile("examples/v2.0/json/petstore.json").mkString
val data = JsonLoader.fromString(json)
Expand Down

0 comments on commit e581516

Please sign in to comment.