brujula 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 728af83883cc6088ff24fc157a824221a04668fe
4
- data.tar.gz: bb27ac407bb64ef0840073ad168cc1abb30e0184
3
+ metadata.gz: 4432f8e3a02056bf3d4699197c82e6036168af26
4
+ data.tar.gz: 973ed2b40689295a17239237cdfc37b099919688
5
5
  SHA512:
6
- metadata.gz: 146647cbd16918d460e3c036b8c886940488fddf4bc6cd9e2edddad732bc61612320fd925fe5c103eb4505b5103ebba629e753cd419d3d524d07d014a631b225
7
- data.tar.gz: c531af198a63ffbeb311213b7cdb12c9e494b3332e5f8adefc1a158c91e056b6717b866c7fcf29a700f2b8cde6a359099de9e263934de249f53d48da1d3a6ac5
6
+ metadata.gz: d08750f73c2ac6f611b001be7b38a34b5da31ddd18d95f47bcecf05147863ca01315329929da65465fc02c4422f7f29183710a72115446999218b3b9fe843547
7
+ data.tar.gz: 04c58c3ef43821a9050139c0652d642e9cb11efd854a6a27248fd400931658021cceb6868428f3c2586dc036d3f88f95197a71bc41a6ca651acabc970fe43432
@@ -31,6 +31,36 @@ securedBy? | :warning: | Definition and merging support. Not fully tested though
31
31
 
