fidor_schema 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile +0 -3
  4. data/Rakefile +5 -5
  5. data/fidor_schema.gemspec +10 -2
  6. data/lib/fidor_schema_version.rb +2 -2
  7. data/lib/validator/base.rb +105 -0
  8. data/lib/validator/j_schema.rb +34 -0
  9. data/lib/validator/json-schema.rb +51 -0
  10. data/lib/validator/json_schema.rb +37 -0
  11. data/lib/{validate → validator}/schema.json +0 -0
  12. data/lib/validator.rb +4 -0
  13. data/schema/v1.0/account.json +9 -6
  14. data/schema/v1.0/base_types/base_types.json +1 -0
  15. data/schema/v1.0/batch_direct_debit.json +5 -10
  16. data/schema/v1.0/batch_transfer.json +5 -14
  17. data/schema/v1.0/customer.json +6 -6
  18. data/schema/v1.0/error.json +2 -2
  19. data/schema/v1.0/internal_transfer.json +2 -2
  20. data/schema/v1.0/rate_limit.json +2 -2
  21. data/schema/v1.0/sepa_credit_transfer.json +2 -2
  22. data/schema/v1.0/sepa_direct_debit.json +2 -2
  23. data/schema/v1.0/sepa_mandate.json +2 -2
  24. data/schema/v1.0/transaction.json +10 -18
  25. data/schema/v1.0/transaction_type_details/credit_card_details.json +2 -2
  26. data/schema/v1.0/transaction_type_details/internal_transfer_details.json +2 -2
  27. data/schema/v1.0/transaction_type_details/sepa_credit_transfer_details.json +2 -2
  28. data/schema/v1.0/transaction_type_details/sepa_direct_debit_details.json +2 -2
  29. data/schema/v1.0/user.json +2 -2
  30. data/spec/fidor_schema_spec.rb +1 -2
  31. data/spec/validator/j_schema_spec.rb +22 -0
  32. data/spec/validator/json-schema_spec.rb +22 -0
  33. data/spec/validator/json_schema_spec.rb +13 -0
  34. metadata +58 -7
  35. data/lib/validate/validate.rb +0 -184
  36. data/schema/v1.0/base_types/lists.json +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63ab80e63895828c2013ea4769e2347307c23b7a
4
- data.tar.gz: 0daa2e9e87cba18071f3a9f527d4fbf419430e8a
3
+ metadata.gz: e1217869917c2c480782fe5be4b130eeb390b964
4
+ data.tar.gz: 74cf5f1880959b32af62a69037baa2e4f75801d1
5
5
  SHA512:
