jsapi 0.9.1 → 1.0

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/dsl/definitions.rb +1 -1
  3. data/lib/jsapi/dsl/operation.rb +20 -0
  4. data/lib/jsapi/dsl/schema.rb +12 -2
  5. data/lib/jsapi/meta/callback/{model.rb → base.rb} +4 -6
  6. data/lib/jsapi/meta/callback/reference.rb +2 -6
  7. data/lib/jsapi/meta/callback.rb +3 -3
  8. data/lib/jsapi/meta/contact.rb +2 -2
  9. data/lib/jsapi/meta/defaults.rb +1 -1
  10. data/lib/jsapi/meta/definitions.rb +10 -8
  11. data/lib/jsapi/meta/example/{model.rb → base.rb} +5 -5
  12. data/lib/jsapi/meta/example/reference.rb +2 -6
  13. data/lib/jsapi/meta/example.rb +3 -3
  14. data/lib/jsapi/meta/external_documentation.rb +2 -2
  15. data/lib/jsapi/meta/header/{model.rb → base.rb} +3 -3
  16. data/lib/jsapi/meta/header/reference.rb +2 -6
  17. data/lib/jsapi/meta/header.rb +3 -3
  18. data/lib/jsapi/meta/info.rb +15 -7
  19. data/lib/jsapi/meta/license.rb +28 -5
  20. data/lib/jsapi/meta/link/{model.rb → base.rb} +2 -2
  21. data/lib/jsapi/meta/link/reference.rb +2 -6
  22. data/lib/jsapi/meta/link.rb +3 -3
  23. data/lib/jsapi/meta/{base → model}/attributes.rb +15 -18
  24. data/lib/jsapi/meta/{base/model.rb → model/base.rb} +2 -2
  25. data/lib/jsapi/meta/model/reference.rb +72 -0
  26. data/lib/jsapi/meta/{base → model}/type_caster.rb +1 -1
  27. data/lib/jsapi/meta/model.rb +6 -0
  28. data/lib/jsapi/meta/oauth_flow.rb +2 -2
  29. data/lib/jsapi/meta/openapi/extensions.rb +9 -25
  30. data/lib/jsapi/meta/openapi/version.rb +11 -0
  31. data/lib/jsapi/meta/openapi.rb +10 -0
  32. data/lib/jsapi/meta/operation.rb +16 -18
  33. data/lib/jsapi/meta/parameter/{model.rb → base.rb} +86 -69
  34. data/lib/jsapi/meta/parameter/reference.rb +4 -9
  35. data/lib/jsapi/meta/parameter.rb +3 -4
  36. data/lib/jsapi/meta/property.rb +7 -6
  37. data/lib/jsapi/meta/request_body/{model.rb → base.rb} +11 -9
  38. data/lib/jsapi/meta/request_body/reference.rb +2 -6
  39. data/lib/jsapi/meta/request_body.rb +3 -3
  40. data/lib/jsapi/meta/rescue_handler.rb +1 -1
  41. data/lib/jsapi/meta/response/{model.rb → base.rb} +3 -3
  42. data/lib/jsapi/meta/response/reference.rb +2 -9
  43. data/lib/jsapi/meta/response.rb +3 -3
  44. data/lib/jsapi/meta/schema/additional_properties.rb +2 -2
  45. data/lib/jsapi/meta/schema/array.rb +3 -5
  46. data/lib/jsapi/meta/schema/base.rb +10 -12
  47. data/lib/jsapi/meta/schema/conversion.rb +2 -2
  48. data/lib/jsapi/meta/schema/discriminator.rb +1 -1
  49. data/lib/jsapi/meta/schema/numeric.rb +3 -5
  50. data/lib/jsapi/meta/schema/object.rb +3 -5
  51. data/lib/jsapi/meta/schema/reference.rb +6 -6
  52. data/lib/jsapi/meta/schema/string.rb +3 -5
  53. data/lib/jsapi/meta/security_requirement.rb +3 -3
  54. data/lib/jsapi/meta/security_scheme/base.rb +1 -1
  55. data/lib/jsapi/meta/server.rb +2 -2
  56. data/lib/jsapi/meta/server_variable.rb +2 -2
  57. data/lib/jsapi/meta/tag.rb +2 -2
  58. data/lib/jsapi/meta.rb +1 -1
  59. data/lib/jsapi/version.rb +1 -1
  60. metadata +14 -15
  61. data/lib/jsapi/meta/base/reference.rb +0 -35
  62. data/lib/jsapi/meta/base.rb +0 -6
  63. data/lib/jsapi/meta/parameter/to_openapi.rb +0 -13
