jsapi 0.1.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.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jsapi/controller/base.rb +21 -0
  3. data/lib/jsapi/controller/error_result.rb +21 -0
  4. data/lib/jsapi/controller/methods.rb +144 -0
  5. data/lib/jsapi/controller/parameters.rb +86 -0
  6. data/lib/jsapi/controller/parameters_invalid.rb +25 -0
  7. data/lib/jsapi/controller/response.rb +84 -0
  8. data/lib/jsapi/controller.rb +13 -0
  9. data/lib/jsapi/dsl/callbacks.rb +32 -0
  10. data/lib/jsapi/dsl/class_methods.rb +85 -0
  11. data/lib/jsapi/dsl/definitions.rb +102 -0
  12. data/lib/jsapi/dsl/error.rb +38 -0
  13. data/lib/jsapi/dsl/examples.rb +30 -0
  14. data/lib/jsapi/dsl/node.rb +62 -0
  15. data/lib/jsapi/dsl/openapi/callback.rb +23 -0
  16. data/lib/jsapi/dsl/openapi/root.rb +12 -0
  17. data/lib/jsapi/dsl/openapi.rb +4 -0
  18. data/lib/jsapi/dsl/operation.rb +118 -0
  19. data/lib/jsapi/dsl/parameter.rb +10 -0
  20. data/lib/jsapi/dsl/request_body.rb +10 -0
  21. data/lib/jsapi/dsl/response.rb +33 -0
  22. data/lib/jsapi/dsl/schema.rb +87 -0
  23. data/lib/jsapi/dsl.rb +24 -0
  24. data/lib/jsapi/json/array.rb +35 -0
  25. data/lib/jsapi/json/boolean.rb +17 -0
  26. data/lib/jsapi/json/integer.rb +15 -0
  27. data/lib/jsapi/json/null.rb +27 -0
  28. data/lib/jsapi/json/number.rb +15 -0
  29. data/lib/jsapi/json/object.rb +53 -0
  30. data/lib/jsapi/json/string.rb +29 -0
  31. data/lib/jsapi/json/value.rb +47 -0
  32. data/lib/jsapi/json.rb +41 -0
  33. data/lib/jsapi/meta/attributes/class_methods.rb +112 -0
  34. data/lib/jsapi/meta/attributes/type_caster.rb +48 -0
  35. data/lib/jsapi/meta/attributes.rb +4 -0
  36. data/lib/jsapi/meta/base.rb +41 -0
  37. data/lib/jsapi/meta/base_reference.rb +33 -0
  38. data/lib/jsapi/meta/definitions.rb +226 -0
  39. data/lib/jsapi/meta/example/model.rb +44 -0
  40. data/lib/jsapi/meta/example/reference.rb +15 -0
  41. data/lib/jsapi/meta/example.rb +19 -0
  42. data/lib/jsapi/meta/existence.rb +69 -0
  43. data/lib/jsapi/meta/invalid_argument_error.rb +11 -0
  44. data/lib/jsapi/meta/openapi/callback/model.rb +36 -0
  45. data/lib/jsapi/meta/openapi/callback/reference.rb +16 -0
  46. data/lib/jsapi/meta/openapi/callback.rb +21 -0
  47. data/lib/jsapi/meta/openapi/contact.rb +34 -0
  48. data/lib/jsapi/meta/openapi/external_documentation.rb +28 -0
  49. data/lib/jsapi/meta/openapi/info.rb +52 -0
  50. data/lib/jsapi/meta/openapi/license.rb +28 -0
  51. data/lib/jsapi/meta/openapi/link/model.rb +48 -0
  52. data/lib/jsapi/meta/openapi/link/reference.rb +16 -0
  53. data/lib/jsapi/meta/openapi/link.rb +21 -0
  54. data/lib/jsapi/meta/openapi/oauth_flow.rb +50 -0
  55. data/lib/jsapi/meta/openapi/root.rb +134 -0
  56. data/lib/jsapi/meta/openapi/security_requirement.rb +27 -0
  57. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +38 -0
  58. data/lib/jsapi/meta/openapi/security_scheme/base.rb +16 -0
  59. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +31 -0
  60. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +37 -0
  61. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +37 -0
  62. data/lib/jsapi/meta/openapi/security_scheme/http.rb +31 -0
  63. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +47 -0
  64. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +33 -0
  65. data/lib/jsapi/meta/openapi/security_scheme.rb +51 -0
  66. data/lib/jsapi/meta/openapi/server.rb +34 -0
  67. data/lib/jsapi/meta/openapi/server_variable.rb +34 -0
  68. data/lib/jsapi/meta/openapi/tag.rb +34 -0
  69. data/lib/jsapi/meta/openapi/version.rb +41 -0
  70. data/lib/jsapi/meta/openapi.rb +16 -0
  71. data/lib/jsapi/meta/operation.rb +186 -0
  72. data/lib/jsapi/meta/parameter/model.rb +170 -0
  73. data/lib/jsapi/meta/parameter/reference.rb +30 -0
  74. data/lib/jsapi/meta/parameter.rb +19 -0
  75. data/lib/jsapi/meta/property.rb +62 -0
  76. data/lib/jsapi/meta/reference_error.rb +12 -0
  77. data/lib/jsapi/meta/request_body/model.rb +65 -0
  78. data/lib/jsapi/meta/request_body/reference.rb +14 -0
  79. data/lib/jsapi/meta/request_body.rb +19 -0
  80. data/lib/jsapi/meta/rescue_handler.rb +26 -0
  81. data/lib/jsapi/meta/response/model.rb +72 -0
  82. data/lib/jsapi/meta/response/reference.rb +17 -0
  83. data/lib/jsapi/meta/response.rb +19 -0
  84. data/lib/jsapi/meta/schema/array.rb +42 -0
  85. data/lib/jsapi/meta/schema/base.rb +146 -0
  86. data/lib/jsapi/meta/schema/boolean.rb +9 -0
  87. data/lib/jsapi/meta/schema/boundary.rb +37 -0
  88. data/lib/jsapi/meta/schema/conversion.rb +28 -0
  89. data/lib/jsapi/meta/schema/delegator.rb +26 -0
  90. data/lib/jsapi/meta/schema/discriminator.rb +36 -0
  91. data/lib/jsapi/meta/schema/integer.rb +9 -0
  92. data/lib/jsapi/meta/schema/number.rb +9 -0
  93. data/lib/jsapi/meta/schema/numeric.rb +56 -0
  94. data/lib/jsapi/meta/schema/object.rb +85 -0
  95. data/lib/jsapi/meta/schema/reference.rb +38 -0
  96. data/lib/jsapi/meta/schema/string.rb +58 -0
  97. data/lib/jsapi/meta/schema/validation/base.rb +29 -0
  98. data/lib/jsapi/meta/schema/validation/enum.rb +26 -0
  99. data/lib/jsapi/meta/schema/validation/max_items.rb +26 -0
  100. data/lib/jsapi/meta/schema/validation/max_length.rb +26 -0
  101. data/lib/jsapi/meta/schema/validation/maximum.rb +51 -0
  102. data/lib/jsapi/meta/schema/validation/min_items.rb +26 -0
  103. data/lib/jsapi/meta/schema/validation/min_length.rb +26 -0
  104. data/lib/jsapi/meta/schema/validation/minimum.rb +51 -0
  105. data/lib/jsapi/meta/schema/validation/multiple_of.rb +24 -0
  106. data/lib/jsapi/meta/schema/validation/pattern.rb +30 -0
  107. data/lib/jsapi/meta/schema/validation.rb +12 -0
  108. data/lib/jsapi/meta/schema.rb +61 -0
  109. data/lib/jsapi/meta.rb +23 -0
  110. data/lib/jsapi/model/attributes.rb +22 -0
  111. data/lib/jsapi/model/base.rb +34 -0
  112. data/lib/jsapi/model/error.rb +15 -0
  113. data/lib/jsapi/model/errors.rb +51 -0
  114. data/lib/jsapi/model/naming.rb +28 -0
  115. data/lib/jsapi/model/nestable.rb +37 -0
  116. data/lib/jsapi/model/nested_error.rb +54 -0
  117. data/lib/jsapi/model/validations.rb +27 -0
  118. data/lib/jsapi/model.rb +15 -0
  119. data/lib/jsapi/version.rb +8 -0
  120. data/lib/jsapi.rb +8 -0
  121. metadata +162 -0
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ class Numeric < Base
7
+ include Conversion
8
+
9
+ ##
10
+ # :attr: maximum
11
+ # The (exclusive) maximum.
12
+ attribute :maximum, writer: false
13
+
14
+ ##
15
+ # :attr: minimum
16
+ # The (exclusive) minimum.
17
+ attribute :minimum, writer: false
18
+
19
+ ##
20
+ # :attr: multiple_of
21
+ attribute :multiple_of, writer: false
22
+
23
+ def maximum=(value) # :nodoc:
24
+ boundary = Boundary.from(value)
25
+
26
+ add_validation(
27
+ 'maximum',
28
+ Validation::Maximum.new(
29
+ boundary.value,
30
+ exclusive: boundary.exclusive?
31
+ )
32
+ )
33
+ @maximum = boundary
34
+ end
35
+
36
+ def minimum=(value) # :nodoc:
37
+ boundary = Boundary.from(value)
38
+
39
+ add_validation(
40
+ 'minimum',
41
+ Validation::Minimum.new(
42
+ boundary.value,
43
+ exclusive: boundary.exclusive?
44
+ )
45
+ )
46
+ @minimum = boundary
47
+ end
48
+
49
+ def multiple_of=(value) # :nodoc:
50
+ add_validation('multiple_of', Validation::MultipleOf.new(value))
51
+ @multiple_of = value
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ class Object < Base
7
+ ##
8
+ # :attr: all_of_references
9
+ attribute :all_of_references, [Reference], default: []
10
+
11
+ alias :all_of= :all_of_references=
12
+ alias :add_all_of :add_all_of_reference
13
+
14
+ ##
15
+ # :attr: discriminator
16
+ attribute :discriminator, Discriminator
17
+
18
+ ##
19
+ # :attr: model
20
+ # The model class to access nested object parameters by. The default
21
+ # model class is Model::Base.
22
+ attribute :model, Class, default: Model::Base
23
+
24
+ ##
25
+ # :attr: properties
26
+ # The properties.
27
+ attribute :properties, { String => Property }, writer: false, default: {}
28
+
29
+ def add_property(name, keywords = {}) # :nodoc:
30
+ (@properties ||= {})[name.to_s] = Property.new(name, **keywords)
31
+ end
32
+
33
+ def resolve_properties(access, definitions)
34
+ properties = merge_properties(definitions, [])
35
+
36
+ case access
37
+ when :read
38
+ properties.reject { |_k, v| v.write_only? }
39
+ when :write
40
+ properties.reject { |_k, v| v.read_only? }
41
+ else
42
+ properties
43
+ end
44
+ end
45
+
46
+ def to_json_schema # :nodoc:
47
+ super.merge(
48
+ allOf: all_of_references.map(&:to_json_schema).presence,
49
+ properties: properties.transform_values(&:to_json_schema),
50
+ required: properties.values.select(&:required?).map(&:name)
51
+ ).compact
52
+ end
53
+
54
+ def to_openapi(version) # :nodoc:
55
+ super.merge(
56
+ allOf: all_of_references.map do |schema|
57
+ schema.to_openapi(version)
58
+ end.presence,
59
+ discriminator: discriminator&.to_openapi(version),
60
+ properties: properties.transform_values do |property|
61
+ property.to_openapi(version)
62
+ end,
63
+ required: properties.values.select(&:required?).map(&:name)
64
+ ).compact
65
+ end
66
+
67
+ protected
68
+
69
+ def merge_properties(definitions, path)
70
+ return properties unless all_of_references.present?
71
+
72
+ {}.tap do |properties|
73
+ all_of_references.each do |reference|
74
+ schema = reference.resolve(definitions)
75
+ raise "circular reference: #{reference.schema}" if schema.in?(path)
76
+
77
+ properties.merge!(schema.merge_properties(definitions, path + [self]))
78
+ end
79
+ properties.merge!(self.properties)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ class Reference < BaseReference
7
+ alias :schema :ref
8
+ alias :schema= :ref=
9
+
10
+ ##
11
+ # :attr: existence
12
+ # The level of Existence. The default level of existence
13
+ # is +ALLOW_OMITTED+.
14
+ attribute :existence, Existence, default: Existence::ALLOW_OMITTED
15
+
16
+ def resolve(definitions) # :nodoc:
17
+ schema = super
18
+ return schema if existence < Existence::ALLOW_EMPTY
19
+
20
+ Delegator.new(schema, [existence, schema.existence].max)
21
+ end
22
+
23
+ # Returns a hash representing the \JSON \Schema reference object.
24
+ def to_json_schema
25
+ { '$ref': "#/definitions/#{ref}" }
26
+ end
27
+
28
+ # Returns a hash representing the \OpenAPI reference object.
29
+ def to_openapi(version)
30
+ version = OpenAPI::Version.from(version)
31
+ path = version.major == 2 ? 'definitions' : 'components/schemas'
32
+
33
+ { '$ref': "#/#{path}/#{ref}" }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ class String < Base
7
+ include Conversion
8
+
9
+ ##
10
+ # :attr: format
11
+ # The optional format of a string. Possible values are:
12
+ #
13
+ # - <code>"date"</code>
14
+ # - <code>"date-time"</code>
15
+ #
16
+ attribute :format, ::String, values: %w[date date-time]
17
+
18
+ ##
19
+ # :attr: max_length
20
+ # The maximum length of a string.
21
+ attribute :max_length, writer: false
22
+
23
+ ##
24
+ # :attr: min_length
25
+ # The minimum length of a string.
26
+ attribute :min_length, writer: false
27
+
28
+ ##
29
+ # :attr: pattern
30
+ # The regular expression a string must match.
31
+ attribute :pattern, writer: false
32
+
33
+ def max_length=(value) # :nodoc:
34
+ add_validation('max_length', Validation::MaxLength.new(value))
35
+ @max_length = value
36
+ end
37
+
38
+ def min_length=(value) # :nodoc:
39
+ add_validation('min_length', Validation::MinLength.new(value))
40
+ @min_length = value
41
+ end
42
+
43
+ def pattern=(value) # :nodoc:
44
+ add_validation('pattern', Validation::Pattern.new(value))
45
+ @pattern = value
46
+ end
47
+
48
+ def to_json_schema # :nodoc:
49
+ format ? super.merge(format: format) : super
50
+ end
51
+
52
+ def to_openapi(*) # :nodoc:
53
+ format ? super.merge(format: format) : super
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class Base
8
+ def self.keyword
9
+ @keyword ||= name.demodulize.camelize(:lower).to_sym
10
+ end
11
+
12
+ attr_reader :value
13
+
14
+ def initialize(value)
15
+ @value = value
16
+ end
17
+
18
+ def to_json_schema_validation
19
+ { self.class.keyword => value }
20
+ end
21
+
22
+ def to_openapi_validation(*)
23
+ to_json_schema_validation
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class Enum < Base
8
+ def initialize(value)
9
+ unless value.respond_to?(:include?)
10
+ raise ArgumentError, "invalid enum: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if self.value.include?(value)
18
+
19
+ errors.add(:base, :inclusion)
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class MaxItems < Base
8
+ def initialize(value)
9
+ unless value.respond_to?(:<=)
10
+ raise ArgumentError, "invalid max items: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if value.size <= self.value
18
+
19
+ errors.add(:base, :invalid)
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class MaxLength < Base
8
+ def initialize(value)
9
+ unless value.respond_to?(:<=)
10
+ raise ArgumentError, "invalid max length: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if value.to_s.length <= self.value
18
+
19
+ errors.add(:base, :too_long, count: self.value)
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class Maximum < Base
8
+ attr_reader :exclusive
9
+
10
+ def initialize(value, exclusive: false)
11
+ if exclusive
12
+ raise ArgumentError, "invalid exclusive maximum: #{value.inspect}" unless value.respond_to?(:<)
13
+ else
14
+ raise ArgumentError, "invalid maximum: #{value.inspect}" unless value.respond_to?(:<=)
15
+ end
16
+
17
+ super(value)
18
+ @exclusive = exclusive
19
+ end
20
+
21
+ def validate(value, errors)
22
+ if exclusive
23
+ return true if value < self.value
24
+
25
+ errors.add(:base, :less_than, count: self.value)
26
+ else
27
+ return true if value <= self.value
28
+
29
+ errors.add(:base, :less_than_or_equal_to, count: self.value)
30
+ end
31
+ false
32
+ end
33
+
34
+ def to_json_schema_validation
35
+ return super unless exclusive
36
+
37
+ { exclusiveMaximum: value }
38
+ end
39
+
40
+ def to_openapi_validation(version)
41
+ version = OpenAPI::Version.from(version)
42
+ return to_json_schema_validation if version.major == 3 && version.minor == 1
43
+ return super unless exclusive
44
+
45
+ { maximum: value, exclusiveMaximum: true }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class MinItems < Base
8
+ def initialize(value)
9
+ unless value.respond_to?(:>=)
10
+ raise ArgumentError, "invalid min items: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if value.size >= self.value
18
+
19
+ errors.add(:base, :invalid)
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class MinLength < Base
8
+ def initialize(value)
9
+ unless value.respond_to?(:>=)
10
+ raise ArgumentError, "invalid min length: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if value.to_s.length >= self.value
18
+
19
+ errors.add(:base, :too_short, count: self.value)
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class Minimum < Base
8
+ attr_reader :exclusive
9
+
10
+ def initialize(value, exclusive: false)
11
+ if exclusive
12
+ raise ArgumentError, "invalid exclusive minimum: #{value.inspect}" unless value.respond_to?(:>)
13
+ else
14
+ raise ArgumentError, "invalid minimum: #{value.inspect}" unless value.respond_to?(:>=)
15
+ end
16
+
17
+ super(value)
18
+ @exclusive = exclusive
19
+ end
20
+
21
+ def validate(value, errors)
22
+ if exclusive
23
+ return true if value > self.value
24
+
25
+ errors.add(:base, :greater_than, count: self.value)
26
+ else
27
+ return true if value >= self.value
28
+
29
+ errors.add(:base, :greater_than_or_equal_to, count: self.value)
30
+ end
31
+ false
32
+ end
33
+
34
+ def to_json_schema_validation
35
+ return super unless exclusive
36
+
37
+ { exclusiveMinimum: value }
38
+ end
39
+
40
+ def to_openapi_validation(version)
41
+ version = OpenAPI::Version.from(version)
42
+ return to_json_schema_validation if version.major == 3 && version.minor == 1
43
+ return super unless exclusive
44
+
45
+ { minimum: value, exclusiveMinimum: true }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class MultipleOf < Base
8
+ def initialize(value)
9
+ raise ArgumentError, "invalid multiple of: #{value.inspect}" unless value.respond_to?(:%)
10
+
11
+ super
12
+ end
13
+
14
+ def validate(value, errors)
15
+ return true if (value % self.value).zero?
16
+
17
+ errors.add(:base, :invalid)
18
+ false
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module Schema
6
+ module Validation
7
+ class Pattern < Base
8
+ def initialize(value)
9
+ unless value.is_a?(Regexp)
10
+ raise ArgumentError, "invalid pattern: #{value.inspect}"
11
+ end
12
+
13
+ super
14
+ end
15
+
16
+ def validate(value, errors)
17
+ return true if value.to_s.match?(self.value)
18
+
19
+ errors.add(:base, :invalid)
20
+ false
21
+ end
22
+
23
+ def to_json_schema_validation
24
+ { pattern: value.source }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'validation/base'
4
+ require_relative 'validation/enum'
5
+ require_relative 'validation/max_items'
6
+ require_relative 'validation/max_length'
7
+ require_relative 'validation/maximum'
8
+ require_relative 'validation/min_items'
9
+ require_relative 'validation/min_length'
10
+ require_relative 'validation/minimum'
11
+ require_relative 'validation/multiple_of'
12
+ require_relative 'validation/pattern'
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'schema/conversion'
4
+ require_relative 'schema/boundary'
5
+ require_relative 'schema/delegator'
6
+ require_relative 'schema/reference'
7
+ require_relative 'schema/discriminator'
8
+ require_relative 'schema/base'
9
+ require_relative 'schema/boolean'
10
+ require_relative 'schema/array'
11
+ require_relative 'schema/numeric'
12
+ require_relative 'schema/integer'
13
+ require_relative 'schema/number'
14
+ require_relative 'schema/object'
15
+ require_relative 'schema/string'
16
+ require_relative 'schema/validation'
17
+
18
+ module Jsapi
19
+ module Meta
20
+ module Schema
21
+ class << self
22
+ # Creates a new schema model or reference. The +:type+ keyword determines
23
+ # the type of the schema to be created. Possible types are:
24
+ #
25
+ # - <code>"array"</code>
26
+ # - <code>"boolean"</code>
27
+ # - <code>"integer"</code>
28
+ # - <code>"number"</code>
29
+ # - <code>"object"</code>
30
+ # - <code>"string"</code>
31
+ #
32
+ # The default type is <code>"object"</code>.
33
+ #
34
+ # Raises an InvalidArgumentError if the given type is invalid.
35
+ def new(keywords = {})
36
+ if keywords.key?(:ref) || keywords.key?(:schema)
37
+ return Reference.new(keywords)
38
+ end
39
+
40
+ type = keywords[:type]
41
+ case type&.to_s
42
+ when 'array'
43
+ Array
44
+ when 'boolean'
45
+ Boolean
46
+ when 'integer'
47
+ Integer
48
+ when 'number'
49
+ Number
50
+ when 'object', nil
51
+ Object
52
+ when 'string'
53
+ String
54
+ else
55
+ raise InvalidArgumentError.new('type', type, Base::TYPES)
56
+ end.new(keywords.except(:type))
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
data/lib/jsapi/meta.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'meta/invalid_argument_error'
4
+ require_relative 'meta/reference_error'
5
+ require_relative 'meta/attributes'
6
+ require_relative 'meta/base'
7
+ require_relative 'meta/base_reference'
8
+ require_relative 'meta/openapi'
9
+ require_relative 'meta/example'
10
+ require_relative 'meta/existence'
11
+ require_relative 'meta/property'
12
+ require_relative 'meta/schema'
13
+ require_relative 'meta/request_body'
14
+ require_relative 'meta/parameter'
15
+ require_relative 'meta/response'
16
+ require_relative 'meta/operation'
17
+ require_relative 'meta/rescue_handler'
18
+ require_relative 'meta/definitions'
19
+
20
+ module Jsapi
21
+ # The meta model.
22
+ module Meta end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Model
5
+ module Attributes
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ delegate :[], :attribute?, :attributes, to: :nested
10
+ end
11
+
12
+ def method_missing(*args) # :nodoc:
13
+ name = args.first
14
+ attribute?(name) ? self[name] : super
15
+ end
16
+
17
+ def respond_to_missing?(param1, _param2) # :nodoc:
18
+ attribute?(param1) ? true : super
19
+ end
20
+ end
21
+ end
22
+ end