6
- metadata.gz: b1d0637a964ab6e1382b85286a61cdd13033e2f53aae3d90ade42fb20872857b8c6321afb3976c49e1e5107d127eef607ed202d500505a52cdebb273049a07e1
7
- data.tar.gz: aae96fdec1918c399573f6ebd04c94a8c518155857bc4a6990a071c0fba56e6150e91cb8270ea2128b6a2a5165c1168648cd34ccddcc030378775900c9015a07
6
+ metadata.gz: 462793875cc0c364bf31614e5064da0ef3ac7f475d96b580ba795196e82a673af19c568c1a827660f22c0567c0fcf989585263643d102f2fbeefbd8ccc45d448
7
+ data.tar.gz: 965d875c3d985d42dd6bcf746bb84aa523c3a44daccbc91b1c65a48d0535e6373a02cf8b9661996476ea64134007f6e7b63552bd3243b0abb4e9932a04b5c206
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  A more detailed view of the changes can be found in the [commit messages](https://github.com/fidor/fidor_schema/commits/)
4
4
 
5
+ ##2015-03
6
+
7
+ * remove name attribute in favour of title
8
+ * remove nested $refs pointing to properties in favour of direct link to the related schema
9
+ * validate the schema files against three different ruby validators
10
+ * add $schema version to each file
11
+
5
12
  ##2015-02
6
13
 
7
14
  * SepaMandates filter by multiple references and ibans
data/Gemfile CHANGED
@@ -1,5 +1,2 @@
1
1
  source 'https://rubygems.org'
2
- gem 'json-schema'
3
- gem 'json_schema'
4
- gem 'jschema'
5
2
  gemspec
data/Rakefile CHANGED
@@ -8,21 +8,21 @@ RSpec::Core::RakeTask.new
8
8
  task :default => :spec
9
9
 
10
10
 
11
- require 'validate/validate'
11
+ require 'validator'
12
12
 
13
13
 
14
14
  task :validate_dash do
15
- Fidor::SchemaValidation.main :dash
15
+ Validator.run :dash
16
16
  end
17
17
 
18
18
  task :validate_underscore do
19
- Fidor::SchemaValidation.main :underscore
19
+ Validator.run :underscore
20
20
  end
21
21
 
22
22
  task :validate_jschema do
23
- Fidor::SchemaValidation.main :jschema
23
+ Validator.run :jschema
24
24
  end
25
25
 
26
26
  task :validate_schema => [:validate_dash, :validate_underscore, :validate_jschema] do
27
-
27
+
28
28
  end
data/fidor_schema.gemspec CHANGED
@@ -21,8 +21,16 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.5'
22
22
  spec.add_development_dependency 'rspec'
23
23
  spec.add_development_dependency 'activesupport'
24
- spec.add_development_dependency 'json_schema_tools', '>=0.3.3'
24
+ spec.add_development_dependency 'json_schema_tools', '>=0.6.1'
25
25
  spec.add_development_dependency 'activemodel' # required by above
26
26
  spec.add_development_dependency 'rake'
27
+ # schema validation gems, for now all of them. must see which one is the most valid ;-)
27
28
 
28
- end
29
+ # most downloads on rubygems, last updated feb 2015
30
+ spec.add_development_dependency 'json-schema'
31
+ # 2nd most downloads on rubygems, last updated March 2015
32
+ spec.add_development_dependency 'json_schema'
33
+ # pretty new , last udpate sep 2014
34
+ spec.add_development_dependency 'jschema'
35
+
36
+ end
@@ -1,5 +1,5 @@
1
1
  module Fidor
2
2
  class Schema
3
- VERSION='0.5.1'
3
+ VERSION='0.6.0'
4
4
  end
5
- end
5
+ end
@@ -0,0 +1,105 @@
1
+ # This functionality is intended to run the schema, through
2
+ # any available Schema Validators for Ruby.
3
+ #
4
+ # They should be valid according to draft-4 ...
5
+ #
6
+ # The schema validators currently being considered are:
7
+ #
8
+ # https://github.com/ruby-json-schema/json-schema
9
+ # https://github.com/brandur/json_schema (note the underscore!)
10
+ # https://github.com/Soylent/jschema
11
+ #
12
+ # These are the three currently available ruby validators that
13
+ # support draft-4. (According to json-schema.org).
14
+ #
15
+ # Each has their quirks, we'll try to:
16
+ # * use each to validate each fidor schema against the json-schema meta-schema
17
+ # * try to load each fidor schema as a schema for validation.
18
+ #
19
+ require 'pathname'
20
+
21
+ module Validator
22
+ class Base
23
+ # @return [Array<String>] file paths
24
+ attr_accessor :files_to_validate
25
+
26
+ # Run the given validator with all schema files
27
+ def self.run(files)
28
+ puts "Running validation with #{name} for #{files.length} schemas"
29
+ v = new(files)
30
+ v.validate_all
31
+ puts v.log_fmt
32
+ v
33
+ end
34
+
35
+ def validate_all
36
+ validate_schemas
37
+ validate_data
38
+ end
39
+
40
+ def validate_schemas
41
+ files_to_validate.each do |file|
42
+ schema = File.read file
43
+ log << "validate schema: #{file}"
44
+ validate schema
45
+ end
46
+ end
47
+
48
+ def validate_data
49
+ files_to_validate.each do |file|
50
+ schema = File.read file
51
+ log << "validate data against: #{file}"
52
+ use_for_validation schema
53
+ end
54
+ end
55
+
56
+
57
+ # Joins the logs before display
58
+ def log_fmt
59
+ res = []
60
+ if errors.length > 0
61
+ res << "#{errors.join("\n\n")}"
62
+ res << "="*50
63
+ res << "#{errors.length} with errors"
64
+ end
65
+ res << "#{success.uniq.length} Schemas passed"
66
+ res.join("\n")
67
+ end
68
+ # @return [Array<String>] error schemas
69
+ def errors
70
+ @errors ||= []
71
+ end
72
+ # @return [Array<String>] test log
73
+ def log
74
+ @log ||= []
75
+ end
76
+ # @return [Array<String>] successfull schema titles
77
+ def success
78
+ @success ||= []
79
+ end
80
+
81
+ end
82
+
83
+ def self.find_all_schema
84
+ # asssume we're running from rake and pwd is project root ...
85
+ this_dir = File.dirname(__FILE__)
86
+ repo_dir = Pathname.new(this_dir+"/../..").cleanpath.to_s
87
+
88
+ Dir.glob("#{repo_dir}/schema/**/*.json")
89
+ end
90
+
91
+
92
+ # @param [Symbol] validator to use
93
+ def self.run(validator)
94
+ case validator
95
+ when :underscore
96
+ Json_Schema.run find_all_schema
97
+ when :dash
98
+ JsonSchema.run find_all_schema
99
+ when :jschema
100
+ JSchema.run find_all_schema
101
+ else
102
+ puts "Unknown validator: #{validator}"
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,34 @@
1
+ require 'jschema'
2
+ module Validator
3
+ class JSchema < Base
4
+
5
+ def initialize(files_to_validate)
6
+ @files_to_validate = files_to_validate
7
+ schema_data = File.read("#{File.dirname(__FILE__)}/schema.json")
8
+ schema_json = JSON.parse(schema_data)
9
+ @meta_schema = ::JSchema.build(schema_json)
10
+ end
11
+
12
+ def validate(schema)
13
+ schema_to_test = JSON.parse(schema)
14
+ result = @meta_schema.validate schema_to_test
15
+ if !result || result.length == 0
16
+ success << schema_to_test['title'] || schema_to_test.keys[0]
17
+ else
18
+ errors << "Schema validation failed: #{schema_to_test['title']}\n#{result.join("\n")}"
19
+ end
20
+ end
21
+
22
+ def use_for_validation(schema)
23
+ schema_to_test = JSON.parse(schema)
24
+ begin
25
+ ::JSchema.build(schema_to_test)
26
+ rescue
27
+ errors << "Data validation failed: #{schema_to_test['title']}\n#{$!}"
28
+ # puts $!.backtrace
29
+ else
30
+ success << schema_to_test['title'] || schema_to_test.keys[0]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,51 @@
1
+ require 'json-schema'
2
+ # https://github.com/ruby-json-schema/json-schema
3
+ module Validator
4
+ class JsonSchema < Base
5
+ def initialize(files_to_validate)
6
+ @files_to_validate = files_to_validate
7
+ @meta_schema_path = "#{File.dirname(__FILE__)}/schema.json"
8
+
9
+ # need to know the base dir of the schema to resolve relative uris.
10
+ # see below.
11
+ @schemadir = File.dirname(@files_to_validate[0])
12
+ end
13
+
14
+ # @param [String] schema to test against the meta schema
15
+ def validate(schema)
16
+ schema_to_test = JSON.parse(schema)
17
+ begin
18
+ result = JSON::Validator.fully_validate(@meta_schema_path, schema_to_test)
19
+ if !result || result.length == 0
20
+ success << schema_to_test['title'] || schema_to_test.keys[0]
21
+ else
22
+ errors << "Schema validation failed: #{schema_to_test['title']}\n#{result.join("\n")}"
23
+ end
24
+ rescue => e
25
+ errors << "Schema validation failed: #{schema_to_test['title']}\n#{e}"
26
+ # puts e.backtrace
27
+ end
28
+ end
29
+
30
+ def use_for_validation(schema)
31
+ schema_to_test = JSON.parse(schema)
32
+
33
+ # json-schema resolves relatives path relative to it's own "."
34
+ # not relative to the file containing the reference ...
35
+ base_dir = Dir.pwd
36
+
37
+ begin
38
+ Dir.chdir @schemadir
39
+ data = {}
40
+ result = JSON::Validator.fully_validate(schema_to_test, data)
41
+ if !result || result.length == 0
42
+ success << schema_to_test['title']
43
+ else
44
+ errors << "Data validation failed: #{schema_to_test['title']}\n#{result.join("\n")}"
45
+ end
46
+ ensure
47
+ Dir.chdir base_dir
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,37 @@
1
+ require 'json_schema'
2
+ module Validator
3
+ class Json_Schema < Base
4
+
5
+ def initialize files_to_validate
6
+ @files_to_validate = files_to_validate
7
+ schema_data = File.read("#{File.dirname(__FILE__)}/schema.json")
8
+ schema_json = JSON.parse(schema_data)
9
+ @schema = ::JsonSchema.parse!(schema_json)
10
+ @errors, @success = [], []
11
+ end
12
+
13
+ # @param [String] schema to test against the meta schema
14
+ def validate(schema)
15
+ schema_to_test = JSON.parse(schema)
16
+ begin
17
+ @schema.validate! schema_to_test
18
+ rescue
19
+ errors << "Schema validation failed: #{schema_to_test['title']}\n#{$!}"
20
+ else
21
+ success << File.basename(schema)
22
+ end
23
+ end
24
+
25
+ def use_for_validation(schema)
26
+ schema_to_test = JSON.parse(schema)
27
+ begin
28
+ ::JsonSchema.parse!(schema_to_test)
29
+ rescue
30
+ errors << "Data validation failed: #{schema_to_test['title']}\n#{$!}"
31
+ else
32
+ success << schema_to_test['title']
33
+ end
34
+ end
35
+
36
+ end
37
+ end
File without changes
data/lib/validator.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'validator/base'
2
+ require 'validator/json-schema'
3
+ require 'validator/json_schema'
4
+ require 'validator/j_schema'
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Account",
4
- "name" : "account",
4
+ "title" : "account",
5
5
  "description" : "A fidor bank account.",
6
6
  "properties" : {
7
7
  "id" : {
@@ -68,9 +68,12 @@
68
68
  "type" : "array",
69
69
  "items" : {
70
70
  "type" : "object",
71
- "properties" : {
72
- "$ref" : "./customer.json#properties"
73
- }
71
+ "$ref" : "./customer.json#"
72
+ // "items" : {
73
+ // "type" : "object",
74
+ // "properties" : {
75
+ // "$ref" : "./customer.json#properties"
76
+ // }
74
77
  },
75
78
  "readOnly" : true
76
79
  },
@@ -107,4 +110,4 @@
107
110
  "href" : "accounts/{id}/sepa_direct_debits"
108
111
  }
109
112
  ]