@@ -3,7 +3,7 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  # Maps an error class to a response status.
6
- class RescueHandler < Base::Model
6
+ class RescueHandler < Model::Base
7
7
  ##
8
8
  # :attr: error_class
9
9
  # The error class to be mapped.
@@ -3,8 +3,8 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Response
6
- # Defines a response.
7
- class Model < Base::Model
6
+ # Specifies a response.
7
+ class Base < Model::Base
8
8
  include OpenAPI::Extensions
9
9
 
10
10
  delegate_missing_to :schema
@@ -42,7 +42,7 @@ module Jsapi
42
42
  ##
43
43
  # :attr_reader: schema
44
44
  # The Schema of the response.
45
- attribute :schema, read_only: true
45
+ attribute :schema, accessors: %i[reader]
46
46
 
47
47
  def initialize(keywords = {})
48
48
  keywords = keywords.dup
@@ -3,15 +3,8 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Response
6
- class Reference < Base::Reference
7
- # Returns a hash representing the \OpenAPI reference object.
8
- def to_openapi(version, *)
9
- version = OpenAPI::Version.from(version)
10
- path = version.major == 2 ? 'responses' : 'components/responses'
11
-
12
- { '$ref': "#/#{path}/#{ref}" }
13
- end
14
- end
6
+ # Refers a reusable response.
7
+ class Reference < Model::Reference; end
15
8
  end
16
9
  end
17
10
  end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'response/model'
3
+ require_relative 'response/base'
4
4
  require_relative 'response/reference'
5
5
 
6
6
  module Jsapi
7
7
  module Meta
8
8
  module Response
9
9
  class << self
10
- # Creates a Model or Reference.
10
+ # Creates a Base or Reference.
11
11
  def new(keywords = {})
12
12
  return Reference.new(keywords) if keywords.key?(:ref)
13
13
 
14
- Model.new(keywords)
14
+ Base.new(keywords)
15
15
  end
16
16
  end
17
17
  end
@@ -3,13 +3,13 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Schema
6
- class AdditionalProperties < Meta::Base::Model
6
+ class AdditionalProperties < Model::Base
7
7
  delegate_missing_to :schema
8
8
 
9
9
  ##
10
10
  # :attr: schema
11
11
  # The Schema of additional properties.
12
- attribute :schema, read_only: true
12
+ attribute :schema, accessors: %i[reader]
13
13
 
14
14
  ##
15
15
  # :attr: source
@@ -7,19 +7,17 @@ module Jsapi
7
7
  ##
8
8
  # :attr: items
9
9
  # The Schema defining the kind of items.
10
- attribute :items, Schema
10
+ attribute :items, Schema, accessors: %i[reader]
11
11
 
12
12
  ##
13
13
  # :attr: max_items
14
14
  # The maximum length of an array.
15
- attribute :max_items
15
+ attribute :max_items, accessors: %i[reader]
16
16
 
17
17
  ##
18
18
  # :attr: min_items
19
19
  # The minimum length of an array.
20
- attribute :min_items
21
-
22
- undef items=, max_items=, min_items=
20
+ attribute :min_items, accessors: %i[reader]
23
21
 
24
22
  def items=(keywords = {}) # :nodoc:
25
23
  if keywords.key?(:schema)
@@ -3,7 +3,7 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Schema
6
- class Base < Meta::Base::Model
6
+ class Base < Model::Base
7
7
  include OpenAPI::Extensions
8
8
 
9
9
  ##
@@ -24,7 +24,7 @@ module Jsapi
24
24
  ##
25
25
  # :attr: enum
26
26
  # The allowed values.
27
- attribute :enum
27
+ attribute :enum, accessors: %i[reader]
28
28
 
29
29
  ##
30
30
  # :attr: examples
@@ -53,8 +53,6 @@ module Jsapi
53
53
  # The validations.
