-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from hornc/custom_schemata
[CNTR-746] Allow swagger validation against custom schemata
- Loading branch information
Showing
9 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,15 @@ $:.push File.expand_path("../lib", __FILE__) | |
|
||
Gem::Specification.new do |s| | ||
s.name = 'apivore' | ||
s.version = '1.2.0' | ||
s.date = '2015-05-20' | ||
s.version = '1.3.0' | ||
s.date = '2015-06-11' | ||
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"] | ||
s.email = '[email protected]' | ||
s.files = ['lib/apivore.rb', 'data/swagger_2.0_schema.json', 'data/draft04_schema.json'] | ||
s.files += Dir['lib/apivore/*.rb'] | ||
s.files += Dir['data/custom_schemata/*.json'] | ||
s.homepage = 'http://github.com/westfieldlabs/apivore' | ||
s.licenses = ['Apache 2.0', 'MIT'] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"title": "Westfield API Standards", | ||
|
||
"type": "object", | ||
"properties": { | ||
"definitions": { | ||
"description": "All entities defined in the 'definitions' section must include an explicit 'type: object' attribute. This forces the entity to be validated.", | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/definitions/schemaObject" | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"schemaObject": { | ||
"type": "object", | ||
"required": [ "type" ], | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": [ "object" ] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Apivore | ||
class CustomSchemaValidator | ||
def initialize(custom_schema) | ||
@schema = File.expand_path("../../data/custom_schemata/#{custom_schema}", File.dirname(__FILE__)) | ||
end | ||
|
||
def matches?(swagger_checker) | ||
@results = JSON::Validator.fully_validate(@schema, swagger_checker.swagger) | ||
@results.empty? | ||
end | ||
|
||
def description | ||
"additionally conforms to #{@schema}" | ||
end | ||
|
||
def failure_message | ||
@results.join("\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"version": "testing", | ||
"title": "Example Centre Directory Service" | ||
}, | ||
"host": "api.test.example.com", | ||
"basePath": "/api", | ||
"schemes": [ | ||
"https" | ||
], | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/services.json": { | ||
"get": { | ||
"description": "Services available to shoppers.", | ||
"operationId": "Services#index", | ||
"responses": { | ||
"200": { | ||
"description": "service index response", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/service" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"post": { | ||
"description": "Creates a service.", | ||
"operationId": "Services#post", | ||
"responses": { | ||
"204": { | ||
"description": "Service created" | ||
} | ||
} | ||
} | ||
}, | ||
"/services/{id}.json": { | ||
"get": { | ||
"description": "Returns a service.", | ||
"operationId": "Services#show", | ||
"responses": { | ||
"200": { | ||
"description": "show service response", | ||
"schema": { | ||
"$ref": "#/definitions/service" | ||
} | ||
} | ||
} | ||
}, | ||
"put": { | ||
"description": "Update a service.", | ||
"operationId": "Services#put", | ||
"responses": { | ||
"204": { | ||
"description": "Service updated" | ||
} | ||
} | ||
}, | ||
"delete": { | ||
"description": "Deletes a service.", | ||
"operationId": "Services#delete", | ||
"responses": { | ||
"204": { | ||
"description": "Service deleted" | ||
} | ||
} | ||
}, | ||
"patch": { | ||
"description": "Patches a service.", | ||
"operationId": "Services#patch", | ||
"responses": { | ||
"204": { | ||
"description": "Service patched" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"service": { | ||
|
||
"required": [ "id" ], | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"description": "Service id" | ||
}, | ||
"name": { | ||
"type": ["string", "null"], | ||
"description": "Service name" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters