brujula 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +9 -0
  3. data/Gemfile +5 -0
  4. data/README.md +64 -0
  5. data/Rakefile +21 -0
  6. data/SPEC_SUPPORT.md +183 -0
  7. data/TODO.md +1 -0
  8. data/lib/brujula.rb +71 -0
  9. data/lib/brujula/basic_type.rb +46 -0
  10. data/lib/brujula/data_transformers/body_declaration.rb +39 -0
  11. data/lib/brujula/data_transformers/property_declaration.rb +28 -0
  12. data/lib/brujula/data_transformers/security_scheme_settings_declaration.rb +23 -0
  13. data/lib/brujula/initializers/inflecto_ramelize.rb +9 -0
  14. data/lib/brujula/initializers/yaml_include.rb +42 -0
  15. data/lib/brujula/key.rb +45 -0
  16. data/lib/brujula/map_object.rb +99 -0
  17. data/lib/brujula/mergers/map_object_merger.rb +78 -0
  18. data/lib/brujula/mergers/merger.rb +27 -0
  19. data/lib/brujula/mergers/object_merger.rb +41 -0
  20. data/lib/brujula/object.rb +40 -0
  21. data/lib/brujula/object_builder.rb +114 -0
  22. data/lib/brujula/object_parser.rb +65 -0
  23. data/lib/brujula/raml.rb +5 -0
  24. data/lib/brujula/raml/definition.rb +45 -0
  25. data/lib/brujula/raml/exceptions.rb +6 -0
  26. data/lib/brujula/raml/v1_0/array.rb +8 -0
  27. data/lib/brujula/raml/v1_0/base_uri_parameters.rb +9 -0
  28. data/lib/brujula/raml/v1_0/body.rb +9 -0
  29. data/lib/brujula/raml/v1_0/body_type.rb +9 -0
  30. data/lib/brujula/raml/v1_0/header.rb +9 -0
  31. data/lib/brujula/raml/v1_0/markdown.rb +8 -0
  32. data/lib/brujula/raml/v1_0/media_type.rb +8 -0
  33. data/lib/brujula/raml/v1_0/method.rb +22 -0
  34. data/lib/brujula/raml/v1_0/null_security_scheme.rb +8 -0
  35. data/lib/brujula/raml/v1_0/property.rb +34 -0
  36. data/lib/brujula/raml/v1_0/query_parameter.rb +9 -0
  37. data/lib/brujula/raml/v1_0/raml_type.rb +37 -0
  38. data/lib/brujula/raml/v1_0/resource.rb +19 -0
  39. data/lib/brujula/raml/v1_0/resource_type.rb +15 -0
  40. data/lib/brujula/raml/v1_0/response.rb +16 -0
  41. data/lib/brujula/raml/v1_0/root.rb +30 -0
  42. data/lib/brujula/raml/v1_0/security_scheme.rb +15 -0
  43. data/lib/brujula/raml/v1_0/security_scheme_part.rb +18 -0
  44. data/lib/brujula/raml/v1_0/security_scheme_settings.rb +24 -0
  45. data/lib/brujula/raml/v1_0/string.rb +8 -0
  46. data/lib/brujula/raml/v1_0/trait.rb +17 -0
  47. data/lib/brujula/raml/v1_0/uri_parameter.rb +9 -0
  48. data/lib/brujula/raml/v1_0/uri_template.rb +8 -0
  49. data/lib/brujula/scheme.rb +77 -0
  50. data/lib/brujula/type_extender/method.rb +29 -0
  51. data/lib/brujula/type_extender/resource.rb +52 -0
  52. data/lib/brujula/type_extender/resource_type.rb +36 -0
  53. data/lib/brujula/version.rb +3 -0
  54. data/lib/brujula/yaml_parser.rb +67 -0
  55. metadata +224 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 627bde01017a2c5a99bb77c5888f7658675204c5