32
32
  * [Raml Data Types](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#raml-data-types)
33
33
 
34
+ Property | Status | Comments
35
+ ---|---|---
36
+ schema? | :white_check_mark: :warning: | Show deprecation notice when using RAML 1.0
37
+ type? | :white_check_mark: :warning: | Some inheritance and merging strategies might not work
38
+ example? | :white_check_mark: :warning: | Should complain if both example and examples are present
39
+ examples? | :white_check_mark: :warning: | Should complain if both example and examples are present
40
+ displayName? | :white_check_mark: |
41
+ description? | :white_check_mark: |
42
+ (<annotationName>)? | :x: |
43
+
44
+ * [Object Data Types](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#object-types)
45
+
46
+
47
+ Property | Status | Comments
48
+ ---|---|---
49
+ properties? | :white_check_mark: :warning: | Some property limitations. See properties
50
+ minProperties? | :warning: | Not fully tested. Need examples
51
+ maxProperties? | :warning: | Not fully tested. Need examples
52
+ additionalProperties? | :warning: | Declaration works. Not fully tested
53
+ patternProperties? | :warning: | Declaration works. Not fully tested
54
+ discriminator? | :x: |
55
+
56
+ Extra Feature | Status
57
+ ---|--
58
+ [Alternative Syntax](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#alternative-syntax) | :white_check_mark:
59
+ [Inheritance](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#inheritance) | :warning: See inheritance
60
+ [Map types](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#map-types) | :x:
61
+
62
+ * [Array Types](https://github.com/raml-org/raml-spec/blob/raml-10/versions/raml-10/raml-10.md/#array-types)
63
+
34
64
  _TBC_
35
65
 
36
66
  * [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)
@@ -34,6 +34,7 @@ require_relative 'brujula/mergers/map_object_merger'
34
34
  require_relative 'brujula/type_extender/resource'
35
35
  require_relative 'brujula/type_extender/resource_type'
36
36
  require_relative 'brujula/type_extender/method'
37
+ require_relative 'brujula/type_extender/raml_type'
37
38
 
38
39
  # Definitions
39
40
  require_relative 'brujula/raml/definition'
@@ -17,7 +17,9 @@ module Brujula
17
17
  def call
18
18
  data.each_with_object({}) do |(key, property), object|
19
19
  if property.is_a?(String) # data as type
20
- object.merge!(key => { "type" => property })
20
+ object.merge!(key.gsub(/\?$/, "") => {
21
+ "type" => property, "required" => !key.to_s.end_with?("?")
22
+ })
21
23
  else
22
24
  object.merge!(key => property)
23
25
  end
@@ -70,6 +70,8 @@ module Brujula
70
70
  Brujula::TypeExtender::Method.new(definition: child).call
71
71
  when Brujula::Raml::V1_0::ResourceType
72
72
  Brujula::TypeExtender::ResourceType.new(definition: child).call
73
+ when Brujula::Raml::V1_0::RamlType
74
+ Brujula::TypeExtender::RamlType.new(definition: child).call
73
75
  else
74
76
  child
75
77
  end
@@ -33,12 +33,22 @@ module Brujula
33
33
  end
34
34
 
35
35
  def normalized_data
36
+ @normalized_data ||= apply_default_type(node_data)
37
+ end
38
+
39
+ def node_data
36
40
  return data unless external_data?
37
41
 
38
- # TODO
39
42
  data.load_external_data(definition.root.base_dir)
40
43
  end
41
44
 
45
+ def apply_default_type(data)
46
+ return data unless scheme.typed?
47
+ return data if data.key?("type")
48
+
49
+ data.merge("type" => scheme.default_type.to_s)
50
+ end
51
+
42
52
  def external_data?
43
53
  data.is_a?(Brujula::YamlInclude)
44
54
  end
@@ -47,15 +57,10 @@ module Brujula
47
57
  @scheme ||= definition.class.scheme
48
58
  end
49
59
 
50
- # Typed schemas must provide a type
51
- def data_type
52
- normalized_data.fetch('type', scheme.default_type)
53
- end
54
-
55
60
  def scheme_keys
56
61
  return scheme.key_collection unless scheme.typed?
57
62
 
58
- scheme.typed_keys(data_type)
63
+ scheme.typed_keys(normalized_data.fetch('type'))
59
64
  end
60
65
 
61
66
  def object_builder(key)
@@ -2,5 +2,6 @@ module Brujula
2
2
  module Raml
3
3
  class RequiredProperty < StandardError; end
4
4
  class ObjectTypeNotFound < StandardError; end
5
+ class InvalidTypeReference < KeyError; end
5
6
  end
6
7
  end
@@ -17,15 +17,15 @@ module Brujula
17
17
  key :enum, as: :array, unless_type_is: %w( file )
18
18
 
19
19
  # When Property is integer
20
- key :minimum, as: :number, for_types: %( number integer )
21
- key :maximum, as: :number, for_types: %( number integer )
20
+ key :minimum, as: :number, for_types: %w( number integer )
21
+ key :maximum, as: :number, for_types: %w( number integer )
22
22
  key :format, as: :string,
23
- in: %( int32 int64 int long float double int16 int8 )
23
+ in: %w( int32 int64 int long float double int16 int8 )
24
24
 
25
25
  # When Property is string
26
- key :pattern, as: :regexp, for_types: %( string )
27
- key :min_length, as: :number, for_types: %( string )
28
- key :max_length, as: :number, for_types: %( string )
26
+ key :pattern, as: :regexp, for_types: %w( string )
27
+ key :min_length, as: :number, for_types: %w( string )
28
+ key :max_length, as: :number, for_types: %w( string )
29
29
 
30
30
  end
31
31
  end
@@ -3,7 +3,7 @@ module Brujula
3
3
  module V1_0
4
4
  class RamlType < Brujula::Object
5
5
  scheme typed: true, default_type: :object do
6
- key :type, as: :string
6
+ key :type, as: :any
7
7
  key :schema, as: :string, deprecated: true
8
8
 
9
9
  key :properties, as: :map_object, children: :property,
@@ -17,15 +17,15 @@ module Brujula
17
17
  key :examples, as: :any
18
18
 
19
19
  # When Property is integer
20
- key :minimum, as: :number, for_types: %( number integer )
21
- key :maximum, as: :number, for_types: %( number integer )
20
+ key :minimum, as: :number, for_types: %w( number integer )
21
+ key :maximum, as: :number, for_types: %w( number integer )
22
22
  key :format, as: :string,
23
- in: %( int32 int64 int long float double int16 int8 )
23
+ in: %w( int32 int64 int long float double int16 int8 )
24
24
 
25
25
  # When Property is string
26
- key :pattern, as: :regexp, for_types: %( string )
27
- key :min_length, as: :number, for_types: %( string )
28
- key :max_length, as: :number, for_types: %( string )
26
+ key :pattern, as: :regexp, for_types: %w( string )
27
+ key :min_length, as: :number, for_types: %w( string )
28
+ key :max_length, as: :number, for_types: %w( string )
29
29
 
30
30
 
31
31
  # include_type_keys
@@ -1,10 +1,8 @@
1
1
  module Brujula
2
2
  class Scheme
3
- attr_reader :keys, :typed, :default_type, :reference,
4
- :store_for_reference, :allow_any
3
+ attr_reader :keys, :typed, :default_type, :reference, :allow_any
5
4
 
6
5
  alias :typed? :typed
7
- alias :store_object_for_reference? :store_for_reference
8
6
  alias :allow_any? :allow_any
9
7
 
10
8
  def initialize(klass, options = {}, block = nil)
@@ -13,7 +11,6 @@ module Brujula
13
11
  @keys = {}
14
12
  @typed = !!options[:typed]
15
13
  @default_type = options[:default_type] || :string
16
- @store_for_reference = !!options[:store_for_reference]
17
14
  @allow_any = !!options[:allow_any]
18
15
 
19
16
  if options[:as]
@@ -33,7 +30,7 @@ module Brujula
33
30
  valid_keys?(data) || raise(Brujula::Raml::RequiredProperty) # && enough_data?(data))
34
31
  end
35
32
 
36
- def typed_keys(type)
33
+ def typed_keys(type) # TODO
37
34
  keys.values.select do |brujula_key|
38
35
  brujula_key.valid_for_type?(type)
39
36
  end
@@ -0,0 +1,60 @@
1
+ module Brujula
2
+ module TypeExtender
3
+ class RamlType
4
+
5
+ RAML_TYPES = %w( object number string integer boolean date file array )
6
+
7
+ attr_reader :definition
8
+
9
+ def initialize(definition:)
10
+ @definition = definition
11
+ end
12
+
13
+ def call
14
+ return definition unless custom_type?
15
+
16
+ expand_object
17
+ end
18
+
19
+ private
20
+
21
+ def expand_object
22
+ superinstances.inject(definition) do |instance, superinstance|
23
+ Brujula::Mergers::ObjectMerger.new(
24
+ superinstance: superinstance, instance: instance
25
+ ).call
26
+ end
27
+ end
28
+
29
+ def superinstances
30
+ case definition.type
31
+ when Array
32
+ definition.type.map { |type| get_reference(type) }
33
+ when String
34
+ [ get_reference(definition.type) ]
35
+ else
36
+ raise_invalid_reference(definition.type)
37
+ end
38
+ end
39
+
40
+ def raise_invalid_reference(reference)
41
+ raise Brujula::Raml::InvalidTypeReference,
42
+ "The referenced type #{ reference } cannot be processed"
43
+ end
44
+
45
+ def custom_type?
46
+ ! RAML_TYPES.include?(definition.type)
47
+ end
48
+
49
+ def get_reference(reference)
50
+ if definition.parent.name == "types" # root types, not preloaded
51
+ definition.parent.fetch(reference)
52
+ else
53
+ definition.root.types.fetch(reference)
54
+ end
55
+ rescue KeyError
56
+ raise_invalid_reference(reference)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module Brujula
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brujula
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Tapiador
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-27 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto
@@ -197,6 +197,7 @@ files:
197
197
  - lib/brujula/scheme.rb
198
198
  - lib/brujula/transformer_functions.rb
199
199
  - lib/brujula/type_extender/method.rb
200
+ - lib/brujula/type_extender/raml_type.rb
200
201
  - lib/brujula/type_extender/resource.rb
201
202
  - lib/brujula/type_extender/resource_type.rb
202
203
  - lib/brujula/version.rb