110
- }
113
+ }
@@ -1,4 +1,5 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "definitions" : {
3
4
  "id" : {
4
5
  "description" : "Unique identifier of the object",
@@ -1,9 +1,8 @@
1
1
  {
2
- "NOTE" : "THIS OBJECT IS NOT SUPPORTED IN THE CURRENT API VERSION",
3
- "note" : "this file is for future reference only!",
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
3
+ "NOTE" : "THIS OBJECT IS NOT SUPPORTED IN THE CURRENT API VERSION, this file is for future reference only!",
4
4
  "type" : "object",
5
- "title" : "Batch Direct Debit",
6
- "name" : "batch_direct_debit",
5
+ "title" : "batch_direct_debit",
7
6
  "description" : "PREVIEW: A direct debit batch contains multiple direct debits which are processed asynchronously.",
8
7
  "required" : ["account_id", "external_uid"],
9
8
  "properties" : {
@@ -24,9 +23,7 @@
24
23
  "type" : "array",
25
24
  "items" : {
26
25
  "type" : "object",
27
- "properties" : {
28
- "$ref" : "./sepa_direct_debit.json#properties"
29
- }
26
+ "$ref" : "./sepa_direct_debit.json#"
30
27
  }
31
28
  },
32
29
  "sepa_direct_debit_ids" : {
@@ -47,9 +44,7 @@
47
44
  },
48
45
  "error" : {
49
46
  "type" : "object",
50
- "properties" : {
51
- "$ref" : "./error.json#properties"
52
- }
47
+ "$ref" : "./error.json#"
53
48
  }
54
49
  }
55
50
  }
@@ -2,8 +2,7 @@
2
2
  "NOTE" : "THIS OBJECT IS NOT SUPPORTED IN THE CURRENT API VERSION",
3
3
  "note" : "this file is for future reference only!",
4
4
  "type" : "object",
5
- "title" : "Batch Transfer",
6
- "name" : "batch_transfer",
5
+ "title" : "batch_transfer",
7
6
  "description" : "PREVIEW: A transfer batch contains multiple transfers which are processed asynchronously.",
8
7
  "required" : ["account_id", "external_uid"],
9
8
  "properties" : {
@@ -24,9 +23,7 @@
24
23
  "type" : "array",
25
24
  "items" : {
26
25
  "type" : "object",
27
- "properties" : {
28
- "$ref" : "./sepa_credit_transfer.json#properties"
29
- }
26
+ "$ref" : "./sepa_credit_transfer.json#"
30
27
  }
31
28
  },
32
29
  "internal_transfers" : {
@@ -34,9 +31,7 @@
34
31
  "type" : "array",
35
32
  "items" : {
36
33
  "type" : "object",
37
- "properties" : {
38
- "$ref" : "./internal_transfer.json#properties"
39
- }
34
+ "$ref" : "./internal_transfer.json#"
40
35
  }
41
36
  },
42
37
  "sepa_credit_transfer_ids" : {
@@ -64,9 +59,7 @@
64
59
  },
65
60
  "error" : {
66
61
  "type" : "object",
67
- "properties" : {
68
- "$ref" : "./error.json#properties"
69
- }
62
+ "$ref" : "./error.json#"
70
63
  }
71
64
  }