54
54
  attr_reader :validations
55
55
 
56
- undef enum=
57
-
58
56
  # Creates a new schema.
59
57
  def initialize(keywords = {})
60
58
  keywords = keywords.dup
@@ -96,9 +94,9 @@ module Jsapi
96
94
  default: default,
97
95
  examples: examples.presence,
98
96
  deprecated: deprecated?.presence
99
- }.tap do |hash|
97
+ }.tap do |result|
100
98
  validations.each_value do |validation|
101
- hash.merge!(validation.to_json_schema_validation)
99
+ result.merge!(validation.to_json_schema_validation)
102
100
  end
103
101
  end.compact
104
102
  end
@@ -129,14 +127,14 @@ module Jsapi
129
127
  examples: examples.presence,
130
128
  deprecated: deprecated?.presence
131
129
  }
132
- end.tap do |hash|
133
- hash[:title] = title
134
- hash[:description] = description
135
- hash[:default] = default
136
- hash[:externalDocs] = external_docs&.to_openapi
130
+ end.tap do |result|
131
+ result[:title] = title
132
+ result[:description] = description
133
+ result[:default] = default
134
+ result[:externalDocs] = external_docs&.to_openapi
137
135
 
138
136
  validations.each_value do |validation|
139
- hash.merge!(validation.to_openapi_validation(version))
137
+ result.merge!(validation.to_openapi_validation(version))
140
138
  end
141
139
  end
142
140
  )
@@ -6,8 +6,8 @@ module Jsapi
6
6
  module Meta
7
7
  module Schema
8
8
  module Conversion
9
- def self.included(mod)
10
- mod.attr_accessor :conversion
9
+ def self.included(base) # :nodoc:
10
+ base.attr_accessor :conversion
11
11
  end
12
12
 
13
13
  def convert(object)
@@ -3,7 +3,7 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Schema
6
- class Discriminator < Meta::Base::Model
6
+ class Discriminator < Model::Base
7
7
  ##
8
8
  # :attr: mappings
9
9
  attribute :mappings, { Object => String }
@@ -9,18 +9,16 @@ module Jsapi
9
9
  ##
10
10
  # :attr: maximum
11
11
  # The (exclusive) maximum.
12
- attribute :maximum
12
+ attribute :maximum, accessors: %i[reader]
13
13
 
14
14
  ##
15
15
  # :attr: minimum
16
16
  # The (exclusive) minimum.
17
- attribute :minimum
17
+ attribute :minimum, accessors: %i[reader]
18
18
 
19
19
  ##
20
20
  # :attr: multiple_of
21
- attribute :multiple_of
22
-
23
- undef maximum=, minimum=, multiple_of=
21
+ attribute :multiple_of, accessors: %i[reader]
24
22
 
25
23
  def maximum=(value) # :nodoc:
26
24
  boundary = Boundary.from(value)
@@ -24,15 +24,13 @@ module Jsapi
24
24
  ##
25
25
  # :attr: model
26
26
  # The model class to access nested object parameters by. The default
27
- # model class is Model::Base.
28
- attribute :model, Class, default: Model::Base
27
+ # model class is Jsapi::Model::Base.
28
+ attribute :model, Class, default: Jsapi::Model::Base
29
29
 
30
30
  ##
31
31
  # :attr: properties
32
32
  # The properties.
33
- attribute :properties, { String => Property }
34
-
35
- undef add_property
33
+ attribute :properties, { String => Property }, accessors: %i[reader writer]
36
34
 
37
35
  def add_property(name, keywords = {}) # :nodoc:
38
36
  (@properties ||= {})[name.to_s] = Property.new(name, **keywords)
@@ -3,7 +3,8 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Schema
6
- class Reference < Base::Reference
6
+ # Refers a reusable schema.
7
+ class Reference < Model::Reference
7
8
  ##
8
9
  # :attr: existence
9
10
  # The level of Existence. The default level of existence is +ALLOW_OMITTED+.
@@ -21,12 +22,11 @@ module Jsapi
21
22
  { '$ref': "#/definitions/#{ref}" }
22
23
  end
23
24
 
24
- # Returns a hash representing the \OpenAPI reference object.
25
- def to_openapi(version, *)
26
- version = OpenAPI::Version.from(version)
27
- path = version.major == 2 ? 'definitions' : 'components/schemas'
25
+ private
28
26
 
