Skip to content

Commit

Permalink
Merge pull request #55 from hornc/master
Browse files Browse the repository at this point in the history
Tidy Custom Schema validation usage, and use latest swagger 2.0 spec
  • Loading branch information
hornc committed Aug 2, 2015
2 parents 0ba4ded + ecb4992 commit 7b40ca1
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apivore.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = 'apivore'
s.version = '1.3.0'
s.date = '2015-06-11'
s.date = '2015-07-31'
s.summary = "Tests your API against its Swagger 2.0 spec"
s.description = "Tests your rails API using its Swagger description of end-points, models, and query parameters."
s.authors = ["Charles Horn"]
Expand Down
127 changes: 110 additions & 17 deletions data/swagger_2.0_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
},
"host": {
"type": "string",
"format": "uri",
"pattern": "^[^{}/ :\\\\]+(?::\\d+)?$",
"description": "The fully qualified URI to the host of the API."
"description": "The host (name or ip) of the API. Example: 'swagger.io'"
},
"basePath": {
"type": "string",
Expand Down Expand Up @@ -101,7 +100,7 @@
},
"description": {
"type": "string",
"description": "A longer description of the API. Should be different from the title. Github-flavored markdown is allowed."
"description": "A longer description of the API. Should be different from the title. GitHub Flavored Markdown is allowed."
},
"termsOfService": {
"type": "string",
Expand Down Expand Up @@ -134,6 +133,11 @@
"description": "The email address of the contact person/organization.",
"format": "email"
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"license": {
Expand All @@ -152,6 +156,11 @@
"description": "The URL pointing to the license.",
"format": "uri"
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"paths": {
Expand Down Expand Up @@ -203,14 +212,16 @@
"type": "string",
"format": "uri"
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"examples": {
"type": "object",
"patternProperties": {
"^[a-z0-9-]+/[a-z0-9\\-+]+$": {}
},
"additionalProperties": false
"additionalProperties": true
},
"mimeType": {
"type": "string",
Expand Down Expand Up @@ -241,14 +252,14 @@
},
"description": {
"type": "string",
"description": "A longer description of the operation, github-flavored markdown is allowed."
"description": "A longer description of the operation, GitHub Flavored Markdown is allowed."
},
"externalDocs": {
"$ref": "#/definitions/externalDocs"
},
"operationId": {
"type": "string",
"description": "A friendly name of the operation"
"description": "A unique identifier of the operation."
},
"produces": {
"description": "A list of MIME types the API can produce.",
Expand Down Expand Up @@ -357,7 +368,14 @@
"type": "string"
},
"schema": {
"$ref": "#/definitions/schema"
"oneOf": [
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/fileSchema"
}
]
},
"headers": {
"$ref": "#/definitions/headers"
Expand All @@ -366,7 +384,12 @@
"$ref": "#/definitions/examples"
}
},
"additionalProperties": false
"additionalProperties": false,
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"headers": {
"type": "object",
Expand Down Expand Up @@ -442,6 +465,11 @@
"description": {
"type": "string"
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"vendorExtension": {
Expand All @@ -464,7 +492,7 @@
"properties": {
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. Github-flavored markdown is allowed."
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -510,7 +538,7 @@
},
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. Github-flavored markdown is allowed."
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -598,7 +626,7 @@
},
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. Github-flavored markdown is allowed."
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -691,7 +719,7 @@
},
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. Github-flavored markdown is allowed."
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -770,6 +798,9 @@
"$ref": "#/definitions/vendorExtension"
}
},
"required": [
"required"
],
"properties": {
"required": {
"type": "boolean",
Expand All @@ -787,7 +818,7 @@
},
"description": {
"type": "string",
"description": "A brief description of the parameter. This could contain examples of use. Github-flavored markdown is allowed."
"description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed."
},
"name": {
"type": "string",
Expand Down Expand Up @@ -955,7 +986,15 @@
"$ref": "http://json-schema.org/draft-04/schema#/properties/enum"
},
"additionalProperties": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/additionalProperties"
"anyOf": [
{
"$ref": "#/definitions/schema"
},
{
"type": "boolean"
}
],
"default": {}
},
"type": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/type"
Expand Down Expand Up @@ -1006,6 +1045,47 @@
},
"additionalProperties": false
},
"fileSchema": {
"type": "object",
"description": "A deterministic version of a JSON Schema object.",
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
},
"properties": {
"format": {
"type": "string"
},
"title": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/title"
},
"description": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/description"
},
"default": {
"$ref": "http://json-schema.org/draft-04/schema#/properties/default"
},
"required": {
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
},
"type": {
"type": "string",
"enum": [
"file"
]
},
"readOnly": {
"type": "boolean",
"default": false
},
"externalDocs": {
"$ref": "#/definitions/externalDocs"
},
"example": {}
},
"additionalProperties": false
},
"primitivesItems": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -1068,6 +1148,11 @@
"multipleOf": {
"$ref": "#/definitions/multipleOf"
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"security": {
Expand Down Expand Up @@ -1108,6 +1193,11 @@
"type": "boolean",
"default": false
}
},
"patternProperties": {
"^x-": {
"$ref": "#/definitions/vendorExtension"
}
}
},
"tag": {
Expand Down Expand Up @@ -1484,6 +1574,9 @@
},
"jsonReference": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
Expand Down
5 changes: 4 additions & 1 deletion lib/apivore/custom_schema_validator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Apivore
class CustomSchemaValidator
# This constant is an example custom schema included with the gem
WF_SCHEMA = File.expand_path("../../data/custom_schemata/westfield_api_standards.json", File.dirname(__FILE__))

def initialize(custom_schema)
@schema = File.expand_path("../../data/custom_schemata/#{custom_schema}", File.dirname(__FILE__))
@schema = custom_schema
end

def matches?(swagger_checker)
Expand Down
2 changes: 1 addition & 1 deletion spec/data/example_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
end

it "fails" do
expect(subject).to conform_to("westfield_api_standards.json")
expect(subject).to conform_to(Apivore::CustomSchemaValidator::WF_SCHEMA)
end
end
end
2 changes: 1 addition & 1 deletion spec/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end

it 'additionally conforms to a custom schema' do
expect(subject).to conform_to("westfield_api_standards.json")
expect(subject).to conform_to(Apivore::CustomSchemaValidator::WF_SCHEMA)
end
# it 'has definitions consistent with the master docs' do
# expect(subject).to be_consistent_with_swagger_definitions(
Expand Down

0 comments on commit 7b40ca1

Please sign in to comment.