72
65
  }
@@ -82,9 +75,7 @@
82
75
  },
83
76
  "error" : {
84
77
  "type" : "object",
85
- "properties" : {
86
- "$ref" : "./error.json#properties"
87
- }
78
+ "$ref" : "./error.json#"
88
79
  }
89
80
  }
90
81
  }
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Customer",
4
- "name" : "customer",
4
+ "title" : "customer",
5
5
  "description" : "",
6
6
  "required" : ["email", "first_name", "last_name", "gender", "title", "nick"],
7
7
  "properties" : {
@@ -193,12 +193,12 @@
193
193
  "href" : "customers/{id}"
194
194
  },
195
195
  {
196
- "rel" : "instances",
197
- "href" : "customers"
196
+ "rel" : "instances",
197
+ "href" : "customers"
198
198
  },
199
199
  {
200
- "rel" : "accounts",
201
- "href" : "customers/{id}/accounts"
200
+ "rel" : "accounts",
201
+ "href" : "customers/{id}/accounts"
202
202
  }
203
203
  ]
204
204
  }
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Error",
4
- "name" : "error",
4
+ "title" : "error",
5
5
  "description" : "A standard error object",
6
6
  "required" : ["message", "code", "errors"],
7
7
  "properties" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Internal Transfer",
4
- "name" : "internal_transfer",
4
+ "title" : "internal_transfer",
5
5
  "description" : "A transfer initiates a transaction e.g get / send money. If the transfer fails no transaction is created!",