29
- { '$ref': "#/#{path}/#{ref}" }
27
+ # Overrides Model::Reference#openapi_components_path.
28
+ def openapi_components_path(version)
29
+ version.major == 2 ? 'definitions' : super
30
30
  end
31
31
  end
32
32
  end
@@ -14,19 +14,17 @@ module Jsapi
14
14
  ##
15
15
  # :attr: max_length
16
16
  # The maximum length of a string.
17
- attribute :max_length
17
+ attribute :max_length, accessors: %i[reader]
18
18
 
19
19
  ##
20
20
  # :attr: min_length
21
21
  # The minimum length of a string.
22
- attribute :min_length
22
+ attribute :min_length, accessors: %i[reader]
23
23
 
24
24
  ##
25
25
  # :attr: pattern
26
26
  # The regular expression a string must match.
27
- attribute :pattern
28
-
29
- undef max_length=, min_length=, pattern=
27
+ attribute :pattern, accessors: %i[reader]
30
28
 
31
29
  def max_length=(value) # :nodoc:
32
30
  add_validation('max_length', Validation::MaxLength.new(value))
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Jsapi
4
4
  module Meta
5
- # Specifies a security requirement object.
6
- class SecurityRequirement < Base::Model
7
- class Scheme < Base::Model
5
+ # Specifies a security requirement.
6
+ class SecurityRequirement < Model::Base
7
+ class Scheme < Model::Base
8
8
  ##
9
9
  # :attr: scopes
10
10
  # The array of scopes.
@@ -3,7 +3,7 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module SecurityScheme
6
- class Base < Meta::Base::Model
6
+ class Base < Model::Base
7
7
  ##
8
8
  # :attr: description
9
9
  # The description of the security scheme.
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Jsapi
4
4
  module Meta
5
- # Specifiess a server object.
6
- class Server < Base::Model
5
+ # Specifies a server.
6
+ class Server < Model::Base
7
7
  include OpenAPI::Extensions
8
8
 
9
9
  ##
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Jsapi
4
4
  module Meta
5
- # Specifies a server variable object.
6
- class ServerVariable < Base::Model
5
+ # Specifies a server variable.
6
+ class ServerVariable < Model::Base
7
7
  include OpenAPI::Extensions
8
8
 
9
9
  ##
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Jsapi
4
4
  module Meta
5
- # Specifies a tag object.
6
- class Tag < Base::Model
5
+ # Specifies a tag.
6
+ class Tag < Model::Base
7
7
  include OpenAPI::Extensions
8
8
 
9
9
  ##
data/lib/jsapi/meta.rb CHANGED
@@ -4,7 +4,7 @@ require_relative 'meta/reference_error'
4
4
  require_relative 'meta/callable'
5
5
  require_relative 'meta/existence'
6
6
  require_relative 'meta/openapi'
7
- require_relative 'meta/base'
7
+ require_relative 'meta/model'
8
8
  require_relative 'meta/defaults'
9
9
  require_relative 'meta/example'
10
10
  require_relative 'meta/external_documentation'
data/lib/jsapi/version.rb CHANGED
@@ -5,6 +5,6 @@ module Jsapi
5
5
  # NOTE: See https://bundler.io/guides/creating_gem.html
6
6
 
7
7
  # The current GEM version.
8
- VERSION = '0.9.1'
8
+ VERSION = '1.0'
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Göller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-18 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: denis@dmgoeller.de
@@ -50,50 +50,49 @@ files:
50
50
  - lib/jsapi/json/string.rb
51
51
  - lib/jsapi/json/value.rb
52
52
  - lib/jsapi/meta.rb
53
- - lib/jsapi/meta/base.rb
54
- - lib/jsapi/meta/base/attributes.rb
55
- - lib/jsapi/meta/base/model.rb
56
- - lib/jsapi/meta/base/reference.rb
57
- - lib/jsapi/meta/base/type_caster.rb
58
53
  - lib/jsapi/meta/callable.rb
59
54
  - lib/jsapi/meta/callable/symbol_evaluator.rb
60
55
  - lib/jsapi/meta/callable/symbol_sequence_evaluator.rb
