dato_json_schema 0.20.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,168 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/hyper-schema#",
3
+ "id": "http://json-schema.org/draft-04/hyper-schema#",
4
+ "title": "JSON Hyper-Schema",
5
+ "allOf": [
6
+ {
7
+ "$ref": "http://json-schema.org/draft-04/schema#"
8
+ }
9
+ ],
10
+ "properties": {
11
+ "additionalItems": {
12
+ "anyOf": [
13
+ {
14
+ "type": "boolean"
15
+ },
16
+ {
17
+ "$ref": "#"
18
+ }
19
+ ]
20
+ },
21
+ "additionalProperties": {
22
+ "anyOf": [
23
+ {
24
+ "type": "boolean"
25
+ },
26
+ {
27
+ "$ref": "#"
28
+ }
29
+ ]
30
+ },
31
+ "dependencies": {
32
+ "additionalProperties": {
33
+ "anyOf": [
34
+ {
35
+ "$ref": "#"
36
+ },
37
+ {
38
+ "type": "array"
39
+ }
40
+ ]
41
+ }
42
+ },
43
+ "items": {
44
+ "anyOf": [
45
+ {
46
+ "$ref": "#"
47
+ },
48
+ {
49
+ "$ref": "#/definitions/schemaArray"
50
+ }
51
+ ]
52
+ },
53
+ "definitions": {
54
+ "additionalProperties": {
55
+ "$ref": "#"
56
+ }
57
+ },
58
+ "patternProperties": {
59
+ "additionalProperties": {
60
+ "$ref": "#"
61
+ }
62
+ },
63
+ "properties": {
64
+ "additionalProperties": {
65
+ "$ref": "#"
66
+ }
67
+ },
68
+ "allOf": {
69
+ "$ref": "#/definitions/schemaArray"
70
+ },
71
+ "anyOf": {
72
+ "$ref": "#/definitions/schemaArray"
73
+ },
74
+ "oneOf": {
75
+ "$ref": "#/definitions/schemaArray"
76
+ },
77
+ "not": {
78
+ "$ref": "#"
79
+ },
80
+
81
+ "links": {
82
+ "type": "array",
83
+ "items": {
84
+ "$ref": "#/definitions/linkDescription"
85
+ }
86
+ },
87
+ "fragmentResolution": {
88
+ "type": "string"
89
+ },
90
+ "media": {
91
+ "type": "object",
92
+ "properties": {
93
+ "type": {
94
+ "description": "A media type, as described in RFC 2046",
95
+ "type": "string"
96
+ },
97
+ "binaryEncoding": {
98
+ "description": "A content encoding scheme, as described in RFC 2045",
99
+ "type": "string"
100
+ }
101
+ }
102
+ },
103
+ "pathStart": {
104
+ "description": "Instances' URIs must start with this value for this schema to apply to them",
105
+ "type": "string",
106
+ "format": "uri"
107
+ }
108
+ },
109
+ "definitions": {
110
+ "schemaArray": {
111
+ "type": "array",
112
+ "items": {
113
+ "$ref": "#"
114
+ }
115
+ },
116
+ "linkDescription": {
117
+ "title": "Link Description Object",
118
+ "type": "object",
119
+ "required": [ "href", "rel" ],
120
+ "properties": {
121
+ "href": {
122
+ "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing",
123
+ "type": "string"
124
+ },
125
+ "rel": {
126
+ "description": "relation to the target resource of the link",
127
+ "type": "string"
128
+ },
129
+ "title": {
130
+ "description": "a title for the link",
131
+ "type": "string"
132
+ },
133
+ "targetSchema": {
134
+ "description": "JSON Schema describing the link target",
135
+ "$ref": "#"
136
+ },
137
+ "mediaType": {
138
+ "description": "media type (as defined by RFC 2046) describing the link target",
139
+ "type": "string"
140
+ },
141
+ "method": {
142
+ "description": "method for requesting the target of the link (e.g. for HTTP this might be \"GET\" or \"DELETE\")",
143
+ "type": "string"
144
+ },
145
+ "encType": {
146
+ "description": "The media type in which to submit data along with the request",
147
+ "type": "string",
148
+ "default": "application/json"
149
+ },
150
+ "schema": {
151
+ "description": "Schema describing the data to submit along with the request",
152
+ "$ref": "#"
153
+ }
154
+ }
155
+ }
156
+ },
157
+ "links": [
158
+ {
159
+ "rel": "self",
160
+ "href": "{+id}"
161
+ },
162
+ {
163
+ "rel": "full",
164
+ "href": "{+($ref)}"
165
+ }
166
+ ]
167
+ }
168
+
@@ -0,0 +1,150 @@
1
+ {
2
+ "id": "http://json-schema.org/draft-04/schema#",
3
+ "$schema": "http://json-schema.org/draft-04/schema#",
4
+ "description": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": { "$ref": "#" }
10
+ },
11
+ "positiveInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "positiveIntegerDefault0": {
16
+ "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": { "type": "string" },
24
+ "minItems": 1,
25
+ "uniqueItems": true
26
+ }
27
+ },
28
+ "type": "object",
29
+ "properties": {
30
+ "id": {
31
+ "type": "string",
32
+ "format": "uri"
33
+ },
34
+ "$schema": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "title": {
39
+ "type": "string"
40
+ },
41
+ "description": {
42
+ "type": "string"
43
+ },
44
+ "default": {},
45
+ "multipleOf": {
46
+ "type": "number",
47
+ "minimum": 0,
48
+ "exclusiveMinimum": true
49
+ },
50
+ "maximum": {
51
+ "type": "number"
52
+ },
53
+ "exclusiveMaximum": {
54
+ "type": "boolean",
55
+ "default": false
56
+ },
57
+ "minimum": {
58
+ "type": "number"
59
+ },
60
+ "exclusiveMinimum": {
61
+ "type": "boolean",
62
+ "default": false
63
+ },
64
+ "maxLength": { "$ref": "#/definitions/positiveInteger" },
65
+ "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
66
+ "pattern": {
67
+ "type": "string",
68
+ "format": "regex"
69
+ },
70
+ "additionalItems": {
71
+ "anyOf": [
72
+ { "type": "boolean" },
73
+ { "$ref": "#" }
74
+ ],
75
+ "default": {}
76
+ },
77
+ "items": {
78
+ "anyOf": [
79
+ { "$ref": "#" },
80
+ { "$ref": "#/definitions/schemaArray" }
81
+ ],
82
+ "default": {}
83
+ },
84
+ "maxItems": { "$ref": "#/definitions/positiveInteger" },
85
+ "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
86
+ "uniqueItems": {
87
+ "type": "boolean",
88
+ "default": false
89
+ },
90
+ "maxProperties": { "$ref": "#/definitions/positiveInteger" },
91
+ "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
92
+ "required": { "$ref": "#/definitions/stringArray" },
93
+ "additionalProperties": {
94
+ "anyOf": [
95
+ { "type": "boolean" },
96
+ { "$ref": "#" }
97
+ ],
98
+ "default": {}
99
+ },
100
+ "definitions": {
101
+ "type": "object",
102
+ "additionalProperties": { "$ref": "#" },
103
+ "default": {}
104
+ },
105
+ "properties": {
106
+ "type": "object",
107
+ "additionalProperties": { "$ref": "#" },
108
+ "default": {}
109
+ },
110
+ "patternProperties": {
111
+ "type": "object",
112
+ "additionalProperties": { "$ref": "#" },
113
+ "default": {}
114
+ },
115
+ "dependencies": {
116
+ "type": "object",
117
+ "additionalProperties": {
118
+ "anyOf": [
119
+ { "$ref": "#" },
120
+ { "$ref": "#/definitions/stringArray" }
121
+ ]
122
+ }
123
+ },
124
+ "enum": {
125
+ "type": "array",
126
+ "minItems": 1,
127
+ "uniqueItems": true
128
+ },
129
+ "type": {
130
+ "anyOf": [
131
+ { "$ref": "#/definitions/simpleTypes" },
132
+ {
133
+ "type": "array",
134
+ "items": { "$ref": "#/definitions/simpleTypes" },
135
+ "minItems": 1,
136
+ "uniqueItems": true
137
+ }
138
+ ]
139
+ },
140
+ "allOf": { "$ref": "#/definitions/schemaArray" },
141
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
142
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
143
+ "not": { "$ref": "#" }
144
+ },
145
+ "dependencies": {
146
+ "exclusiveMaximum": [ "maximum" ],
147
+ "exclusiveMinimum": [ "minimum" ]
148
+ },
149
+ "default": {}
150
+ }
data/test/bin_test.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ #
4
+ # The purpose of this sets of tests is just to test our Ruby executables
5
+ # where possible so that we can get very basic sanity checks on their syntax.
6
+ #
7
+ # We can do this without actually executing them with a "ruby -c" call.
8
+ #
9
+
10
+ describe "executables in bin/" do
11
+ before do
12
+ @bin_dir = File.expand_path("../../bin", __FILE__)
13
+ end
14
+
15
+ it "has roughly valid Ruby structure for validate-schema" do
16
+ IO.popen(["ruby", "-c", File.join(@bin_dir, "validate-schema")]) { |io| io.read }
17
+ assert_equal $?.exitstatus, 0, "Ruby syntax check failed; see error above"
18
+ end
19
+ end
@@ -0,0 +1,121 @@
1
+ require "test_helper"
2
+
3
+ require "commands/validate_schema"
4
+ require "tempfile"
5
+
6
+ describe Commands::ValidateSchema do
7
+ before do
8
+ @command = Commands::ValidateSchema.new
9
+ end
10
+
11
+ it "shows usage with no arguments" do
12
+ success = @command.run([])
13
+ assert_equal [], @command.errors
14
+ assert_equal [], @command.messages
15
+ refute success
16
+ end
17
+
18
+ it "runs successfully in fail fast mode" do
19
+ temp_file(basic_schema) do |path|
20
+ @command.fail_fast = true
21
+ success = @command.run([schema_path, path])
22
+ assert_equal [], @command.errors
23
+ assert_equal ["#{path} is valid."], @command.messages
24
+ assert success
25
+ end
26
+ end
27
+
28
+ it "runs successfully in detect mode" do
29
+ temp_file(basic_schema) do |path|
30
+ @command.extra_schemas << schema_path
31
+ @command.detect = true
32
+ success = @command.run([path])
33
+ assert_equal [], @command.errors
34
+ assert_equal ["#{path} is valid."], @command.messages
35
+ assert success
36
+ end
37
+ end
38
+
39
+ it "runs successfully out of detect mode" do
40
+ temp_file(basic_schema) do |path|
41
+ @command.detect = false
42
+ success = @command.run([schema_path, path])
43
+ assert_equal [], @command.errors
44
+ assert_equal ["#{path} is valid."], @command.messages
45
+ assert success
46
+ end
47
+ end
48
+
49
+ it "takes extra schemas" do
50
+ temp_file(basic_hyper_schema) do |path|
51
+ @command.detect = false
52
+ @command.extra_schemas << schema_path
53
+ success = @command.run([hyper_schema_path, path])
54
+ assert_equal [], @command.errors
55
+ assert_equal ["#{path} is valid."], @command.messages
56
+ assert success
57
+ end
58
+ end
59
+
60
+ it "requires at least one argument in detect mode" do
61
+ @command.detect = true
62
+ success = @command.run([])
63
+ assert_equal [], @command.errors
64
+ assert_equal [], @command.messages
65
+ refute success
66
+ end
67
+
68
+ it "requires at least two arguments out of detect mode" do
69
+ @command.detect = false
70
+ success = @command.run([hyper_schema_path])
71
+ assert_equal [], @command.errors
72
+ assert_equal [], @command.messages
73
+ refute success
74
+ end
75
+
76
+ it "errors on invalid files" do
77
+ @command.detect = false
78
+ success = @command.run(["dne-1", "dne-2"])
79
+ assert_equal ["dne-1: No such file or directory."], @command.errors
80
+ assert_equal [], @command.messages
81
+ refute success
82
+ end
83
+
84
+ it "errors on empty files" do
85
+ temp_file("") do |path|
86
+ success = @command.run([hyper_schema_path, path])
87
+ assert_equal ["#{path}: File is empty."], @command.errors
88
+ refute success
89
+ end
90
+ end
91
+
92
+ def basic_hyper_schema
93
+ <<-eos
94
+ { "$schema": "http://json-schema.org/draft-04/hyper-schema" }
95
+ eos
96
+ end
97
+
98
+ def basic_schema
99
+ <<-eos
100
+ { "$schema": "http://json-schema.org/draft-04/schema" }
101
+ eos
102
+ end
103
+
104
+ def hyper_schema_path
105
+ File.expand_path("schema.json", "#{__FILE__}/../../../schemas")
106
+ end
107
+
108
+ def schema_path
109
+ File.expand_path("schema.json", "#{__FILE__}/../../../schemas")
110
+ end
111
+
112
+ def temp_file(contents)
113
+ file = Tempfile.new("schema")
114
+ file.write(contents)
115
+ file.size() # flush
116
+ yield(file.path)
117
+ ensure
118
+ file.close
119
+ file.unlink
120
+ end
121
+ end