6
6
  "required" : ["account_id", "receiver", "amount", "external_uid"],
7
7
  "properties" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Rate limit",
4
- "name" : "rate_limit",
4
+ "title" : "rate_limit",
5
5
  "description" : "Overall, remaining rate limits and the time frame until the reset.",
6
6
  "properties" : {
7
7
  "limit" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Sepa Credit Transfer",
4
- "name" : "sepa_credit_transfer",
4
+ "title" : "sepa_credit_transfer",
5
5
  "description" : "A transfer initiates a transaction e.g get / send money. If the transfer fails no transaction is created!",
6
6
  "required" : ["account_id", "amount", "external_uid"],
7
7
  "properties" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Sepa Direct Debit",
4
- "name" : "sepa_direct_debit",
4
+ "title" : "sepa_direct_debit",
5
5
  "description" : "A direct debit can only be performed with a valid sepa mandate, authorizing access to the debtor's account.",
6
6
  "required" : ["account_id", "mandate_id", "amount", "collection_date", "external_uid"],
7
7
  "properties" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Sepa Mandate",
4
- "name" : "sepa_mandate",
4
+ "title" : "sepa_mandate",
5
5
  "description" : "A mandate object authorizing debits from an account.",
6
6
  "required" : ["external_uid", "customer_id", "mandate_reference", "remote_title", "remote_name", "remote_email",
7
7
  "remote_address_line1", "remote_address_line2", "remote_country", "remote_iban", "remote_bic",
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Transaction",
4
- "name" : "transaction",
4
+ "title" : "transaction",
5
5
  "description" : "A transaction is the result of a successful transfer or debit.",
6
6
  "properties" : {
7
7
  "id" : {
@@ -21,28 +21,20 @@
21
21
  "type" : "object",
22
22
  "oneOf" : [
23
23
  {
24
- "name" : "credit_card_details",
25
- "properties" : {
26
- "$ref" : "./transaction_type_details/credit_card_details.json#properties"
27
- }
24
+ "title" : "credit_card_details",
25
+ "$ref" : "./transaction_type_details/credit_card_details.json#"
28
26
  },
29
27
  {
30
- "name" : "internal_transfer_details",
31
- "properties" : {
32
- "$ref" : "./transaction_type_details/internal_transfer_details.json#properties"
33
- }
28
+ "title" : "internal_transfer_details",
29
+ "$ref" : "./transaction_type_details/internal_transfer_details.json#"
34
30
  },
35
31
  {
36
- "name" : "sepa_credit_transfer_details",
37
- "properties" : {
38
- "$ref" : "./transaction_type_details/sepa_credit_transfer_details.json#properties"
39
- }
32
+ "title" : "sepa_credit_transfer_details",
33
+ "$ref" : "./transaction_type_details/sepa_credit_transfer_details.json#"
40
34
  },
41
35
  {
42
- "name" : "sepa_direct_debit_details",
43
- "properties" : {
44
- "$ref" : "./transaction_type_details/sepa_direct_debit_details.json#properties"
45
- }
36
+ "title" : "sepa_direct_debit_details",
37
+ "$ref" : "./transaction_type_details/sepa_direct_debit_details.json#"
46
38
  }
47
39
  ]
48
40
  },
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Credit Card Details",
4
- "name" : "credit_card_details",
4
+ "title" : "credit_card_details",
5
5
  "description" : "Credit card information available in a CreditCard transaction",
6
6
  "properties" : {
7
7
  "cc_merchant_name" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Internal Transfer Details",
4
- "name" : "internal_transfer_details",
4
+ "title" : "internal_transfer_details",
5
5
  "description" : "Remote account for a Fidor internal transfer",
6
6
  "properties" : {
7
7
  "remote_account_id" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Sepa Credit Transfer Details",
4
- "name" : "sepa_credit_transfer_details",
4
+ "title" : "sepa_credit_transfer_details",
5
5
  "description" : "Remote account information available in a SEPA credit transfer",
6
6
  "properties" : {
7
7
  "sepa_credit_transfer_id" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "Sepa Direct Debit Details",
4
- "name" : "sepa_direct_debit_details",
4
+ "title" : "sepa_direct_debit_details",
5
5
  "description" : "Remote account information for a SEPA direct debit",
6
6
  "properties" : {
7
7
  "remote_iban" : {
@@ -1,7 +1,7 @@
1
1
  {
2
+ "$schema" : "http://json-schema.org/draft-04/schema#",
2
3
  "type" : "object",
3
- "title" : "User",
4
- "name" : "user",
4
+ "title" : "user",
5
5
  "description" : "",
6
6
  "required" : ["email"],
7
7
  "properties" : {
@@ -24,7 +24,6 @@ describe Fidor::Schema do
24
24
  SchemaTools.schema_path = Fidor::Schema.path
25
25
  schema = SchemaTools::Reader.read('account').to_h
26
26
  expect(schema['properties']['customers']['items']['properties']['id']['type']).to eq 'string'
27
-
28
27
  end
29
28
 
30
29
  it 'should resolve all' do
@@ -38,4 +37,4 @@ describe Fidor::Schema do
38
37
  end
39
38
 
40
39
  end
41
- end
40
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'validator'
3
+
4
+ describe Validator::JSchema do
5
+ it 'validates schemas against the meta schema' do
6
+ path = Fidor::Schema.path
7
+ files = Dir.glob("#{path}/**/*.json")
8
+ v = Validator::JSchema.new files
9
+ v.validate_schemas
10
+ expect(v.log[0]).to include('validate schema')
11
+ expect(v.errors).to be_empty
12
+ end
13
+
14
+ it 'validates schemas against blank data' do
15
+ path = Fidor::Schema.path
16
+ files = Dir.glob("#{path}/**/*.json")
17
+ v = Validator::JSchema.new files
18
+ v.validate_data
19
+ expect(v.log[0]).to include('validate data')
20
+ # expect(v.errors).to be_empty
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'validator'
3
+
4
+ describe Validator::JsonSchema do
5
+ it 'validates schemas against the meta schema' do
6
+ path = Fidor::Schema.path
7
+ files = Dir.glob("#{path}/**/*.json")
8
+ v = Validator::JsonSchema.new files
9
+ v.validate_schemas
10
+ expect(v.log[0]).to include('validate schema')
11
+ expect(v.errors).to be_empty
12
+ end
13
+
14
+ it 'validates schemas against blank data' do
15
+ path = Fidor::Schema.path
16
+ files = Dir.glob("#{path}/**/*.json")
17
+ v = Validator::JsonSchema.new files
18
+ v.validate_data
19
+ expect(v.log[0]).to include('validate data')
20
+ # expect(v.errors).to be_empty
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'validator'
3
+
4
+ describe Validator::Json_Schema do
5
+ it 'validates schemas against the meta schema' do
6
+ path = Fidor::Schema.path
7
+ files = Dir.glob("#{path}/**/*.json")
8
+ v = Validator::Json_Schema.new files
9
+ v.validate_schemas
10
+ expect(v.log[0]).to include('validate schema')
11
+ expect(v.errors).to be_empty
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fidor_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.3
61
+ version: 0.6.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.3.3
68
+ version: 0.6.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activemodel
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json-schema
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json_schema
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: jschema
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description: Fidor API description. Using JSON Schema to describe the available objects,
98
140
  their fields and resource links. Beware of the BETA status, as things can change
99
141
  slightly
@@ -111,11 +153,14 @@ files:
111
153
  - lib/fidor/schema.rb
112
154
  - lib/fidor_schema.rb
113
155
  - lib/fidor_schema_version.rb
114
- - lib/validate/schema.json
115
- - lib/validate/validate.rb
156
+ - lib/validator.rb
157
+ - lib/validator/base.rb
158
+ - lib/validator/j_schema.rb
159
+ - lib/validator/json-schema.rb
160
+ - lib/validator/json_schema.rb
161
+ - lib/validator/schema.json
116
162
  - schema/v1.0/account.json
117
163
  - schema/v1.0/base_types/base_types.json
118
- - schema/v1.0/base_types/lists.json
119
164
  - schema/v1.0/batch_direct_debit.json
120
165
  - schema/v1.0/batch_transfer.json
121
166
  - schema/v1.0/customer.json
@@ -133,6 +178,9 @@ files:
133
178
  - schema/v1.0/user.json
134
179
  - spec/fidor_schema_spec.rb
135
180
  - spec/spec_helper.rb
181
+ - spec/validator/j_schema_spec.rb
182
+ - spec/validator/json-schema_spec.rb
183
+ - spec/validator/json_schema_spec.rb
136
184
  homepage: https://www.fidor.de
137
185
  licenses:
138
186
  - MIT
@@ -160,3 +208,6 @@ summary: BETA Fidor API - JSON Schema
160
208
  test_files:
161
209
  - spec/fidor_schema_spec.rb
162
210
  - spec/spec_helper.rb
211
+ - spec/validator/j_schema_spec.rb
212
+ - spec/validator/json-schema_spec.rb
213
+ - spec/validator/json_schema_spec.rb
@@ -1,184 +0,0 @@
1
- # This functionality is intended to run the schema, through
2
- # any available Schema Validators for Ruby.
3
- #
4
- # They should be valid according to draft-4 ...
5
- #
6
- # The schema validators currently being considered are:
7
- #
8
- # https://github.com/ruby-json-schema/json-schema
9
- # https://github.com/brandur/json_schema (note the underscore!)
10
- # https://github.com/Soylent/jschema
11
- #
12
- # These are the three currently available ruby validators that
13
- # support draft-4. (According to json-schema.org).
14
- #
15
- # Each has their quirks, we'll try to:
16
- # * use each to validate each fidor schema against the json-schema meta-schema
17
- # * try to load each fidor schema as a schema for validation.
18
- #
19
- require 'pathname'
20
- require 'json-schema'
21
- require 'json_schema'
22
- require 'jschema'
23
-
24
- module Fidor
25
- module SchemaValidation
26
-
27
- class Validator # Base
28
- def validate_all
29
- @files_to_validate.each do |file|
30
- schema = File.read file
31
- puts "\nvalidating: #{file}"
32
- validate schema
33
- puts "\nusing #{file} for validation."
34
- use_for_validation schema
35
- end
36
- end
37
- end
38
-
39
- # https://github.com/ruby-json-schema/json-schema
40
- class JsonDashSchemaValidator < Validator
41
- def initialize files_to_validate
42
- @files_to_validate = files_to_validate
43
- @meta_schema_fn = "#{File.dirname(__FILE__)}/schema.json"
44
-
45
- # need to know the base dir of the schema to resolve relative uris.
46
- # see below.
47
- @schemadir = File.dirname(@files_to_validate[0])
48
-
49
- validate_all
50
- end # init
51
-
52
- def validate schema
53
- begin
54
- results = JSON::Validator.fully_validate(@meta_schema_fn, schema)
55
- if !results || results.length == 0
56
- puts "Passed!"
57
- else
58
- puts "Failed!"
59
- puts results
60
- end
61
- rescue
62
- puts "Failed! Error..."
63
- puts $!
64
- puts $!.backtrace
65
- end
66
- end
67
-
68
- def use_for_validation schema
69
- # json-schema resolves relatives path relative to it's own "."
70
- # not relative to the file containing the reference ...
71
- baseDirectory = Dir.pwd
72
-
73
- begin
74
- Dir.chdir @schemadir
75
- data = {}
76
- results = JSON::Validator.fully_validate(schema, data)
77
- if !results || results.length == 0
78
- puts "Passed!"
79
- else
80
- puts "Failed!"
81
- puts results
82
- end
83
- ensure
84
- Dir.chdir baseDirectory
85
- end
86
- end
87
- end
88
-
89
- class JsonUnderscoreSchemaValidator < Validator
90
- def initialize files_to_validate
91
- @files_to_validate = files_to_validate
92
- schema_data = File.read("#{File.dirname(__FILE__)}/schema.json")
93
- schema_json = JSON.parse(schema_data)
94
- @schema = JsonSchema.parse!(schema_json)
95
- validate_all
96
- end
97
-
98
- def validate schema
99
- begin
100
- schema_to_test = JSON.parse(schema)
101
- @schema.validate! schema_to_test
102
- puts "Passed validation against meta-schema!"
103
- JsonSchema.parse!(schema_to_test)
104
- rescue
105
- puts $!
106
- puts "Failed!"
107
- else
108
- puts "Passed!"
109
- end
110
- end
111
- def use_for_validation schema
112
- begin
113
- schema_to_test = JSON.parse(schema)
114
- JsonSchema.parse!(schema_to_test)
115
- rescue
116
- puts $!
117
- puts "Failed"
118
- else
119
- puts "Passed!"
120
- end
121
- end
122
- end
123
-
124
- class JSchemaValidator < Validator
125
- def initialize files_to_validate
126
- @files_to_validate = files_to_validate
127
- schema_data = File.read("#{File.dirname(__FILE__)}/schema.json")
128
- schema_json = JSON.parse(schema_data)
129
- @schema = JSchema.build(schema_json)
130
- validate_all
131
- end
132
- def validate schema
133
- schema_to_test = JSON.parse(schema)
134
- results = @schema.validate schema_to_test
135
- if !results || results.length == 0
136
- puts "Passed!"
137
- else
138
- puts "Failed!"
139
- puts results
140
- end
141
- end
142
- def use_for_validation schema
143
- schema_to_test = JSON.parse(schema)
144
- begin
145
- JSchema.build(schema_to_test)
146
- rescue
147
- puts "Failed!"
148
- puts $!
149
- # puts $!.backtrace
150
- else
151
- puts "Passed!"
152
- end
153
- end
154
- end
155
-
156
- def self.find_all_schema
157
- # asssume we're running from rake and
158
- # pwd is project root ...
159
- this_dir = File.dirname(__FILE__)
160
- repo_dir = Pathname.new(this_dir+"/../..").cleanpath.to_s
161
-
162
- Dir.glob("#{repo_dir}/schema/*/*.json")
163
- end
164
-
165
-
166
- def self.main validator
167
- case validator
168
- when :underscore
169
- puts "Running validation with JSON_Schema"
170
- JsonUnderscoreSchemaValidator.new find_all_schema
171
- when :dash
172
- puts "Running validation with JSON-Schema"
173
- JsonDashSchemaValidator.new find_all_schema
174
- when :jschema
175
- puts "Running validation with JSchema"
176
- JSchemaValidator.new find_all_schema
177
- else
178
- puts "Unknown validator: #{validator}"
179
- end
180
-
181
- end
182
- end
183
- end
184
-
@@ -1,32 +0,0 @@
1
- {
2
- "type" : "object",
3
- "title" : "List",
4
- "name" : "list",
5
- "description" : "A paginated list of objects",
6
- "properties" : {
7
- "data" : {
8
- "description" : "The requested objects",
9
- "type" : "array"
10
- },
11
- "collection" : {
12
- "type" : "object",
13
- "name" : "collection",
14
- "description" : "Pagination information for a list of returned object (not standalone)",
15
- "properties" : {
16
- "current_page" : {
17
- "type" : "integer"
18
- },
19
- "per_page" : {
20
- "type" : "integer"
21
- },
22
- "total_entries" : {
23
- "type" : "integer"
24
- },
25
- "total_pages" : {
26
- "type" : "integer"
27
- }
28
- }
29
- }
30
- }
31
- }
32
-