61
56
  - lib/jsapi/meta/callback.rb
62
- - lib/jsapi/meta/callback/model.rb
57
+ - lib/jsapi/meta/callback/base.rb
63
58
  - lib/jsapi/meta/callback/reference.rb
64
59
  - lib/jsapi/meta/contact.rb
65
60
  - lib/jsapi/meta/defaults.rb
66
61
  - lib/jsapi/meta/definitions.rb
67
62
  - lib/jsapi/meta/example.rb
68
- - lib/jsapi/meta/example/model.rb
63
+ - lib/jsapi/meta/example/base.rb
69
64
  - lib/jsapi/meta/example/reference.rb
70
65
  - lib/jsapi/meta/existence.rb
71
66
  - lib/jsapi/meta/external_documentation.rb
72
67
  - lib/jsapi/meta/header.rb
73
- - lib/jsapi/meta/header/model.rb
68
+ - lib/jsapi/meta/header/base.rb
74
69
  - lib/jsapi/meta/header/reference.rb
75
70
  - lib/jsapi/meta/info.rb
76
71
  - lib/jsapi/meta/license.rb
77
72
  - lib/jsapi/meta/link.rb
78
- - lib/jsapi/meta/link/model.rb
73
+ - lib/jsapi/meta/link/base.rb
79
74
  - lib/jsapi/meta/link/reference.rb
75
+ - lib/jsapi/meta/model.rb
76
+ - lib/jsapi/meta/model/attributes.rb
77
+ - lib/jsapi/meta/model/base.rb
78
+ - lib/jsapi/meta/model/reference.rb
79
+ - lib/jsapi/meta/model/type_caster.rb
80
80
  - lib/jsapi/meta/oauth_flow.rb
81
81
  - lib/jsapi/meta/openapi.rb
82
82
  - lib/jsapi/meta/openapi/extensions.rb
83
83
  - lib/jsapi/meta/openapi/version.rb
84
84
  - lib/jsapi/meta/operation.rb
85
85
  - lib/jsapi/meta/parameter.rb
86
- - lib/jsapi/meta/parameter/model.rb
86
+ - lib/jsapi/meta/parameter/base.rb
87
87
  - lib/jsapi/meta/parameter/reference.rb
88
- - lib/jsapi/meta/parameter/to_openapi.rb
89
88
  - lib/jsapi/meta/property.rb
90
89
  - lib/jsapi/meta/reference_error.rb
91
90
  - lib/jsapi/meta/request_body.rb
92
- - lib/jsapi/meta/request_body/model.rb
91
+ - lib/jsapi/meta/request_body/base.rb
93
92
  - lib/jsapi/meta/request_body/reference.rb
94
93
  - lib/jsapi/meta/rescue_handler.rb
95
94
  - lib/jsapi/meta/response.rb
96
- - lib/jsapi/meta/response/model.rb
95
+ - lib/jsapi/meta/response/base.rb
97
96
  - lib/jsapi/meta/response/reference.rb
98
97
  - lib/jsapi/meta/schema.rb
99
98
  - lib/jsapi/meta/schema/additional_properties.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module Base
6
- # The base reference class.
7
- class Reference < Model
8
- ##
9
- # :attr: ref
10
- # The name of the referred object.
11
- attribute :ref, String
12
-
13
- # Derrives the component type from the inner most module name.
14
- def self.component_type
15
- @component_type ||= name.split('::')[-2].underscore
16
- end
17
-
18
- # Returns true.
19
- def reference?
20
- true
21
- end
22
-
23
- # Resolves +ref+ by looking up the object with that name in +definitions+.
24
- #
25
- # Raises a ReferenceError if +ref+ could not be resolved.
26
- def resolve(definitions)
27
- object = definitions.send("find_#{self.class.component_type}", ref)
28
- raise ReferenceError, ref if object.nil?
29
-
30
- object.resolve(definitions)
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base/type_caster'
4
- require_relative 'base/attributes'
5
- require_relative 'base/model'
6
- require_relative 'base/reference'
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module Parameter
6
- module ToOpenAPI
7
- def to_openapi(version, definitions)
8
- to_openapi_parameters(version, definitions).first
9
- end
10
- end
11
- end
12
- end
13
- end