finitio 0.8.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +28 -0
- data/Gemfile +0 -10
- data/Gemfile.lock +84 -37
- data/README.md +1 -2
- data/finitio.gemspec +9 -157
- data/lib/finitio/json_schema/ad_type.rb +11 -0
- data/lib/finitio/json_schema/alias_type.rb +9 -0
- data/lib/finitio/json_schema/any_type.rb +9 -0
- data/lib/finitio/json_schema/builtin_type.rb +30 -0
- data/lib/finitio/json_schema/hash_based_type.rb +25 -0
- data/lib/finitio/json_schema/proxy_type.rb +9 -0
- data/lib/finitio/json_schema/rel_based_type.rb +13 -0
- data/lib/finitio/json_schema/seq_type.rb +12 -0
- data/lib/finitio/json_schema/set_type.rb +13 -0
- data/lib/finitio/json_schema/struct_type.rb +12 -0
- data/lib/finitio/json_schema/sub_type.rb +10 -0
- data/lib/finitio/json_schema/union_type.rb +23 -0
- data/lib/finitio/json_schema.rb +17 -0
- data/lib/finitio/support/heading.rb +8 -2
- data/lib/finitio/syntax/lexer.citrus +1 -1
- data/lib/finitio/version.rb +2 -2
- data/spec/inference/test_inference.rb +8 -8
- data/spec/json_schema/test_ad_type.rb +20 -0
- data/spec/json_schema/test_alias_type.rb +15 -0
- data/spec/json_schema/test_any_type.rb +11 -0
- data/spec/json_schema/test_builtin_type.rb +51 -0
- data/spec/json_schema/test_multi_relation_type.rb +58 -0
- data/spec/json_schema/test_multi_tuple_type.rb +50 -0
- data/spec/json_schema/test_relation_type.rb +30 -0
- data/spec/json_schema/test_seq_type.rb +18 -0
- data/spec/json_schema/test_set_type.rb +19 -0
- data/spec/json_schema/test_struct_type.rb +18 -0
- data/spec/json_schema/test_sub_type.rb +17 -0
- data/spec/json_schema/test_tuple_type.rb +26 -0
- data/spec/json_schema/test_union_type.rb +75 -0
- data/spec/regression/test_heading_extra_are_proxy_resolved.rb +41 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/syntax/nodes/test_attribute.rb +13 -1
- metadata +301 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67c8e3434a57c9b94e5175d34f6a20078c3ea3cd
|
4
|
+
data.tar.gz: 18e6c0cfc68d0ce75ec91c9e000a1a80db551a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baa24a0c65ebe967e44dd30b6b0e381a7e9abcb2f43b3a27d1b3f573aa4f14aa718295f2efdd36846edcd87ca0920bf0f065add879d6058723ff13f93cad8ac6
|
7
|
+
data.tar.gz: dcb03256d1892b6c6f42321d53b7fedbf7a43219228c235f91643ab94fe22aee5d6d728c5e159817f3105dfa3aed2c20338ae6f6ba8c8a73ab186397b4674da4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
# 0.11.1 - 2021/12/09
|
2
|
+
|
3
|
+
* Fix github actions and extend test grid.
|
4
|
+
|
5
|
+
# 0.11.0 - 2021/12/09
|
6
|
+
|
7
|
+
* Fix json schema generation of Boolean and union types with a |Nil
|
8
|
+
* Add support for dashses in attribute names (tuple & relation types).
|
9
|
+
|
10
|
+
# 0.10.0 - 2021/01/11
|
11
|
+
|
12
|
+
* Upgrade all dependencies.
|
13
|
+
|
14
|
+
* Ruby < 2.3 is no longer supported.
|
15
|
+
|
16
|
+
* Fix code and build under Ruby 3.0.
|
17
|
+
|
18
|
+
# 0.9.1 - 2020/12/24
|
19
|
+
|
20
|
+
* Fixes a bug where proxy types are not properly resolved when used
|
21
|
+
in a heading extra, e.g. `{ ...: Proxy }`
|
22
|
+
|
23
|
+
# 0.9.0 - 2020/12/16
|
24
|
+
|
25
|
+
* Add Type#to_json_schema that converts Finitio types to JSON schema
|
26
|
+
representations. This first implementation skips all constraints on sub types,
|
27
|
+
though. You need to explicitly require 'finitio/json_schema' to use it.
|
28
|
+
|
1
29
|
# 0.8.0 - 2019/10/21
|
2
30
|
|
3
31
|
* Add `Type#unconstrained` that returns a super type with all user specific
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,70 +1,117 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
finitio (0.
|
5
|
-
citrus (>=
|
4
|
+
finitio (0.11.1)
|
5
|
+
citrus (>= 3.0, < 4.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
10
|
+
activesupport (5.2.6)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
awesome_print (1.9.2)
|
16
|
+
builder (3.2.4)
|
12
17
|
citrus (3.0.2)
|
18
|
+
concurrent-ruby (1.1.9)
|
13
19
|
coveralls (0.8.23)
|
14
20
|
json (>= 1.8, < 3)
|
15
21
|
simplecov (~> 0.16.1)
|
16
22
|
term-ansicolor (~> 1.3)
|
17
23
|
thor (>= 0.19.4, < 2.0)
|
18
24
|
tins (~> 1.6)
|
19
|
-
cucumber (1.
|
20
|
-
builder (>= 2.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
cucumber (4.1.0)
|
26
|
+
builder (~> 3.2, >= 3.2.3)
|
27
|
+
cucumber-core (~> 7.1, >= 7.1.0)
|
28
|
+
cucumber-create-meta (~> 1.0.0, >= 1.0.0)
|
29
|
+
cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
|
30
|
+
cucumber-gherkin (~> 14.0, >= 14.0.1)
|
31
|
+
cucumber-html-formatter (~> 7.0, >= 7.0.0)
|
32
|
+
cucumber-messages (~> 12.2, >= 12.2.0)
|
33
|
+
cucumber-wire (~> 3.1, >= 3.1.0)
|
34
|
+
diff-lcs (~> 1.3, >= 1.3, < 1.4)
|
35
|
+
multi_test (~> 0.1, >= 0.1.2)
|
36
|
+
sys-uname (~> 1.0, >= 1.0.2)
|
37
|
+
cucumber-core (7.1.0)
|
38
|
+
cucumber-gherkin (~> 14.0, >= 14.0.1)
|
39
|
+
cucumber-messages (~> 12.2, >= 12.2.0)
|
40
|
+
cucumber-tag-expressions (~> 2.0, >= 2.0.4)
|
41
|
+
cucumber-create-meta (1.0.0)
|
42
|
+
cucumber-messages (~> 12.2, >= 12.2.0)
|
43
|
+
sys-uname (~> 1.2, >= 1.2.1)
|
44
|
+
cucumber-cucumber-expressions (10.3.0)
|
45
|
+
cucumber-gherkin (14.2.0)
|
46
|
+
cucumber-messages (~> 12.4, >= 12.4.0)
|
47
|
+
cucumber-html-formatter (7.2.0)
|
48
|
+
cucumber-messages (~> 12.4, >= 12.4.0)
|
49
|
+
cucumber-messages (12.4.0)
|
50
|
+
protobuf-cucumber (~> 3.10, >= 3.10.8)
|
51
|
+
cucumber-tag-expressions (2.0.4)
|
52
|
+
cucumber-wire (3.1.0)
|
53
|
+
cucumber-core (~> 7.1, >= 7.1.0)
|
54
|
+
cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
|
55
|
+
cucumber-messages (~> 12.2, >= 12.2.0)
|
25
56
|
diff-lcs (1.3)
|
26
|
-
docile (1.3.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
docile (1.3.5)
|
58
|
+
ffi (1.15.4)
|
59
|
+
i18n (1.8.11)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
json (2.6.1)
|
62
|
+
middleware (0.1.0)
|
63
|
+
minitest (5.14.4)
|
64
|
+
multi_json (1.15.0)
|
31
65
|
multi_test (0.1.2)
|
32
|
-
path (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
66
|
+
path (2.0.1)
|
67
|
+
protobuf-cucumber (3.10.8)
|
68
|
+
activesupport (>= 3.2)
|
69
|
+
middleware
|
70
|
+
thor
|
71
|
+
thread_safe
|
72
|
+
rake (13.0.6)
|
73
|
+
rspec (3.10.0)
|
74
|
+
rspec-core (~> 3.10.0)
|
75
|
+
rspec-expectations (~> 3.10.0)
|
76
|
+
rspec-mocks (~> 3.10.0)
|
77
|
+
rspec-core (3.10.1)
|
78
|
+
rspec-support (~> 3.10.0)
|
79
|
+
rspec-expectations (3.10.1)
|
41
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-mocks (3.
|
81
|
+
rspec-support (~> 3.10.0)
|
82
|
+
rspec-mocks (3.10.2)
|
44
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-support (3.
|
84
|
+
rspec-support (~> 3.10.0)
|
85
|
+
rspec-support (3.10.3)
|
47
86
|
simplecov (0.16.1)
|
48
87
|
docile (~> 1.1)
|
49
88
|
json (>= 1.8, < 3)
|
50
89
|
simplecov-html (~> 0.10.0)
|
51
90
|
simplecov-html (0.10.2)
|
91
|
+
sync (0.5.0)
|
92
|
+
sys-uname (1.2.2)
|
93
|
+
ffi (~> 1.1)
|
52
94
|
term-ansicolor (1.7.1)
|
53
95
|
tins (~> 1.0)
|
54
|
-
thor (
|
55
|
-
|
96
|
+
thor (1.1.0)
|
97
|
+
thread_safe (0.3.6)
|
98
|
+
tins (1.29.1)
|
99
|
+
sync
|
100
|
+
tzinfo (1.2.9)
|
101
|
+
thread_safe (~> 0.1)
|
56
102
|
|
57
103
|
PLATFORMS
|
58
|
-
|
104
|
+
x86_64-linux
|
59
105
|
|
60
106
|
DEPENDENCIES
|
61
|
-
awesome_print (~> 1.
|
62
|
-
coveralls
|
63
|
-
cucumber (~> 1
|
107
|
+
awesome_print (~> 1.8)
|
108
|
+
coveralls (~> 0.8)
|
109
|
+
cucumber (~> 4.1)
|
64
110
|
finitio!
|
65
|
-
|
66
|
-
|
111
|
+
multi_json (~> 1.15)
|
112
|
+
path (>= 2.0, < 3.0)
|
113
|
+
rake (~> 13.0)
|
67
114
|
rspec (~> 3.0)
|
68
115
|
|
69
116
|
BUNDLED WITH
|
70
|
-
2.
|
117
|
+
2.2.33
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
[](https://gemnasium.com/blambeau/finitio-rb)
|
1
|
+
[](https://travis-ci.org/blambeau/finitio-rb)
|
3
2
|
[](https://codeclimate.com/github/blambeau/finitio-rb)
|
4
3
|
[](https://coveralls.io/r/blambeau/finitio-rb)
|
5
4
|
|
data/finitio.gemspec
CHANGED
@@ -1,186 +1,38 @@
|
|
1
|
-
# We require your library, mainly to have access to the VERSION number.
|
2
|
-
# Feel free to set $version manually.
|
3
1
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
2
|
require "finitio/version"
|
5
3
|
$version = Finitio::Version.to_s
|
6
4
|
|
7
|
-
#
|
8
|
-
# This is your Gem specification. Default values are provided so that your library
|
9
|
-
# should be correctly packaged given what you have described in the .noespec file.
|
10
|
-
#
|
11
5
|
Gem::Specification.new do |s|
|
12
|
-
|
13
|
-
################################################################### ABOUT YOUR GEM
|
14
|
-
|
15
|
-
# Gem name (required)
|
16
6
|
s.name = "finitio"
|
17
|
-
|
18
|
-
# Gem version (required)
|
19
7
|
s.version = $version
|
20
|
-
|
21
|
-
# A short summary of this gem
|
22
|
-
#
|
23
|
-
# This is displayed in `gem list -d`.
|
24
8
|
s.summary = "Finitio - in Ruby"
|
25
|
-
|
26
|
-
# A long description of this gem (required)
|
27
|
-
#
|
28
|
-
# The description should be more detailed than the summary. For example,
|
29
|
-
# you might wish to copy the entire README into the description.
|
30
9
|
s.description = "Implements the Finitio information language in Ruby."
|
31
|
-
|
32
|
-
# The URL of this gem home page (optional)
|
33
10
|
s.homepage = "https://github.com/blambeau/finitio"
|
34
|
-
|
35
|
-
# Gem publication date (required but auto)
|
36
|
-
#
|
37
|
-
# Today is automatically used by default, uncomment only if
|
38
|
-
# you know what you do!
|
39
|
-
#
|
40
|
-
# s.date = Time.now.strftime('%Y-%m-%d')
|
41
|
-
|
42
|
-
# The license(s) for the library. Each license must be a short name, no
|
43
|
-
# more than 64 characters.
|
44
|
-
#
|
45
|
-
# s.licences = %w{}
|
46
|
-
|
47
|
-
# The rubyforge project this gem lives under (optional)
|
48
|
-
#
|
49
|
-
# s.rubyforge_project = nil
|
50
|
-
|
51
|
-
################################################################### ABOUT THE AUTHORS
|
52
|
-
|
53
|
-
# The list of author names who wrote this gem.
|
54
|
-
#
|
55
|
-
# If you are providing multiple authors and multiple emails they should be
|
56
|
-
# in the same order.
|
57
|
-
#
|
58
11
|
s.authors = ["Bernard Lambeau"]
|
59
|
-
|
60
|
-
# Contact emails for this gem
|
61
|
-
#
|
62
|
-
# If you are providing multiple authors and multiple emails they should be
|
63
|
-
# in the same order.
|
64
|
-
#
|
65
|
-
# NOTE: Somewhat strangly this attribute is always singular!
|
66
|
-
# Don't replace by s.emails = ...
|
67
12
|
s.email = ["blambeau@gmail.com"]
|
68
|
-
|
69
|
-
################################################################### PATHS, FILES, BINARIES
|
70
|
-
|
71
|
-
# Paths in the gem to add to $LOAD_PATH when this gem is
|
72
|
-
# activated (required).
|
73
|
-
#
|
74
|
-
# The default 'lib' is typically sufficient.
|
75
13
|
s.require_paths = ["lib"]
|
76
|
-
|
77
|
-
# Files included in this gem.
|
78
|
-
#
|
79
|
-
# By default, we take all files included in the Manifest.txt file on root
|
80
|
-
# of the project. Entries of the manifest are interpreted as Dir[...]
|
81
|
-
# patterns so that lazy people may use wilcards like lib/**/*
|
82
|
-
#
|
83
14
|
here = File.expand_path(File.dirname(__FILE__))
|
84
15
|
s.files = File.readlines(File.join(here, 'Manifest.txt')).
|
85
16
|
inject([]){|files, pattern| files + Dir[File.join(here, pattern.strip)]}.
|
86
17
|
collect{|x| x[(1+here.size)..-1]}
|
87
18
|
|
88
|
-
# Test files included in this gem.
|
89
|
-
#
|
90
19
|
s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
|
91
|
-
|
92
|
-
# The path in the gem for executable scripts (optional)
|
93
|
-
#
|
94
20
|
s.bindir = "bin"
|
95
|
-
|
96
|
-
# Executables included in the gem.
|
97
|
-
#
|
98
21
|
s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
|
99
|
-
|
100
|
-
################################################################### REQUIREMENTS & INSTALL
|
101
|
-
# Remember the gem version requirements operators and schemes:
|
102
|
-
# = Equals version
|
103
|
-
# != Not equal to version
|
104
|
-
# > Greater than version
|
105
|
-
# < Less than version
|
106
|
-
# >= Greater than or equal to
|
107
|
-
# <= Less than or equal to
|
108
|
-
# ~> Approximately greater than
|
109
|
-
#
|
110
|
-
# Don't forget to have a look at http://lmgtfy.com/?q=Ruby+Versioning+Policies
|
111
|
-
# for setting your gem version.
|
112
|
-
#
|
113
|
-
# For your requirements to other gems, remember that
|
114
|
-
# ">= 2.2.0" (optimistic: specify minimal version)
|
115
|
-
# ">= 2.2.0", "< 3.0" (pessimistic: not greater than the next major)
|
116
|
-
# "~> 2.2" (shortcut for ">= 2.2.0", "< 3.0")
|
117
|
-
# "~> 2.2.0" (shortcut for ">= 2.2.0", "< 2.3.0")
|
118
|
-
#
|
119
|
-
s.add_dependency("citrus", ">= 2.4", "< 4.0")
|
120
|
-
|
121
|
-
#
|
122
|
-
# One call to add_dependency('gem_name', 'gem version requirement') for each
|
123
|
-
# runtime dependency. These gems will be installed with your gem.
|
124
|
-
# One call to add_development_dependency('gem_name', 'gem version requirement')
|
125
|
-
# for each development dependency. These gems are required for developers
|
126
|
-
#
|
127
|
-
# We use Gemfile for development dependencies.
|
128
22
|
|
23
|
+
s.add_dependency("citrus", ">= 3.0", "< 4.0")
|
24
|
+
|
25
|
+
s.add_development_dependency("rake", "~> 13.0")
|
26
|
+
s.add_development_dependency("rspec", "~> 3.0")
|
27
|
+
s.add_development_dependency("cucumber", "~> 4.1")
|
28
|
+
s.add_development_dependency("path", ">= 2.0", "< 3.0")
|
29
|
+
s.add_development_dependency("awesome_print", "~> 1.8")
|
30
|
+
s.add_development_dependency("coveralls", "~> 0.8")
|
31
|
+
s.add_development_dependency("multi_json", "~> 1.15")
|
129
32
|
|
130
|
-
# The version of ruby required by this gem
|
131
|
-
#
|
132
|
-
# Uncomment and set this if your gem requires specific ruby versions.
|
133
|
-
#
|
134
|
-
# s.required_ruby_version = ">= 0"
|
135
|
-
|
136
|
-
# The RubyGems version required by this gem
|
137
|
-
#
|
138
|
-
# s.required_rubygems_version = ">= 0"
|
139
|
-
|
140
|
-
# The platform this gem runs on. See Gem::Platform for details.
|
141
|
-
#
|
142
|
-
# s.platform = nil
|
143
|
-
|
144
|
-
# Extensions to build when installing the gem.
|
145
|
-
#
|
146
|
-
# Valid types of extensions are extconf.rb files, configure scripts
|
147
|
-
# and rakefiles or mkrf_conf files.
|
148
|
-
#
|
149
33
|
s.extensions = []
|
150
|
-
|
151
|
-
# External (to RubyGems) requirements that must be met for this gem to work.
|
152
|
-
# It’s simply information for the user.
|
153
|
-
#
|
154
34
|
s.requirements = nil
|
155
|
-
|
156
|
-
# A message that gets displayed after the gem is installed
|
157
|
-
#
|
158
|
-
# Uncomment and set this if you want to say something to the user
|
159
|
-
# after gem installation
|
160
|
-
#
|
161
35
|
s.post_install_message = nil
|
162
|
-
|
163
|
-
################################################################### SECURITY
|
164
|
-
|
165
|
-
# The key used to sign this gem. See Gem::Security for details.
|
166
|
-
#
|
167
|
-
# s.signing_key = nil
|
168
|
-
|
169
|
-
# The certificate chain used to sign this gem. See Gem::Security for
|
170
|
-
# details.
|
171
|
-
#
|
172
|
-
# s.cert_chain = []
|
173
|
-
|
174
|
-
################################################################### RDOC
|
175
|
-
|
176
|
-
# An ARGV style array of options to RDoc
|
177
|
-
#
|
178
|
-
# See 'rdoc --help' about this
|
179
|
-
#
|
180
36
|
s.rdoc_options = []
|
181
|
-
|
182
|
-
# Extra files to add to RDoc such as README
|
183
|
-
#
|
184
37
|
s.extra_rdoc_files = Dir["README.md"] + Dir["CHANGELOG.md"] + Dir["LICENCE.md"]
|
185
|
-
|
186
38
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
|
4
|
+
BUILTIN_MAPPING = {
|
5
|
+
NilClass => "null",
|
6
|
+
String => "string",
|
7
|
+
Integer => "integer",
|
8
|
+
Fixnum => "integer",
|
9
|
+
Bignum => "integer",
|
10
|
+
Float => "number",
|
11
|
+
Numeric => "number",
|
12
|
+
TrueClass => "boolean",
|
13
|
+
FalseClass => "boolean",
|
14
|
+
Object => "object"
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
class BuiltinType
|
19
|
+
|
20
|
+
def to_json_schema(*args, &bl)
|
21
|
+
mapped = JsonSchema::BUILTIN_MAPPING[ruby_type]
|
22
|
+
if mapped
|
23
|
+
{ type: mapped }
|
24
|
+
else
|
25
|
+
raise JsonSchema::Error, "Unable to map #{ruby_type} to json-schema"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end # class BuiltinType
|
30
|
+
end # module Finitio
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Finitio
|
2
|
+
module HashBasedType
|
3
|
+
|
4
|
+
def to_json_schema(*args, &bl)
|
5
|
+
base = {
|
6
|
+
type: "object"
|
7
|
+
}
|
8
|
+
unless heading.empty?
|
9
|
+
base[:properties] = heading.inject({}){|ps,a|
|
10
|
+
ps.merge(a.name => a.type.to_json_schema(*args, &bl))
|
11
|
+
}
|
12
|
+
end
|
13
|
+
unless (reqs = heading.select{|a| a.required? }).empty?
|
14
|
+
base[:required] = reqs.map{|a| a.name }
|
15
|
+
end
|
16
|
+
base[:additionalProperties] = if heading.allow_extra?
|
17
|
+
heading.allow_extra.to_json_schema(*args, &bl)
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
|
+
base
|
22
|
+
end
|
23
|
+
|
24
|
+
end # module HashBasedType
|
25
|
+
end # module UnionType
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Finitio
|
2
|
+
class UnionType
|
3
|
+
|
4
|
+
NIL_TYPE = BuiltinType.new(NilClass)
|
5
|
+
|
6
|
+
FALSE_TYPE = BuiltinType.new(TrueClass)
|
7
|
+
|
8
|
+
TRUE_TYPE = BuiltinType.new(FalseClass)
|
9
|
+
|
10
|
+
BOOLEAN_TYPE = UnionType.new([TRUE_TYPE, FALSE_TYPE])
|
11
|
+
|
12
|
+
def to_json_schema(*args, &bl)
|
13
|
+
cs = candidates.reject{|c| c == NIL_TYPE }
|
14
|
+
return { type: 'boolean'} if self == BOOLEAN_TYPE
|
15
|
+
return cs.first.to_json_schema(*args, &bl) if cs.size == 1
|
16
|
+
|
17
|
+
{
|
18
|
+
anyOf: cs.map{|c| c.to_json_schema(*args, &bl) }
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class UnionType
|
23
|
+
end # module Finitio
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Finitio
|
2
|
+
module JsonSchema
|
3
|
+
class Error < Finitio::Error; end
|
4
|
+
end # module JsonSchema
|
5
|
+
end # module Finitio
|
6
|
+
require_relative 'json_schema/ad_type'
|
7
|
+
require_relative 'json_schema/any_type'
|
8
|
+
require_relative 'json_schema/alias_type'
|
9
|
+
require_relative 'json_schema/builtin_type'
|
10
|
+
require_relative 'json_schema/hash_based_type'
|
11
|
+
require_relative 'json_schema/rel_based_type'
|
12
|
+
require_relative 'json_schema/seq_type'
|
13
|
+
require_relative 'json_schema/set_type'
|
14
|
+
require_relative 'json_schema/struct_type'
|
15
|
+
require_relative 'json_schema/sub_type'
|
16
|
+
require_relative 'json_schema/union_type'
|
17
|
+
require_relative 'json_schema/proxy_type'
|
@@ -100,8 +100,14 @@ module Finitio
|
|
100
100
|
protected :attributes, :options
|
101
101
|
|
102
102
|
def resolve_proxies(system)
|
103
|
-
as = attributes.map{|k,a|
|
104
|
-
|
103
|
+
as = attributes.map{|k,a|
|
104
|
+
a.resolve_proxies(system)
|
105
|
+
}
|
106
|
+
opts = options.dup
|
107
|
+
if options[:allow_extra] && options[:allow_extra].is_a?(Type)
|
108
|
+
opts[:allow_extra] = opts[:allow_extra].resolve_proxies(system)
|
109
|
+
end
|
110
|
+
Heading.new(as, opts)
|
105
111
|
end
|
106
112
|
|
107
113
|
def unconstrained
|