jsapi 0.9.2 → 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.
- checksums.yaml +4 -4
- data/lib/jsapi/controller/methods.rb +4 -2
- data/lib/jsapi/meta/callback/{model.rb → base.rb} +4 -6
- data/lib/jsapi/meta/callback/reference.rb +2 -7
- data/lib/jsapi/meta/callback.rb +3 -3
- data/lib/jsapi/meta/contact.rb +2 -2
- data/lib/jsapi/meta/defaults.rb +1 -1
- data/lib/jsapi/meta/definitions.rb +4 -6
- data/lib/jsapi/meta/example/{model.rb → base.rb} +5 -5
- data/lib/jsapi/meta/example/reference.rb +2 -7
- data/lib/jsapi/meta/example.rb +3 -3
- data/lib/jsapi/meta/external_documentation.rb +2 -2
- data/lib/jsapi/meta/header/{model.rb → base.rb} +3 -3
- data/lib/jsapi/meta/header/reference.rb +2 -7
- data/lib/jsapi/meta/header.rb +3 -3
- data/lib/jsapi/meta/info.rb +15 -7
- data/lib/jsapi/meta/license.rb +28 -5
- data/lib/jsapi/meta/link/{model.rb → base.rb} +2 -2
- data/lib/jsapi/meta/link/reference.rb +2 -7
- data/lib/jsapi/meta/link.rb +3 -3
- data/lib/jsapi/meta/{base → model}/attributes.rb +15 -18
- data/lib/jsapi/meta/{base/model.rb → model/base.rb} +2 -2
- data/lib/jsapi/meta/model/reference.rb +72 -0
- data/lib/jsapi/meta/{base → model}/type_caster.rb +1 -1
- data/lib/jsapi/meta/model.rb +6 -0
- data/lib/jsapi/meta/oauth_flow.rb +2 -2
- data/lib/jsapi/meta/openapi/extensions.rb +9 -25
- data/lib/jsapi/meta/openapi/version.rb +11 -0
- data/lib/jsapi/meta/openapi.rb +10 -0
- data/lib/jsapi/meta/operation.rb +15 -17
- data/lib/jsapi/meta/parameter/{model.rb → base.rb} +85 -68
- data/lib/jsapi/meta/parameter/reference.rb +4 -11
- data/lib/jsapi/meta/parameter.rb +3 -4
- data/lib/jsapi/meta/property.rb +6 -6
- data/lib/jsapi/meta/request_body/{model.rb → base.rb} +10 -8
- data/lib/jsapi/meta/request_body/reference.rb +2 -7
- data/lib/jsapi/meta/request_body.rb +3 -3
- data/lib/jsapi/meta/rescue_handler.rb +1 -1
- data/lib/jsapi/meta/response/{model.rb → base.rb} +10 -2
- data/lib/jsapi/meta/response/reference.rb +2 -10
- data/lib/jsapi/meta/response.rb +3 -3
- data/lib/jsapi/meta/schema/additional_properties.rb +2 -2
- data/lib/jsapi/meta/schema/array.rb +3 -5
- data/lib/jsapi/meta/schema/base.rb +10 -12
- data/lib/jsapi/meta/schema/conversion.rb +2 -2
- data/lib/jsapi/meta/schema/discriminator.rb +1 -1
- data/lib/jsapi/meta/schema/numeric.rb +3 -5
- data/lib/jsapi/meta/schema/object.rb +3 -5
- data/lib/jsapi/meta/schema/reference.rb +6 -6
- data/lib/jsapi/meta/schema/string.rb +3 -5
- data/lib/jsapi/meta/security_requirement.rb +3 -3
- data/lib/jsapi/meta/security_scheme/base.rb +1 -1
- data/lib/jsapi/meta/server.rb +2 -2
- data/lib/jsapi/meta/server_variable.rb +2 -2
- data/lib/jsapi/meta/tag.rb +2 -2
- data/lib/jsapi/meta.rb +1 -1
- data/lib/jsapi/version.rb +1 -1
- metadata +14 -15
- data/lib/jsapi/meta/base/reference.rb +0 -35
- data/lib/jsapi/meta/base.rb +0 -6
- data/lib/jsapi/meta/parameter/to_openapi.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a24c58c515109ade6015fbd712e6d08f8ea0dc3e1b747ecd1e2430de0ad157d2
|
4
|
+
data.tar.gz: 98112b68df57d56b51f9edcaa2283069481fb0c2a494cde18cb35d0205917423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e08e06bcfe77edb6b356a0f2aa00bc141bf1aae3c1fac09fdb61be36b7be27b24a8c698fcad63374936d2defa345cbb9328f5a6f486a9816ae21be0cd52853
|
7
|
+
data.tar.gz: 8b671d32824bdb6e924fd7bd11f16c3baeac90c8bd3ef7a3796d8a8220b574740f750cad6e79f986f4950b8659ca9bb151ad95d6cfe63beb95e6ed63e76e4a3a
|
@@ -15,7 +15,7 @@ module Jsapi
|
|
15
15
|
# Performs an API operation by calling the given block. The request parameters are
|
16
16
|
# passed as an instance of the operation's model class to the block. The object
|
17
17
|
# returned by the block is implicitly rendered according to the appropriate +response+
|
18
|
-
# specification.
|
18
|
+
# specification when the content type is a JSON MIME type.
|
19
19
|
#
|
20
20
|
# api_operation('foo') do |api_params|
|
21
21
|
# # ...
|
@@ -151,9 +151,11 @@ module Jsapi
|
|
151
151
|
|
152
152
|
Error.new(e, status: status)
|
153
153
|
end
|
154
|
-
response = Response.new(result, response_model, definitions, omit: omit)
|
155
154
|
|
156
155
|
# Write response
|
156
|
+
return unless response_model.json_type?
|
157
|
+
|
158
|
+
response = Response.new(result, response_model, definitions, omit: omit)
|
157
159
|
self.content_type = response_model.content_type
|
158
160
|
render(json: response, status: status)
|
159
161
|
end
|
@@ -2,16 +2,14 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
class Operation < Base
|
5
|
+
class Operation < Model::Base; end
|
6
6
|
|
7
7
|
module Callback
|
8
|
-
# Specifies a callback
|
9
|
-
class
|
8
|
+
# Specifies a callback. Applies to \OpenAPI 3.0 and higher.
|
9
|
+
class Base < Model::Base
|
10
10
|
##
|
11
11
|
# :attr: operations
|
12
|
-
attribute :operations, { String => Operation }
|
13
|
-
|
14
|
-
undef add_operation
|
12
|
+
attribute :operations, { String => Operation }, accessors: %i[reader writer]
|
15
13
|
|
16
14
|
# Adds a callback operation.
|
17
15
|
#
|
@@ -3,13 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Callback
|
6
|
-
#
|
7
|
-
class Reference <
|
8
|
-
# Returns a hash representing the \OpenAPI reference object.
|
9
|
-
def to_openapi(*)
|
10
|
-
{ '$ref': "#/components/callbacks/#{ref}" }
|
11
|
-
end
|
12
|
-
end
|
6
|
+
# Refers a reusable callback.
|
7
|
+
class Reference < Model::Reference; end
|
13
8
|
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/jsapi/meta/callback.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'callback/
|
3
|
+
require_relative 'callback/base'
|
4
4
|
require_relative 'callback/reference'
|
5
5
|
|
6
6
|
module Jsapi
|
7
7
|
module Meta
|
8
8
|
module Callback
|
9
9
|
class << self
|
10
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
11
11
|
def new(keywords = {})
|
12
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
13
|
|
14
|
-
|
14
|
+
Base.new(keywords)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/jsapi/meta/contact.rb
CHANGED
data/lib/jsapi/meta/defaults.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
class Definitions < Base
|
5
|
+
class Definitions < Model::Base
|
6
6
|
include OpenAPI::Extensions
|
7
7
|
|
8
8
|
##
|
@@ -58,12 +58,12 @@ module Jsapi
|
|
58
58
|
##
|
59
59
|
# :attr: operations
|
60
60
|
# The Operation objects.
|
61
|
-
attribute :operations, { String => Operation }
|
61
|
+
attribute :operations, { String => Operation }, accessors: %i[reader writer]
|
62
62
|
|
63
63
|
##
|
64
64
|
# :attr: parameters
|
65
65
|
# The reusable Parameter objects.
|
66
|
-
attribute :parameters, { String => Parameter }
|
66
|
+
attribute :parameters, { String => Parameter }, accessors: %i[reader writer]
|
67
67
|
|
68
68
|
##
|
69
69
|
# :attr: rescue_handlers
|
@@ -138,8 +138,6 @@ module Jsapi
|
|
138
138
|
@parent&.inherited(self)
|
139
139
|
end
|
140
140
|
|
141
|
-
undef add_operation, add_parameter
|
142
|
-
|
143
141
|
def add_operation(name = nil, keywords = {}) # :nodoc:
|
144
142
|
name = name.nil? ? default_operation_name : name.to_s
|
145
143
|
keywords = keywords.reverse_merge(path: default_operation_path)
|
@@ -273,7 +271,7 @@ module Jsapi
|
|
273
271
|
else
|
274
272
|
{
|
275
273
|
# Order according to the OpenAPI specification 3.x
|
276
|
-
openapi: version.minor.zero? ? '3.0.3' : '3.1.
|
274
|
+
openapi: version.minor.zero? ? '3.0.3' : '3.1.1',
|
277
275
|
info: openapi_objects[:info],
|
278
276
|
servers: openapi_objects[:servers] ||
|
279
277
|
[default_server&.to_openapi].compact.presence,
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Example
|
6
|
-
# Specifies an example
|
7
|
-
class
|
6
|
+
# Specifies an example.
|
7
|
+
class Base < Model::Base
|
8
8
|
include OpenAPI::Extensions
|
9
9
|
|
10
10
|
##
|
@@ -29,11 +29,11 @@ module Jsapi
|
|
29
29
|
|
30
30
|
# Returns a hash representing the \OpenAPI example object.
|
31
31
|
def to_openapi(*)
|
32
|
-
with_openapi_extensions(summary: summary, description: description).tap do |
|
32
|
+
with_openapi_extensions(summary: summary, description: description).tap do |result|
|
33
33
|
if external?
|
34
|
-
|
34
|
+
result[:external_value] = value
|
35
35
|
else
|
36
|
-
|
36
|
+
result[:value] = value
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -3,13 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Example
|
6
|
-
#
|
7
|
-
class Reference <
|
8
|
-
# Returns a hash representing the \OpenAPI reference object.
|
9
|
-
def to_openapi(*)
|
10
|
-
{ '$ref': "#/components/examples/#{ref}" }
|
11
|
-
end
|
12
|
-
end
|
6
|
+
# Refers a reusable example.
|
7
|
+
class Reference < Model::Reference; end
|
13
8
|
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/jsapi/meta/example.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'example/
|
3
|
+
require_relative 'example/base'
|
4
4
|
require_relative 'example/reference'
|
5
5
|
|
6
6
|
module Jsapi
|
7
7
|
module Meta
|
8
8
|
module Example
|
9
9
|
class << self
|
10
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
11
11
|
def new(keywords = {})
|
12
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
13
|
|
14
|
-
|
14
|
+
Base.new(keywords)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Header
|
6
|
-
# Specifies
|
7
|
-
class
|
6
|
+
# Specifies an HTTP header.
|
7
|
+
class Base < Model::Base
|
8
8
|
include OpenAPI::Extensions
|
9
9
|
|
10
10
|
delegate_missing_to :schema
|
@@ -39,7 +39,7 @@ module Jsapi
|
|
39
39
|
##
|
40
40
|
# :attr_reader: schema
|
41
41
|
# The Schema of the header.
|
42
|
-
attribute :schema,
|
42
|
+
attribute :schema, accessors: %i[reader]
|
43
43
|
|
44
44
|
def initialize(keywords = {})
|
45
45
|
raise ArgumentError, "type can't be object" if keywords[:type] == 'object'
|
@@ -3,13 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Header
|
6
|
-
#
|
7
|
-
class Reference <
|
8
|
-
# Returns a hash representing the \OpenAPI reference object.
|
9
|
-
def to_openapi(*)
|
10
|
-
{ '$ref': "#/components/headers/#{ref}" }
|
11
|
-
end
|
12
|
-
end
|
6
|
+
# Refers a reusable header.
|
7
|
+
class Reference < Model::Reference; end
|
13
8
|
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/jsapi/meta/header.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'header/
|
3
|
+
require_relative 'header/base'
|
4
4
|
require_relative 'header/reference'
|
5
5
|
|
6
6
|
module Jsapi
|
7
7
|
module Meta
|
8
8
|
module Header
|
9
9
|
class << self
|
10
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
11
11
|
def new(keywords = {})
|
12
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
13
|
|
14
|
-
|
14
|
+
Base.new(keywords)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/jsapi/meta/info.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
# Specifies an
|
6
|
-
class Info < Base
|
5
|
+
# Specifies metadata about an API.
|
6
|
+
class Info < Model::Base
|
7
7
|
include OpenAPI::Extensions
|
8
8
|
|
9
9
|
##
|
10
10
|
# :attr: contact
|
11
|
-
# The Contact
|
11
|
+
# The Contact.
|
12
12
|
attribute :contact, Contact
|
13
13
|
|
14
14
|
##
|
@@ -18,9 +18,14 @@ module Jsapi
|
|
18
18
|
|
19
19
|
##
|
20
20
|
# :attr: license
|
21
|
-
# The License
|
21
|
+
# The License.
|
22
22
|
attribute :license, License
|
23
23
|
|
24
|
+
##
|
25
|
+
# :attr: summary
|
26
|
+
# The short summary of the API. Applies to \OpenAPI 3.1 and higher.
|
27
|
+
attribute :summary, String
|
28
|
+
|
24
29
|
##
|
25
30
|
# :attr: terms_of_service
|
26
31
|
# The URL pointing to the terms of service.
|
@@ -37,14 +42,17 @@ module Jsapi
|
|
37
42
|
attribute :version, String
|
38
43
|
|
39
44
|
# Returns a hash representing the \OpenAPI info object.
|
40
|
-
def to_openapi(*)
|
45
|
+
def to_openapi(version, *)
|
46
|
+
version = OpenAPI::Version.from(version)
|
47
|
+
|
41
48
|
with_openapi_extensions(
|
42
49
|
title: title,
|
43
|
-
|
50
|
+
summary: (summary if version >= OpenAPI::V3_1),
|
44
51
|
description: description,
|
45
52
|
termsOfService: terms_of_service,
|
46
53
|
contact: contact&.to_openapi,
|
47
|
-
license: license&.to_openapi
|
54
|
+
license: license&.to_openapi(version),
|
55
|
+
version: self.version
|
48
56
|
)
|
49
57
|
end
|
50
58
|
end
|
data/lib/jsapi/meta/license.rb
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
# Specifies a license
|
6
|
-
class License < Base
|
5
|
+
# Specifies a license.
|
6
|
+
class License < Model::Base
|
7
7
|
include OpenAPI::Extensions
|
8
8
|
|
9
|
+
##
|
10
|
+
# :attr: identifier
|
11
|
+
# The SDPX identifier of the license. Applies to \OpenAPI 3.1 and higher.
|
12
|
+
attribute :identifier, String, accessors: %i[reader]
|
13
|
+
|
9
14
|
##
|
10
15
|
# :attr: name
|
11
16
|
# The name of the license.
|
@@ -14,11 +19,29 @@ module Jsapi
|
|
14
19
|
##
|
15
20
|
# :attr: url
|
16
21
|
# The URL of the license.
|
17
|
-
attribute :url, String
|
22
|
+
attribute :url, String, accessors: %i[reader]
|
23
|
+
|
24
|
+
def identifier=(identifier) # :nodoc:
|
25
|
+
raise 'identifier and url are mutually exclusive' if url.present?
|
26
|
+
|
27
|
+
@identifier = identifier
|
28
|
+
end
|
29
|
+
|
30
|
+
def url=(url) # :nodoc:
|
31
|
+
raise 'identifier and url are mutually exclusive' if identifier.present?
|
32
|
+
|
33
|
+
@url = url
|
34
|
+
end
|
18
35
|
|
19
36
|
# Returns a hash representing the \OpenAPI license object.
|
20
|
-
def to_openapi(*)
|
21
|
-
|
37
|
+
def to_openapi(version, *)
|
38
|
+
version = OpenAPI::Version.from(version)
|
39
|
+
|
40
|
+
with_openapi_extensions(
|
41
|
+
name: name,
|
42
|
+
identifier: (identifier if version >= OpenAPI::V3_1),
|
43
|
+
url: url
|
44
|
+
)
|
22
45
|
end
|
23
46
|
end
|
24
47
|
end
|
@@ -3,13 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Link
|
6
|
-
#
|
7
|
-
class Reference <
|
8
|
-
# Returns a hash representing the \OpenAPI reference object.
|
9
|
-
def to_openapi(*)
|
10
|
-
{ '$ref': "#/components/links/#{ref}" }
|
11
|
-
end
|
12
|
-
end
|
6
|
+
# Refers a reusable link.
|
7
|
+
class Reference < Model::Reference; end
|
13
8
|
end
|
14
9
|
end
|
15
10
|
end
|
data/lib/jsapi/meta/link.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'link/
|
3
|
+
require_relative 'link/base'
|
4
4
|
require_relative 'link/reference'
|
5
5
|
|
6
6
|
module Jsapi
|
7
7
|
module Meta
|
8
8
|
module Link
|
9
9
|
class << self
|
10
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
11
11
|
def new(keywords = {})
|
12
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
13
|
|
14
|
-
|
14
|
+
Base.new(keywords)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
module
|
5
|
+
module Model
|
6
6
|
module Attributes
|
7
7
|
DEFAULT_ARRAY = [].freeze
|
8
8
|
DEFAULT_HASH = {}.freeze
|
9
9
|
|
10
10
|
# Defines an attribute.
|
11
11
|
def attribute(name, type = Object,
|
12
|
+
accessors: %i[add reader writer],
|
12
13
|
default: nil,
|
13
14
|
default_key: nil,
|
14
15
|
keys: nil,
|
15
|
-
read_only: false,
|
16
16
|
values: nil)
|
17
17
|
|
18
18
|
(@attribute_names ||= []) << name.to_sym
|
@@ -24,10 +24,9 @@ module Jsapi
|
|
24
24
|
# General default
|
25
25
|
default ||= DEFAULT_ARRAY
|
26
26
|
|
27
|
-
|
27
|
+
if accessors.include?(:add) || accessors.include?(:writer)
|
28
28
|
singular_name = name.to_s.singularize
|
29
29
|
add_method = "add_#{singular_name}"
|
30
|
-
|
31
30
|
type_caster = TypeCaster.new(type.first, values: values, name: singular_name)
|
32
31
|
|
33
32
|
# Attribute writer
|
@@ -35,7 +34,7 @@ module Jsapi
|
|
35
34
|
instance_variable_set(instance_variable_name, []).tap do
|
36
35
|
Array.wrap(argument).each { |element| send(add_method, element) }
|
37
36
|
end
|
38
|
-
end
|
37
|
+
end if accessors.include?(:writer)
|
39
38
|
|
40
39
|
# Add method
|
41
40
|
define_method(add_method) do |argument = nil|
|
@@ -47,26 +46,24 @@ module Jsapi
|
|
47
46
|
end << casted_argument
|
48
47
|
attribute_changed(name)
|
49
48
|
end
|
50
|
-
end
|
49
|
+
end if accessors.include?(:add)
|
51
50
|
end
|
52
51
|
when Hash
|
53
|
-
|
52
|
+
# General default
|
53
|
+
default ||= DEFAULT_HASH
|
54
54
|
|
55
|
+
singular_name = name.to_s.singularize
|
55
56
|
key_type, value_type = type.first
|
56
57
|
key_type_caster = TypeCaster.new(key_type, values: keys, name: 'key')
|
57
58
|
|
58
|
-
# General default
|
59
|
-
default ||= DEFAULT_HASH
|
60
|
-
|
61
59
|
# Lookup method
|
62
60
|
define_method(singular_name) do |key = nil|
|
63
61
|
key = default_key if key.to_s.empty?
|
64
62
|
send(name)[key_type_caster.cast(key)]
|
65
|
-
end
|
63
|
+
end if accessors.include?(:reader)
|
66
64
|
|
67
|
-
|
65
|
+
if accessors.include?(:add) || accessors.include?(:writer)
|
68
66
|
add_method = "add_#{singular_name}"
|
69
|
-
|
70
67
|
value_type_caster = TypeCaster.new(value_type, values: values)
|
71
68
|
|
72
69
|
# Attribute writer
|
@@ -74,7 +71,7 @@ module Jsapi
|
|
74
71
|
instance_variable_set(instance_variable_name, {}).tap do
|
75
72
|
Hash(argument).each { |key, value| send(add_method, key, value) }
|
76
73
|
end
|
77
|
-
end
|
74
|
+
end if accessors.include?(:writer)
|
78
75
|
|
79
76
|
# Add method
|
80
77
|
define_method(add_method) do |key_or_value, value = nil|
|
@@ -98,16 +95,16 @@ module Jsapi
|
|
98
95
|
|
99
96
|
attribute_changed(name)
|
100
97
|
casted_value
|
101
|
-
end
|
98
|
+
end if accessors.include?(:add)
|
102
99
|
end
|
103
100
|
else
|
104
101
|
# Predicate method
|
105
102
|
define_method("#{name}?") do
|
106
103
|
value = instance_variable_get(instance_variable_name)
|
107
104
|
value.nil? ? default || false : value
|
108
|
-
end if values == [true, false]
|
105
|
+
end if values == [true, false] && accessors.include?(:reader)
|
109
106
|
|
110
|
-
|
107
|
+
if accessors.include?(:writer)
|
111
108
|
type_caster = TypeCaster.new(type, values: values, name: name)
|
112
109
|
|
113
110
|
# Attribute writer
|
@@ -124,7 +121,7 @@ module Jsapi
|
|
124
121
|
define_method(name) do
|
125
122
|
value = instance_variable_get(instance_variable_name)
|
126
123
|
value.nil? ? default : value
|
127
|
-
end
|
124
|
+
end if accessors.include?(:reader)
|
128
125
|
end
|
129
126
|
|
130
127
|
def attribute_names
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Model
|
6
|
+
# The base reference class.
|
7
|
+
class Reference < Base
|
8
|
+
# Derrives the component type from the inner most module name.
|
9
|
+
def self.component_type
|
10
|
+
@component_type ||= name.split('::')[-2].underscore
|
11
|
+
end
|
12
|
+
|
13
|
+
# Derrives the \OpenAPI component type from the inner most module name.
|
14
|
+
def self.openapi_component_type
|
15
|
+
@openapi_component_type ||= name.split('::')[-2].pluralize.camelize(:lower)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# :attr: description
|
20
|
+
# The description to be displayed instead of the description of the referred object.
|
21
|
+
# Applies to \OpenAPI 3.1 and higher.
|
22
|
+
attribute :description, String
|
23
|
+
|
24
|
+
##
|
25
|
+
# :attr: ref
|
26
|
+
# The name of the referred object.
|
27
|
+
attribute :ref, String
|
28
|
+
|
29
|
+
##
|
30
|
+
# :attr: summary
|
31
|
+
# The summary to be displayed instead of the summary of the referred object.
|
32
|
+
# Applies to \OpenAPI 3.1 and higher.
|
33
|
+
attribute :summary, String
|
34
|
+
|
35
|
+
# Returns true.
|
36
|
+
def reference?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# Resolves +ref+ by looking up the object with that name in +definitions+.
|
41
|
+
#
|
42
|
+
# Raises a ReferenceError if +ref+ could not be resolved.
|
43
|
+
def resolve(definitions)
|
44
|
+
object = definitions.send("find_#{self.class.component_type}", ref)
|
45
|
+
raise ReferenceError, ref if object.nil?
|
46
|
+
|
47
|
+
object.resolve(definitions)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a hash representing the \OpenAPI reference object.
|
51
|
+
def to_openapi(version, *)
|
52
|
+
version = OpenAPI::Version.from(version)
|
53
|
+
|
54
|
+
{ '$ref': "#/#{openapi_components_path(version)}/#{ref}" }.tap do |result|
|
55
|
+
if version >= OpenAPI::V3_1
|
56
|
+
result[:summary] = summary if summary
|
57
|
+
result[:description] = description if description
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def openapi_components_path(version)
|
65
|
+
component_type = self.class.openapi_component_type
|
66
|
+
|
67
|
+
version.major == 2 ? component_type : "components/#{component_type}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|