4
+ data.tar.gz: 09b0aa8cd8ef8373365e39215c72ac2caadaee6b
5
+ SHA512:
6
+ metadata.gz: 56b5d1e7b3f629efc13cd78921795dd1d0ffd30383b42d209b62258453a12ba1c708662f6853196d9bbe7be6ae6e301b41f5f256fe57d85e6870f68a99ec690e
7
+ data.tar.gz: 3ab91bd63e736f10fae5fdd6e5c116dd177cf56a9a270c1b3e2da214f517b3a338db8adbd2f4ff09901d8926650eb4b1bb47d62a9b5e8f59997d3bb208132dab
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Contributing
2
+
3
+ _TBC with more information. But for now, you know how this works_
4
+
5
+ 1. Fork it
6
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
7
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
8
+ 4. Push to the branch (`git push origin my-new-feature`)
9
+ 5. Create new Pull Request
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ Brújula
2
+ ========
3
+
4
+ [![Build Status](https://travis-ci.org/nogates/brujula.svg?branch=master)](https://travis-ci.org/nogates/brujula)
5
+ [![Code Climate](https://codeclimate.com/github/nogates/brujula/badges/gpa.svg)](https://codeclimate.com/github/nogates/brujula)
6
+ [![Test Coverage](https://codeclimate.com/github/nogates/brujula/badges/coverage.svg)](https://codeclimate.com/github/nogates/brujula)
7
+
8
+ _Yet another Ruby RAML parser aiming for version 1.0 fully support_
9
+
10
+ # Status
11
+
12
+ Brujula is still under development and not the full RAML specification is covered. Please see `SPEC_SUPPORT.md` for more information.
13
+
14
+ # Use
15
+
16
+ Install the gem `brujula` via your preferred method, and use `parse_file` to load and parse any RAML file
17
+
18
+ ```ruby
19
+ require 'brujula'
20
+
21
+ root = Brujula.parse_file('path/my_example_api.raml')
22
+
23
+ # Alternatively
24
+
25
+ raml = <<-RAML
26
+ # version 1.0
27
+ title: 'My example API'
28
+ /examples:
29
+ get:
30
+
31
+ RAML
32
+
33
+ root = Brujula.parse(raml)
34
+ ```
35
+
36
+ As expected, the properties of the root object can be accessed from the root object
37
+
38
+ ```ruby
39
+ root.title
40
+ => 'My example API'
41
+ ```
42
+
43
+ Object collections, such as Resources, Methods or Security Schemes, inherits from `Brujula::MapObject`, which implements the `Enumerable` module. Thus, you can use any of this module's method to get collection objects.
44
+
45
+ ```ruby
46
+ root.resources.each_with_object([]) do |resource, resource_names|
47
+ resource_names << resource.name
48
+ end
49
+ ```
50
+
51
+ Alternatively, you can you use hash methods such as `[]` or `fetch` to get specific objects by its key name
52
+
53
+ ```ruby
54
+ root.resources['/examples']
55
+ ```
56
+
57
+
58
+ ## Contributing
59
+
60
+ Pull request are kindly requested. Specially in the form of RAML examples. If you are using some advances features of RAML 1.0 spec, like annotations, type inheritance or libraries, and you would like to help this project, please have a look at `CONTRIBUTING.md`.
61
+
62
+ ## License
63
+
64
+ See [LICENSE](https://raw.githubusercontent.com/lonelyplanet/brujula/master/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:cucumber) do |t|
6
+ t.cucumber_opts = '--tags ~@wip'
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ # desc 'Clear tmp folders'
12
+ # task :clobber do
13
+ # FileUtils.rm_rf(File.join(__dir__, 'coverage'))
14
+ # end
15
+
16
+ # Not sure why simplecov is preventing cucumber for being run after spec
17
+ # when running rake default. That is why I am using commands to execute them
18
+ task :default do
19
+ raise 'Cucumber Failed' unless system('bundle exec rake cucumber')
20
+ raise 'RSpec Failed' unless system('bundle exec rake spec')
21
+ end
data/SPEC_SUPPORT.md ADDED
@@ -0,0 +1,183 @@
1
+ # Raml 1.0 (rc2) Specification support
2
+
3
+ :white_check_mark: The feature should work as expected
4
+
5
+ :warning: The feature is not completed yet (see comments)
6
+
7
+ :x: The feature is not currently supported (PRs are welcome!)
8
+
9
+
10
+ - [Raml Root](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#the-root-of-the-document)
11
+
12
+ Property | Status | Comments
13
+ ---|---|---
14
+ description | :white_check_mark: |
15
+ (annotationName)? | :x: |
16
+ schemas? | :warning: | Basic support. See Types support
17
+ types? | :warning: | Basic support. See Types support
18
+ traits? | :white_check_mark: :warning: | Definition and merging support. Not fully tested though
19
+ resourceTypes? | :white_check_mark: :warning: | Definition and merging support. Not fully tested though
20
+ annotationTypes? | :x: |
21
+ securitySchemes? | :white_check_mark: :warning: | Definition and merging support. Not fully tested though
22
+ uses? | :x: |
23
+ title | :white_check_mark: |
24
+ version | :white_check_mark: |
25
+ baseUri? | :white_check_mark: |
26
+ baseUriParameters? | :white_check_mark: |
27
+ protocols? | :white_check_mark: |
28
+ mediaType? | :white_check_mark: |
29
+ securedBy? | :warning: | Definition and merging support. Not fully tested though
30
+ /resources? | :white_check_mark: |
31
+
32
+ * [Raml Data Types](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#raml-data-types)
33
+
34
+ _TBC_
35
+
36
+ * [Base URI and Base URI Parameters](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#base-uri-and-base-uri-parameters)
37
+
38
+ :white_check_mark: Parsing Base Uri and Base parameters as collection should works as expected
39
+
40
+ :warning: Template validation.
41
+
42
+ :warning: These two properties should be mutually exclusive.
43
+
44
+
45
+ * [Protocols](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#protocols)
46
+
47
+ :white_check_mark: Parsing protocols strings should work as expected
48
+
49
+ :warning: Any protocol is currently accepted as long as they are strings.
50
+
51
+ * [Default Media Type](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#default-media-type)
52
+
53
+
54
+ :white_check_mark: Parsing Media type and using it as default body key
55
+
56
+ :warning: Media type validation
57
+
58
+ * [Default Security](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#default-security)
59
+
60
+ :x: Although parsing security schemes is supported, applying their properties to the resources and methods is not yet implemented
61
+
62
+ * [Resources and Nested Resources](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#resources-and-nested-resources)
63
+
64
+
65
+ Property | Status | Comments
66
+ ---|---|---
67
+ displayName | :white_check_mark: |
68
+ description | :white_check_mark: |
69
+ (annotationName)? | :x: |
70
+ get? | :white_check_mark: |
71
+ patch? | :white_check_mark: |
72
+ put? | :white_check_mark: |
73
+ post? | :white_check_mark: |
74
+ delete? | :white_check_mark: |
75
+ options? | :white_check_mark: |
76
+ head? | :white_check_mark: |
77
+ is? | :white_check_mark: |
78
+ type? | :white_check_mark: |
79
+ securedBy? | :warning: | Merging of security scheme properties is not yet implemented
80
+ uriParameters? | :white_check_mark: |
81
+ /relativeUri as resource | :white_check_mark: |
82
+
83
+
84
+ * [Template URIs and URI Parameters](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#template-uris-and-uri-parameters)
85
+
86
+ :warning: Parsing Uri Strings and Uri parameters as collection should works as expected
87
+
88
+ :warning: Template validation.
89
+
90
+ :warning: These two properties should be mutually exclusive.
91
+
92
+ * [Methods](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#methods)
93
+
94
+
95
+ Property | Status | Comments
96
+ ---|---|---
97
+ displayName | :white_check_mark: |
98
+ description | :white_check_mark: |
99
+ (annotationName)? | :x: |
100
+ queryParameters? | :white_check_mark: |
101
+ headers? | :white_check_mark: |
102
+ queryString? | :white_check_mark: |
103
+ responses? | :white_check_mark: |
104
+ body? | :warning: | Same Type limitations
105
+ protocols? | :warning: | Protocols limitations
106
+ is? | :white_check_mark: |
107
+ securedBy? | :warning: | Merging of security scheme properties is not yet implemented
108
+
109
+ * [Headers](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#headers)
110
+
111
+ :white_check_mark: Parsing Headers as a properties declaration should work as expected
112
+
113
+ :warning: Needs more testing, specially using headers of array type
114
+
115
+
116
+ * [Query Strings and Query Parameters](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#query-strings-and-query-parameters)
117
+
118
+ :white_check_mark: Parsing Query Strings and Query parameters as collection should works as expected
119
+
120
+ :warning: Template validation.
121
+
122
+ :warning: These two properties should be mutually exclusive.
123
+
124
+
125
+ * [Bodies](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#bodies)
126
+
127
+ :white_check_mark: Body declarations using both strings (and therefore, default media type) and objects
128
+
129
+ :warning: Same limitations as Raml Types
130
+
131
+ * [Responses](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#responses)
132
+
133
+ :white_check_mark: Responses should work as expected
134
+
135
+
136
+ * [Resource Types and Traits](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#resource-types-and-traits)
137
+
138
+ Feature | status | comments
139
+ ---|---|---
140
+ Query Parameters, Responses, and Headers collection mergin | :white_check_mark: |
141
+ usage description | :white_check_mark: |
142
+ Optional properties (`/^?/`) | :warning: | Needs testing and real examples
143
+ Algorithm of Merging Traits With Methods | :warning: | Needs testing and real examples
144
+ Parameters (both custom and reserved parameters) | :x: |
145
+ Modifier functions | :x: |
146
+
147
+
148
+ * [Security Schemes](https://github.com/raml-org/raml-spec/blob/raml-10-rc2/versions/raml-10/raml-10.md#security-schemes)
149
+
150
+ Type | Status | Comments
151
+ ---|---|---
152
+ OAuth 1.0 | :white_check_mark: |
153
+ OAuth 2.0 | :white_check_mark: |
154
+ Basic Authentication | :white_check_mark: |
155
+ Digest Authentication | :white_check_mark: |
156
+ Pass Through| :white_check_mark: |
157
+ x-{other} | :white_check_mark: |
158
+ null | :white_check_mark: |
159
+
160
+
161
+ :warning: Merging security schemes is not yet implemented. :warning:
162
+
163
+
164
+ * [Annotations](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#annotations)
165
+
166
+ :x: Not even started yet :x:
167
+
168
+ * [Modularization](https://github.com/raml-org/raml-spec/blob/raml-10-rc2/versions/raml-10/raml-10.md#modularization)
169
+
170
+ Type | Status | Comments
171
+ ---|---|---
172
+ `!include <absolute or relative url>` as Type Fragments | :white_check_mark: |
173
+ `!include <absolute or relative url>#<reference>` as References to inner elements | :x: |
174
+
175
+
176
+ * [Libraries](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#libraries)
177
+
178
+
179
+ :x: Not even started yet :x:
180
+
181
+ * [Overlays and Extensions](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md#overlays-and-extensions)
182
+
183
+ :x: Not even started yet :x:
data/TODO.md ADDED
@@ -0,0 +1 @@
1
+ - Exclusion Between (BaseUri/Query)Parameters and (BaseUri/Query)String
data/lib/brujula.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'inflecto'
2
+ require 'pathname'
3
+
4
+ require_relative 'brujula/initializers/inflecto_ramelize'
5
+ require_relative 'brujula/initializers/yaml_include'
6
+
7
+ require_relative 'brujula/object_parser'
8
+ require_relative 'brujula/object_builder'
9
+ require_relative 'brujula/scheme'
10
+ require_relative 'brujula/raml'
11
+ require_relative 'brujula/object'
12
+ require_relative 'brujula/map_object'
13
+ require_relative 'brujula/key'
14
+ require_relative 'brujula/basic_type'
15
+ require_relative 'brujula/raml/exceptions'
16
+
17
+ # data transformers
18
+ require_relative 'brujula/data_transformers/property_declaration'
19
+ require_relative 'brujula/data_transformers/security_scheme_settings_declaration'
20
+ require_relative 'brujula/data_transformers/body_declaration'
21
+
22
+ # mergers
23
+ require_relative 'brujula/mergers/merger'
24
+ require_relative 'brujula/mergers/object_merger'
25
+ require_relative 'brujula/mergers/map_object_merger'
26
+
27
+ # extenders
28
+ require_relative 'brujula/type_extender/resource'
29
+ require_relative 'brujula/type_extender/resource_type'
30
+ require_relative 'brujula/type_extender/method'
31
+
32
+ # Definitions
33
+ require_relative 'brujula/raml/definition'
34
+
35
+ # Types
36
+ require_relative 'brujula/raml/v1_0/array'
37
+ require_relative 'brujula/raml/v1_0/string'
38
+ require_relative 'brujula/raml/v1_0/markdown'
39
+ require_relative 'brujula/raml/v1_0/media_type'
40
+ require_relative 'brujula/raml/v1_0/uri_template'
41
+
42
+ # Objects
43
+ require_relative 'brujula/raml/v1_0/raml_type'
44
+ require_relative 'brujula/raml/v1_0/body_type'
45
+ require_relative 'brujula/raml/v1_0/property'
46
+ require_relative 'brujula/raml/v1_0/trait'
47
+ require_relative 'brujula/raml/v1_0/root'
48
+ require_relative 'brujula/raml/v1_0/header'
49
+ require_relative 'brujula/raml/v1_0/method'
50
+ require_relative 'brujula/raml/v1_0/body'
51
+ require_relative 'brujula/raml/v1_0/response'
52
+ require_relative 'brujula/raml/v1_0/resource'
53
+ require_relative 'brujula/raml/v1_0/resource_type'
54
+ require_relative 'brujula/raml/v1_0/query_parameter'
55
+ require_relative 'brujula/raml/v1_0/uri_parameter'
56
+ require_relative 'brujula/raml/v1_0/security_scheme_part'
57
+ require_relative 'brujula/raml/v1_0/security_scheme_settings'
58
+ require_relative 'brujula/raml/v1_0/security_scheme'
59
+ require_relative 'brujula/raml/v1_0/null_security_scheme'
60
+
61
+ module Brujula
62
+ class << self
63
+ def parse_file(file_path)
64
+ Brujula::Raml::Definition.from_file(file_path)
65
+ end
66
+
67
+ def parse_string(string)
68
+ Brujula::Raml::Definition.from_string(string)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,46 @@
1
+ module Brujula
2
+ module BasicTypeMixin
3
+ attr_reader :parent, :name
4
+ end
5
+
6
+ class BasicType
7
+ attr_reader :data, :as, :parent, :name
8
+
9
+ def initialize(parent: nil, data:, name:, as:)
10
+ @parent = parent
11
+ @data = data
12
+ @name = name
13
+ @as = as
14
+ end
15
+
16
+ def expand
17
+ case as
18
+ when :boolean, :number, :any
19
+ data
20
+ else
21
+ base_class.new(normalized_data).tap do |instance|
22
+ instance.extend(BasicTypeMixin)
23
+ instance.define_singleton_method :parent do
24
+ instance_variable_get("@parent")
25
+ end
26
+ instance.instance_variable_set("@name", name)
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def base_class
34
+ Brujula::Raml::V1_0.const_get(Inflecto.camelize(as.to_s))
35
+ end
36
+
37
+ def normalized_data
38
+ case as
39
+ when :string
40
+ data.to_s
41
+ else
42
+ data
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require 'mime-types'
2
+
3
+ module Brujula
4
+ module DataTransformers
5
+ class BodyDeclaration
6
+ class << self
7
+ def call(*args)
8
+ new(*args).call
9
+ end
10
+ end
11
+
12
+ attr_reader :data, :parent
13
+
14
+ def initialize(parent, data)
15
+ @parent = parent
16
+ @data = data
17
+ end
18
+
19
+ def call
20
+ case
21
+ when keys_are_media_type?
22
+ data
23
+ else
24
+ { default_media_type => data }
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def keys_are_media_type?
31
+ data.keys.all? { |key| MIME::Types[key].any? }
32
+ end
33
+
34
+ def default_media_type
35
+ parent.root.media_type || raise('Default Media Type required')
36
+ end
37
+ end
38
+ end
39
+ end