lacerda 0.14.8 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +0 -3
- data/lacerda.gemspec +1 -1
- data/lib/lacerda/conversion.rb +1 -1
- data/lib/lacerda/conversion/data_structure.rb +53 -13
- data/lib/lacerda/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba190f9b01d30f9afeb11e942c37982a3dd08ab4
|
4
|
+
data.tar.gz: 58a84ea79e3ee495ca67066f7ca7ffa7a5b5f68d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f7239617c9d9b789b3af53ba83d378e3bbd7de016944816f4910726f80c60e58b595a7888bd67effa8cf9f252d1d6772dc43094ef1162f7621db930812de19
|
7
|
+
data.tar.gz: 75401fc75ec919d81a8d998d7ecc876720f7d81d3ec332ad7649123b5d5f6615c97127effd9f0e3eb54ce618359cd5753ca2df922a94c765281c26ae75c85f2a
|
data/CHANGELOG.markdown
CHANGED
data/lacerda.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "json-schema", ["~> 2.6.2"]
|
26
26
|
|
27
|
-
spec.add_runtime_dependency "redsnow", ["~> 0.4.
|
27
|
+
spec.add_runtime_dependency "redsnow", ["~> 0.4.3"]
|
28
28
|
spec.add_runtime_dependency "colorize"
|
29
29
|
spec.add_runtime_dependency "blumquist", ["~> 0.5"]
|
30
30
|
|
data/lib/lacerda/conversion.rb
CHANGED
@@ -29,7 +29,7 @@ module Lacerda
|
|
29
29
|
service_scope = File.dirname(filename).split(File::SEPARATOR).last.underscore
|
30
30
|
|
31
31
|
# Parse MSON to an apiary blueprint AST
|
32
|
-
# (see https://github.com/apiaryio/api-blueprint
|
32
|
+
# (see https://github.com/apiaryio/api-blueprint)
|
33
33
|
ast_file = mson_to_ast_json(filename)
|
34
34
|
|
35
35
|
# Pluck out Data structures from it
|
@@ -38,6 +38,7 @@ module Lacerda
|
|
38
38
|
@schema['title'] = @id
|
39
39
|
add_description_to_json_schema
|
40
40
|
add_properties_to_json_schema
|
41
|
+
@schema['additionalProperties'] = false
|
41
42
|
end
|
42
43
|
|
43
44
|
def to_json
|
@@ -72,8 +73,8 @@ module Lacerda
|
|
72
73
|
spec = {}
|
73
74
|
name = Lacerda.underscore(content['name']['literal'])
|
74
75
|
|
75
|
-
# This is either type: primimtive or $ref: reference_name
|
76
|
-
spec.merge!(
|
76
|
+
# This is either type: primimtive or a oneOf { $ref: reference_name }
|
77
|
+
spec.merge!(primitive_or_oneOf(type, is_required))
|
77
78
|
|
78
79
|
# We might have a description
|
79
80
|
spec['description'] = content['description']
|
@@ -81,8 +82,7 @@ module Lacerda
|
|
81
82
|
# If it's an array, we need to pluck out the item types
|
82
83
|
if type == 'array'
|
83
84
|
nestedTypes = type_definition['typeSpecification']['nestedTypes']
|
84
|
-
|
85
|
-
spec['items'] = nestedTypes.map{|t| primitive_or_reference(t, false) }
|
85
|
+
spec['items'] = array_items(nestedTypes)
|
86
86
|
|
87
87
|
# If it's an object, we need recursion
|
88
88
|
elsif type == 'object'
|
@@ -101,22 +101,62 @@ module Lacerda
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
# returns the type of an array, given its specified type(s). This will be
|
105
|
+
# either exactly one basic type, or a oneOf in case there are 1+ types
|
106
|
+
# or exactly 1 non-basic type.
|
107
|
+
# As there are specied types in the array, `nil` should not be a valid value
|
108
|
+
# and therefore required should be true.
|
109
|
+
def array_items(types)
|
110
|
+
if types.size == 1 && PRIMITIVES.include?(types.first)
|
111
|
+
primitive(types.first, true)
|
112
|
+
else
|
113
|
+
oneOf(types, true)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def primitive_or_oneOf(type, is_required)
|
105
118
|
return { 'type' => 'object' } if type.blank?
|
119
|
+
if PRIMITIVES.include?(type)
|
120
|
+
primitive(type, is_required)
|
121
|
+
else
|
122
|
+
oneOf([type], is_required)
|
123
|
+
end
|
124
|
+
end
|
106
125
|
|
126
|
+
# A basic type is either a primitive type with exactly 1 primitive type
|
127
|
+
# {'type' => [boolean] }
|
128
|
+
# a reference
|
129
|
+
# { '$ref' => "#/definitions/name" }
|
130
|
+
# or an object if the type in not there
|
131
|
+
# { 'type' => object }
|
132
|
+
# Basic types don't care about being required or not.
|
133
|
+
def basic_type(type)
|
134
|
+
return { 'type' => 'object' } if type.blank?
|
107
135
|
if PRIMITIVES.include?(type)
|
108
|
-
|
109
|
-
types << 'null' unless is_required
|
110
|
-
{ 'type' => types }
|
136
|
+
primitive(type, true)
|
111
137
|
else
|
112
|
-
|
113
|
-
types << { 'type' => 'null' } unless is_required
|
114
|
-
{
|
115
|
-
'oneOf' => types
|
116
|
-
}
|
138
|
+
reference(type)
|
117
139
|
end
|
118
140
|
end
|
119
141
|
|
142
|
+
def oneOf(types, is_required)
|
143
|
+
types = types.map { |type| basic_type(type) }
|
144
|
+
types << { 'type' => 'null' } unless is_required
|
145
|
+
{
|
146
|
+
'oneOf' => types.uniq
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def primitive(type, is_required)
|
151
|
+
types = [type]
|
152
|
+
types << 'null' unless is_required
|
153
|
+
{ 'type' => types }
|
154
|
+
end
|
155
|
+
|
156
|
+
def reference(type)
|
157
|
+
{'$ref' => "#/definitions/#{self.class.scope(@scope, type['literal'])}" }
|
158
|
+
end
|
159
|
+
|
120
160
|
def json_schema_blueprint
|
121
161
|
{
|
122
162
|
"type" => "object",
|
data/lib/lacerda/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lacerda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jannis Hermanns
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.4.
|
61
|
+
version: 0.4.3
|
62
62
|
type: :runtime
|
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.4.
|
68
|
+
version: 0.4.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: colorize
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,9 +276,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
276
276
|
version: '0'
|
277
277
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
278
278
|
requirements:
|
279
|
-
- - "
|
279
|
+
- - ">"
|
280
280
|
- !ruby/object:Gem::Version
|
281
|
-
version:
|
281
|
+
version: 1.3.1
|
282
282
|
requirements: []
|
283
283
|
rubyforge_project:
|
284
284
|
rubygems_version: 2.5.1
|