raml_parser 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/raml_parser.rb +52 -32
- data/lib/raml_parser/model.rb +8 -4
- data/lib/raml_parser/version.rb +1 -1
- data/spec/examples/raml/baseuriparameters1.raml +6 -0
- data/spec/examples/raml/baseuriparameters2.raml +16 -0
- data/spec/examples/raml/schemas.raml +41 -0
- data/spec/examples/raml_bad/uriparameters.raml +10 -0
- data/spec/lib/raml_parser_spec.rb +41 -10
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abe1cc6ee7e11604113e202e4c9b301b96bdcbe5
|
4
|
+
data.tar.gz: 98af92840d95058855e4bfe9f599886fffafe2a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47f74ef12621fe8156078eb71df570f89390e379ec2d46682b5406a3bee6ef872810a03c5105c6b795fe2618fdd12df781f540c18105f1af046293456553050
|
7
|
+
data.tar.gz: 97557ac026a4dc26aaab273e4d9556f30b6e8255d0c92061aa1ac7895c83739a2d32930f4b9da581d30d4ef698341f67bf0771a177f9add568b577bf2760e54c
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# RamlParser
|
2
2
|
|
3
3
|
[![build](https://img.shields.io/travis/ePages-de/raml_parser/develop.svg)](https://travis-ci.org/ePages-de/raml_parser)
|
4
|
-
[![
|
4
|
+
[![gem](https://img.shields.io/gem/v/raml_parser.svg)](https://rubygems.org/gems/raml_parser)
|
5
|
+
[![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT)
|
5
6
|
|
6
7
|
A parser for the [RAML](http://raml.org/) API modeling language.
|
7
8
|
|
@@ -10,7 +11,9 @@ A parser for the [RAML](http://raml.org/) API modeling language.
|
|
10
11
|
Add this line to your application's Gemfile:
|
11
12
|
|
12
13
|
```ruby
|
13
|
-
|
14
|
+
source 'https://rubygems.org'
|
15
|
+
|
16
|
+
gem 'raml_parser'
|
14
17
|
```
|
15
18
|
|
16
19
|
And then execute:
|
@@ -25,8 +28,6 @@ TODO: Write usage instructions here
|
|
25
28
|
|
26
29
|
These are features of the RAML 0.8 specification that are not fully handled yet. This list should be complete, i.e. everything not listed here should work.
|
27
30
|
|
28
|
-
* [Base URI Parameters](http://raml.org/spec.html#base-uri-parameters)
|
29
|
-
* [Schemas](http://raml.org/spec.html#schemas)
|
30
31
|
* [Protocols](http://raml.org/spec.html#protocols)
|
31
32
|
* [Named parameters with multiple types](http://raml.org/spec.html#named-parameters-with-multiple-types)
|
32
33
|
|
data/lib/raml_parser.rb
CHANGED
@@ -3,14 +3,14 @@ require 'raml_parser/model'
|
|
3
3
|
|
4
4
|
module RamlParser
|
5
5
|
class Parser
|
6
|
-
attr_reader :path, :root
|
7
|
-
|
8
6
|
def self.parse_file(path)
|
7
|
+
ensure_raml_0_8(path)
|
9
8
|
node = YamlNode.new(nil, 'root', YamlHelper.read_yaml(path))
|
10
9
|
parse_root(node)
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.parse_file_with_marks(path)
|
13
|
+
ensure_raml_0_8(path)
|
14
14
|
node = YamlNode.new(nil, 'root', YamlHelper.read_yaml(path))
|
15
15
|
node.mark_all(:unused)
|
16
16
|
node.mark(:used)
|
@@ -20,20 +20,28 @@ module RamlParser
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def self.
|
24
|
-
|
23
|
+
def self.ensure_raml_0_8(path)
|
24
|
+
first_line = File.open(path) { |f| f.readline }.strip
|
25
|
+
raise "File #{path} does not start with RAML 0.8 comment" unless first_line == '#%RAML 0.8'
|
26
|
+
end
|
25
27
|
|
28
|
+
def self.parse_root(node)
|
26
29
|
root = Model::Root.new
|
27
30
|
root.title = node.hash('title').or_default('').value
|
28
|
-
root.base_uri = node.hash('baseUri').or_default('').value
|
29
31
|
root.version = node.hash('version').value
|
32
|
+
root.base_uri = node.hash('baseUri').or_default('').value.gsub('{version}', root.version || '')
|
30
33
|
root.media_type = node.hash('mediaType').value
|
31
34
|
root.secured_by = node.hash('securedBy').or_default([]).array_map { |n| n.value }
|
32
35
|
root.documentation = node.hash('documentation').array_map { |n| parse_documenation(n) }
|
36
|
+
root.schemas = node.hash('schemas').arrayhash_map { |n| n.value }
|
33
37
|
root.security_schemes = node.hash('securitySchemes').arrayhash_map { |n| parse_security_scheme(n) }
|
34
38
|
root.resource_types = node.hash('resourceTypes').mark_all(:used).arrayhash_map { |n| n }
|
35
39
|
root.traits = node.hash('traits').mark_all(:used).arrayhash_map { |n| n }
|
36
40
|
|
41
|
+
implicit_base_uri_parameters = extract_uri_parameters(root.base_uri)
|
42
|
+
explicit_base_uri_parameters = node.hash('baseUriParameters').hash_map { |n| parse_named_parameter(n) }
|
43
|
+
root.base_uri_parameters = implicit_base_uri_parameters.merge(explicit_base_uri_parameters)
|
44
|
+
|
37
45
|
root.resources = traverse_resources(node, nil) do |n,parent|
|
38
46
|
parent_absolute_uri = parent != nil ? parent.absolute_uri : root.base_uri || ''
|
39
47
|
parent_relative_uri = parent != nil ? parent.relative_uri : ''
|
@@ -45,25 +53,23 @@ module RamlParser
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def self.parse_resource(node, root, parent_absolute_uri, parent_relative_uri, parent_uri_parameters, as_resource_type)
|
48
|
-
def self.extract_uri_parameters(relative_uri)
|
49
|
-
names = relative_uri.scan(/\{([a-zA-Z\_\-]+)\}/).map { |m| m.first }
|
50
|
-
Hash[names.map { |name| [name, Model::NamedParameter.new(name, 'string', name)] }]
|
51
|
-
end
|
52
|
-
|
53
56
|
node = node.or_default({})
|
54
57
|
resource = Model::Resource.new(parent_absolute_uri + node.key, parent_relative_uri + node.key)
|
55
58
|
resource.display_name = node.hash('displayName').value
|
56
59
|
resource.description = node.hash('description').value
|
57
|
-
resource.uri_parameters = extract_uri_parameters(node.key).merge(parent_uri_parameters.merge(node.hash('uriParameters').hash_map { |n| parse_named_parameter(n) }))
|
58
60
|
resource.type = parse_type(node.hash('type'))
|
59
61
|
resource.is = parse_is(node.hash('is'))
|
60
62
|
resource.secured_by = (root.secured_by + node.hash('securedBy').or_default([]).array_map { |n| n.value }).uniq
|
63
|
+
resource.methods = Hash[find_method_nodes(node).map { |n| [n.key, parse_method(n, root, resource, as_resource_type)] }]
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
root_base_uri_parameters = root.base_uri_parameters
|
66
|
+
own_base_uri_parameters = node.hash('baseUriParameters').hash_map { |n| parse_named_parameter(n) }
|
67
|
+
resource.base_uri_parameters = root_base_uri_parameters.merge(own_base_uri_parameters)
|
68
|
+
|
69
|
+
implicit_uri_parameters = extract_uri_parameters(node.key)
|
70
|
+
explicit_uri_parameters = node.hash('uriParameters').hash_map { |n| parse_named_parameter(n) }
|
71
|
+
raise 'Can only explicitly specify URI parameters from the current relative URI' unless as_resource_type or (explicit_uri_parameters.keys - implicit_uri_parameters.keys).empty?
|
72
|
+
resource.uri_parameters = parent_uri_parameters.merge(implicit_uri_parameters).merge(explicit_uri_parameters)
|
67
73
|
|
68
74
|
unless as_resource_type
|
69
75
|
resource = mixin_resource_types(node, root, resource)
|
@@ -79,8 +85,8 @@ module RamlParser
|
|
79
85
|
method.display_name = node.hash('displayName').value
|
80
86
|
method.description = node.hash('description').value
|
81
87
|
method.query_parameters = node.hash('queryParameters').hash_map { |n| parse_named_parameter(n) }
|
82
|
-
method.bodies = node.hash('body').hash_map { |n| parse_body(n) }
|
83
|
-
method.responses = node.hash('responses').hash_map { |n| parse_response(n) }
|
88
|
+
method.bodies = node.hash('body').hash_map { |n| parse_body(n, root) }
|
89
|
+
method.responses = node.hash('responses').hash_map { |n| parse_response(n, root) }
|
84
90
|
method.headers = node.hash('headers').hash_map { |n| parse_named_parameter(n) }
|
85
91
|
method.secured_by = (resource.secured_by + node.hash('securedBy').or_default([]).array_map { |n| n.value }).uniq if resource
|
86
92
|
method.is = parse_is(node.hash('is'))
|
@@ -93,12 +99,12 @@ module RamlParser
|
|
93
99
|
method
|
94
100
|
end
|
95
101
|
|
96
|
-
def self.parse_response(node)
|
102
|
+
def self.parse_response(node, root)
|
97
103
|
node = node.or_default({})
|
98
104
|
response = Model::Response.new(node.key)
|
99
105
|
response.display_name = node.hash('displayName').value
|
100
106
|
response.description = node.hash('description').value
|
101
|
-
response.bodies = node.hash('body').hash_map { |n| parse_body(n) }
|
107
|
+
response.bodies = node.hash('body').hash_map { |n| parse_body(n, root) }
|
102
108
|
response.headers = node.hash('headers').hash_map { |n| parse_named_parameter(n) }
|
103
109
|
response
|
104
110
|
end
|
@@ -128,24 +134,23 @@ module RamlParser
|
|
128
134
|
named_parameter
|
129
135
|
end
|
130
136
|
|
131
|
-
def self.parse_body(node)
|
137
|
+
def self.parse_body(node, root)
|
132
138
|
node = node.or_default({})
|
133
139
|
body = Model::Body.new(node.key)
|
134
140
|
body.example = node.hash('example').value
|
135
141
|
body.schema = node.hash('schema').value
|
142
|
+
body.schema = root.schemas[body.schema] if root.schemas.has_key? body.schema
|
136
143
|
body.form_parameters = node.hash('formParameters').hash_map { |n| parse_named_parameter(n) }
|
137
144
|
# TODO: Form parameters are only allowed for media type application/x-www-form-urlencoded or multipart/form-data
|
138
145
|
body
|
139
146
|
end
|
140
147
|
|
141
148
|
def self.parse_security_scheme(node)
|
142
|
-
node.hash('describedBy').mark_all(:unsupported) if node.value.has_key? 'describedBy'
|
143
|
-
|
144
149
|
node = node.or_default({})
|
145
150
|
security_scheme = Model::SecurityScheme.new(node.key)
|
146
151
|
security_scheme.type = node.hash('type').value
|
147
152
|
security_scheme.description = node.hash('description').value
|
148
|
-
security_scheme.described_by = node.hash('describedBy')
|
153
|
+
security_scheme.described_by = parse_method(node.hash('describedBy'), nil, nil, true)
|
149
154
|
security_scheme.settings = node.hash('settings').mark_all(:used).value
|
150
155
|
security_scheme
|
151
156
|
end
|
@@ -256,15 +261,30 @@ module RamlParser
|
|
256
261
|
YamlNode.new(node.parent, node.key, traverse(node.value, params, node))
|
257
262
|
end
|
258
263
|
|
264
|
+
def self.find_resource_nodes(node)
|
265
|
+
def self.is_resource(key)
|
266
|
+
key =~ /^\//
|
267
|
+
end
|
268
|
+
(node.value || {}).select { |k,_| is_resource(k) }.map { |k,_| node.hash(k) }
|
269
|
+
end
|
270
|
+
|
271
|
+
def self.find_method_nodes(node)
|
272
|
+
def self.is_method(key)
|
273
|
+
%w(get post put delete head patch options trace connect).include? key
|
274
|
+
end
|
275
|
+
(node.value || {}).select { |k,_| is_method(k) }.map { |k,_| node.hash(k) }
|
276
|
+
end
|
277
|
+
|
278
|
+
def self.extract_uri_parameters(uri)
|
279
|
+
names = uri.scan(/\{([a-zA-Z\_\-]+)\}/).map { |m| m.first }
|
280
|
+
Hash[names.map { |name| [name, Model::NamedParameter.new(name, 'string', name)] }]
|
281
|
+
end
|
282
|
+
|
259
283
|
def self.traverse_resources(node, parent_resource, &code)
|
260
|
-
node.
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
else
|
265
|
-
[]
|
266
|
-
end
|
267
|
-
}.values.flatten
|
284
|
+
find_resource_nodes(node).map { |n|
|
285
|
+
resource = code.call(n, parent_resource)
|
286
|
+
[resource] + traverse_resources(n, resource, &code)
|
287
|
+
}.flatten
|
268
288
|
end
|
269
289
|
end
|
270
290
|
end
|
data/lib/raml_parser/model.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module RamlParser
|
2
2
|
module Model
|
3
3
|
class Root
|
4
|
-
attr_accessor :title, :base_uri, :version, :media_type, :security_schemes, :resource_types, :traits, :secured_by, :documentation, :resources
|
4
|
+
attr_accessor :title, :base_uri, :version, :media_type, :schemas, :security_schemes, :base_uri_parameters, :resource_types, :traits, :secured_by, :documentation, :resources
|
5
5
|
|
6
|
-
def initialize(title = nil, base_uri = nil, version = nil, media_type = nil, security_schemes = {}, resource_types = {}, traits = {}, secured_by = [], documentation = [], resources = [])
|
6
|
+
def initialize(title = nil, base_uri = nil, version = nil, media_type = nil, schemas = {}, security_schemes = {}, base_uri_parameters = {}, resource_types = {}, traits = {}, secured_by = [], documentation = [], resources = [])
|
7
7
|
@title = title
|
8
8
|
@base_uri = base_uri
|
9
9
|
@version = version
|
10
10
|
@media_type = media_type
|
11
|
+
@schemas = schemas
|
11
12
|
@security_schemes = security_schemes
|
13
|
+
@base_uri_parameters = base_uri_parameters
|
12
14
|
@resource_types = resource_types
|
13
15
|
@traits = traits
|
14
16
|
@secured_by = secured_by
|
@@ -18,13 +20,14 @@ module RamlParser
|
|
18
20
|
end
|
19
21
|
|
20
22
|
class Resource
|
21
|
-
attr_accessor :absolute_uri, :relative_uri, :display_name, :description, :uri_parameters, :methods, :type, :is, :secured_by
|
23
|
+
attr_accessor :absolute_uri, :relative_uri, :display_name, :description, :base_uri_parameters, :uri_parameters, :methods, :type, :is, :secured_by
|
22
24
|
|
23
|
-
def initialize(absolute_uri, relative_uri, display_name = nil, description = nil, uri_parameters = {}, methods = {}, type = {}, is = {}, secured_by = [])
|
25
|
+
def initialize(absolute_uri, relative_uri, display_name = nil, description = nil, base_uri_parameters = {}, uri_parameters = {}, methods = {}, type = {}, is = {}, secured_by = [])
|
24
26
|
@absolute_uri = absolute_uri
|
25
27
|
@relative_uri = relative_uri
|
26
28
|
@display_name = display_name
|
27
29
|
@description = description
|
30
|
+
@base_uri_parameters = base_uri_parameters
|
28
31
|
@uri_parameters = uri_parameters
|
29
32
|
@methods = methods
|
30
33
|
@type = type
|
@@ -37,6 +40,7 @@ module RamlParser
|
|
37
40
|
|
38
41
|
resource.display_name = if b.display_name then b.display_name else a.display_name end
|
39
42
|
resource.description = if b.description then b.description else a.description end
|
43
|
+
resource.base_uri_parameters = a.base_uri_parameters.merge(b.base_uri_parameters)
|
40
44
|
resource.uri_parameters = a.uri_parameters.merge(b.uri_parameters)
|
41
45
|
resource.methods = a.methods.merge(b.methods)
|
42
46
|
resource.type = a.type.merge(b.type)
|
data/lib/raml_parser/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
#%RAML 0.8
|
2
|
+
---
|
3
|
+
title: Example API
|
4
|
+
baseUri: http://{user}.domain.com/{version}/{language}
|
5
|
+
version: v1
|
6
|
+
baseUriParameters:
|
7
|
+
user:
|
8
|
+
description: The user
|
9
|
+
/a:
|
10
|
+
/b/{next}:
|
11
|
+
uriParameters:
|
12
|
+
next:
|
13
|
+
/c:
|
14
|
+
baseUriParameters:
|
15
|
+
user:
|
16
|
+
description: Changed
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#%RAML 0.8
|
2
|
+
---
|
3
|
+
title: Example API
|
4
|
+
baseUri: http://localhost:3000
|
5
|
+
schemas:
|
6
|
+
- schema1: |
|
7
|
+
<?xml version="1.1"?>
|
8
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
9
|
+
<xs:element name="note">
|
10
|
+
<xs:complexType>
|
11
|
+
<xs:sequence>
|
12
|
+
<xs:element name="to" type="xs:string"/>
|
13
|
+
</xs:sequence>
|
14
|
+
</xs:complexType>
|
15
|
+
</xs:element>
|
16
|
+
</xs:schema>
|
17
|
+
- schema2: |
|
18
|
+
<?xml version="1.2"?>
|
19
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
20
|
+
<xs:element name="note">
|
21
|
+
<xs:complexType>
|
22
|
+
<xs:sequence>
|
23
|
+
<xs:element name="from" type="xs:string"/>
|
24
|
+
</xs:sequence>
|
25
|
+
</xs:complexType>
|
26
|
+
</xs:element>
|
27
|
+
</xs:schema>
|
28
|
+
/route:
|
29
|
+
get:
|
30
|
+
body:
|
31
|
+
text/xml:
|
32
|
+
schema: schema1
|
33
|
+
post:
|
34
|
+
body:
|
35
|
+
text/xml:
|
36
|
+
schema: schema2
|
37
|
+
put:
|
38
|
+
body:
|
39
|
+
text/xml:
|
40
|
+
schema: |
|
41
|
+
<?xml version="1.3"?>
|
@@ -25,7 +25,7 @@ RSpec.describe RamlParser::Parser do
|
|
25
25
|
raml = RamlParser::Parser.parse_file('spec/examples/raml/uriparameters.raml')
|
26
26
|
expect(raml.resources[0].uri_parameters.map { |_,param| param.name }).to eq []
|
27
27
|
expect(raml.resources[1].uri_parameters.map { |_,param| param.name }).to eq ['first']
|
28
|
-
expect(raml.resources[2].uri_parameters.map { |_,param| param.name }).to eq ['
|
28
|
+
expect(raml.resources[2].uri_parameters.map { |_,param| param.name }).to eq ['first', 'second']
|
29
29
|
expect(raml.resources[3].uri_parameters.map { |_,param| param.name }).to eq ['third']
|
30
30
|
expect(raml.resources[2].uri_parameters['first'].display_name).to eq 'first'
|
31
31
|
expect(raml.resources[2].uri_parameters['first'].type).to eq 'string'
|
@@ -89,6 +89,9 @@ RSpec.describe RamlParser::Parser do
|
|
89
89
|
expect(raml.security_schemes['oauth_2_0'].type).to eq 'OAuth 2.0'
|
90
90
|
expect(raml.security_schemes['oauth_1_0'].type).to eq 'OAuth 1.0'
|
91
91
|
expect(raml.security_schemes['customHeader'].type).to eq nil
|
92
|
+
|
93
|
+
expect(raml.security_schemes['oauth_2_0'].settings['authorizationUri']).to eq 'https://www.dropbox.com/1/oauth2/authorize'
|
94
|
+
expect(raml.security_schemes['oauth_2_0'].described_by.headers['Authorization'].description).to start_with 'Used to send'
|
92
95
|
end
|
93
96
|
|
94
97
|
it 'parses documentation' do
|
@@ -97,6 +100,33 @@ RSpec.describe RamlParser::Parser do
|
|
97
100
|
expect(raml.documentation[1].title).to eq 'FAQ'
|
98
101
|
end
|
99
102
|
|
103
|
+
it 'parses schemas' do
|
104
|
+
raml = RamlParser::Parser.parse_file('spec/examples/raml/schemas.raml')
|
105
|
+
expect(raml.schemas['schema1']).to start_with '<?xml version="1.1"?>'
|
106
|
+
expect(raml.schemas['schema2']).to start_with '<?xml version="1.2"?>'
|
107
|
+
expect(raml.resources[0].methods['get'].bodies['text/xml'].schema).to start_with '<?xml version="1.1"?>'
|
108
|
+
expect(raml.resources[0].methods['post'].bodies['text/xml'].schema).to start_with '<?xml version="1.2"?>'
|
109
|
+
expect(raml.resources[0].methods['put'].bodies['text/xml'].schema).to start_with '<?xml version="1.3"?>'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'parses base URI parameters' do
|
113
|
+
raml1 = RamlParser::Parser.parse_file('spec/examples/raml/baseuriparameters1.raml')
|
114
|
+
expect(raml1.resources[0].absolute_uri).to eq 'http://localhost:3000/v4/a'
|
115
|
+
expect(raml1.base_uri_parameters).to eq ({})
|
116
|
+
|
117
|
+
raml2 = RamlParser::Parser.parse_file('spec/examples/raml/baseuriparameters2.raml')
|
118
|
+
expect(raml2.base_uri_parameters.map { |_,p| p.name }).to eq ['user', 'language']
|
119
|
+
expect(raml2.resources[0].uri_parameters.map { |_,p| p.name }).to eq []
|
120
|
+
expect(raml2.resources[0].base_uri_parameters.map { |_,p| p.name }).to eq ['user', 'language']
|
121
|
+
expect(raml2.resources[1].uri_parameters.map { |_,p| p.name }).to eq ['next']
|
122
|
+
expect(raml2.resources[1].base_uri_parameters.map { |_,p| p.name }).to eq ['user', 'language']
|
123
|
+
expect(raml2.resources[2].uri_parameters.map { |_,p| p.name }).to eq ['next']
|
124
|
+
expect(raml2.resources[2].base_uri_parameters.map { |_,p| p.name }).to eq ['user', 'language']
|
125
|
+
expect(raml2.resources[0].base_uri_parameters['user'].description).to eq 'The user'
|
126
|
+
expect(raml2.resources[1].base_uri_parameters['user'].description).to eq 'The user'
|
127
|
+
expect(raml2.resources[2].base_uri_parameters['user'].description).to eq 'Changed'
|
128
|
+
end
|
129
|
+
|
100
130
|
it 'handle secured by' do
|
101
131
|
raml1 = RamlParser::Parser.parse_file('spec/examples/raml/securedby1.raml')
|
102
132
|
expect(raml1.resources[0].methods['get'].secured_by).to eq ['oauth_1_0']
|
@@ -180,17 +210,18 @@ RSpec.describe RamlParser::Parser do
|
|
180
210
|
it 'does not fail on any example RAML file' do
|
181
211
|
files = Dir.glob('spec/examples/raml/**/*.raml')
|
182
212
|
files.each { |f|
|
183
|
-
known_unused = %w()
|
184
|
-
known_unsupported = %w(root.schemas .describedBy .someMultipartFormParamWithMultipleTypes)
|
185
|
-
|
186
213
|
result = RamlParser::Parser.parse_file_with_marks(f)
|
187
|
-
unused = result[:marks].select { |_,m| m == :unused }
|
188
|
-
unsupported = result[:marks].select { |_,m| m == :unsupported }
|
189
|
-
unknown = result[:marks].select { |_,m| not [:used, :unused, :unsupported].include? m }
|
190
214
|
|
191
|
-
expect(
|
192
|
-
|
193
|
-
|
215
|
+
expect(result[:marks]).to all(satisfy do |p,m|
|
216
|
+
m == :used or m == :unsupported
|
217
|
+
end)
|
218
|
+
}
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'fail on any bad example RAML file' do
|
222
|
+
files = Dir.glob('spec/examples/raml_bad/**/*.raml')
|
223
|
+
files.each { |f|
|
224
|
+
expect { RamlParser::Parser.parse_file_with_marks(f) }.to raise_error
|
194
225
|
}
|
195
226
|
end
|
196
227
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raml_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Hoffmeister
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- lib/raml_parser/version.rb
|
87
87
|
- lib/raml_parser/yaml_helper.rb
|
88
88
|
- raml_parser.gemspec
|
89
|
+
- spec/examples/raml/baseuriparameters1.raml
|
90
|
+
- spec/examples/raml/baseuriparameters2.raml
|
89
91
|
- spec/examples/raml/documentation.raml
|
90
92
|
- spec/examples/raml/external/box.raml
|
91
93
|
- spec/examples/raml/external/bug.raml
|
@@ -131,12 +133,14 @@ files:
|
|
131
133
|
- spec/examples/raml/resources.raml
|
132
134
|
- spec/examples/raml/resourcetypes.raml
|
133
135
|
- spec/examples/raml/responses.raml
|
136
|
+
- spec/examples/raml/schemas.raml
|
134
137
|
- spec/examples/raml/securedby1.raml
|
135
138
|
- spec/examples/raml/securedby2.raml
|
136
139
|
- spec/examples/raml/securityschemes.raml
|
137
140
|
- spec/examples/raml/simple.raml
|
138
141
|
- spec/examples/raml/traits.raml
|
139
142
|
- spec/examples/raml/uriparameters.raml
|
143
|
+
- spec/examples/raml_bad/uriparameters.raml
|
140
144
|
- spec/examples/yaml/include1.yml
|
141
145
|
- spec/examples/yaml/include2.yml
|
142
146
|
- spec/examples/yaml/simple.yml
|
@@ -169,6 +173,8 @@ signing_key:
|
|
169
173
|
specification_version: 4
|
170
174
|
summary: A parser for the RAML API modeling language.
|
171
175
|
test_files:
|
176
|
+
- spec/examples/raml/baseuriparameters1.raml
|
177
|
+
- spec/examples/raml/baseuriparameters2.raml
|
172
178
|
- spec/examples/raml/documentation.raml
|
173
179
|
- spec/examples/raml/external/box.raml
|
174
180
|
- spec/examples/raml/external/bug.raml
|
@@ -214,12 +220,14 @@ test_files:
|
|
214
220
|
- spec/examples/raml/resources.raml
|
215
221
|
- spec/examples/raml/resourcetypes.raml
|
216
222
|
- spec/examples/raml/responses.raml
|
223
|
+
- spec/examples/raml/schemas.raml
|
217
224
|
- spec/examples/raml/securedby1.raml
|
218
225
|
- spec/examples/raml/securedby2.raml
|
219
226
|
- spec/examples/raml/securityschemes.raml
|
220
227
|
- spec/examples/raml/simple.raml
|
221
228
|
- spec/examples/raml/traits.raml
|
222
229
|
- spec/examples/raml/uriparameters.raml
|
230
|
+
- spec/examples/raml_bad/uriparameters.raml
|
223
231
|
- spec/examples/yaml/include1.yml
|
224
232
|
- spec/examples/yaml/include2.yml
|
225
233
|
- spec/examples/yaml/simple.yml
|