jsapi 1.4 → 2.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.
- checksums.yaml +4 -4
- data/lib/jsapi/controller/actions/class_methods.rb +61 -0
- data/lib/jsapi/controller/actions.rb +13 -0
- data/lib/jsapi/controller/authentication/class_methods.rb +65 -0
- data/lib/jsapi/controller/authentication/credentials/api_key.rb +24 -0
- data/lib/jsapi/controller/authentication/credentials/http/base.rb +25 -0
- data/lib/jsapi/controller/authentication/credentials/http/basic.rb +34 -0
- data/lib/jsapi/controller/authentication/credentials/http/bearer.rb +30 -0
- data/lib/jsapi/controller/authentication/credentials/http.rb +5 -0
- data/lib/jsapi/controller/authentication/credentials.rb +38 -0
- data/lib/jsapi/controller/authentication.rb +70 -0
- data/lib/jsapi/controller/base.rb +5 -4
- data/lib/jsapi/controller/methods/callbacks/callback.rb +80 -0
- data/lib/jsapi/controller/methods/callbacks/class_methods.rb +62 -0
- data/lib/jsapi/controller/methods/callbacks.rb +54 -0
- data/lib/jsapi/controller/methods.rb +209 -116
- data/lib/jsapi/controller/parameters.rb +24 -20
- data/lib/jsapi/controller/response.rb +71 -39
- data/lib/jsapi/controller.rb +2 -1
- data/lib/jsapi/dsl/base.rb +38 -5
- data/lib/jsapi/dsl/class_methods.rb +2 -2
- data/lib/jsapi/dsl/definitions.rb +41 -27
- data/lib/jsapi/dsl/operation.rb +10 -109
- data/lib/jsapi/dsl/parameter.rb +1 -1
- data/lib/jsapi/dsl/path.rb +41 -18
- data/lib/jsapi/dsl/request_body.rb +1 -1
- data/lib/jsapi/dsl/response.rb +9 -6
- data/lib/jsapi/dsl/schema.rb +11 -5
- data/lib/jsapi/dsl/shared_operation_methods.rb +140 -0
- data/lib/jsapi/dsl.rb +1 -2
- data/lib/jsapi/json/array.rb +2 -2
- data/lib/jsapi/json/object.rb +6 -6
- data/lib/jsapi/json.rb +4 -6
- data/lib/jsapi/media/range.rb +102 -0
- data/lib/jsapi/media/type.rb +70 -0
- data/lib/jsapi/media/type_and_subtype.rb +38 -0
- data/lib/jsapi/media.rb +9 -0
- data/lib/jsapi/messages.rb +19 -0
- data/lib/jsapi/meta/callback/base.rb +63 -8
- data/lib/jsapi/meta/content.rb +59 -0
- data/lib/jsapi/meta/definitions.rb +299 -153
- data/lib/jsapi/meta/example/base.rb +41 -8
- data/lib/jsapi/meta/existence.rb +4 -2
- data/lib/jsapi/meta/header/base.rb +4 -2
- data/lib/jsapi/meta/info.rb +3 -1
- data/lib/jsapi/meta/license.rb +11 -5
- data/lib/jsapi/meta/model/attributes/class_methods.rb +150 -0
- data/lib/jsapi/meta/model/attributes/frozen_error.rb +16 -0
- data/lib/jsapi/meta/model/attributes/type_caster.rb +56 -0
- data/lib/jsapi/meta/model/attributes.rb +24 -118
- data/lib/jsapi/meta/model/base.rb +2 -5
- data/lib/jsapi/meta/model/reference.rb +46 -10
- data/lib/jsapi/meta/model/wrappable.rb +23 -0
- data/lib/jsapi/meta/model/wrapper.rb +26 -0
- data/lib/jsapi/meta/model.rb +2 -1
- data/lib/jsapi/meta/oauth_flow.rb +1 -1
- data/lib/jsapi/meta/openapi/extensions.rb +5 -6
- data/lib/jsapi/meta/openapi/version.rb +16 -4
- data/lib/jsapi/meta/operation.rb +177 -71
- data/lib/jsapi/meta/parameter/base.rb +10 -6
- data/lib/jsapi/meta/parameter/wrapper.rb +13 -0
- data/lib/jsapi/meta/parameter.rb +3 -0
- data/lib/jsapi/meta/path.rb +59 -13
- data/lib/jsapi/meta/pathname.rb +6 -3
- data/lib/jsapi/meta/property.rb +10 -0
- data/lib/jsapi/meta/request_body/base.rb +69 -32
- data/lib/jsapi/meta/request_body/wrapper.rb +13 -0
- data/lib/jsapi/meta/request_body.rb +3 -0
- data/lib/jsapi/meta/rescue_handler.rb +18 -17
- data/lib/jsapi/meta/response/base.rb +82 -58
- data/lib/jsapi/meta/response/reference.rb +11 -1
- data/lib/jsapi/meta/response/wrapper.rb +26 -0
- data/lib/jsapi/meta/response.rb +3 -0
- data/lib/jsapi/meta/schema/additional_properties.rb +8 -0
- data/lib/jsapi/meta/schema/array.rb +20 -8
- data/lib/jsapi/meta/schema/base.rb +10 -9
- data/lib/jsapi/meta/schema/boundary.rb +1 -0
- data/lib/jsapi/meta/schema/numeric.rb +26 -20
- data/lib/jsapi/meta/schema/object.rb +60 -44
- data/lib/jsapi/meta/schema/reference.rb +1 -8
- data/lib/jsapi/meta/schema/string.rb +12 -6
- data/lib/jsapi/meta/schema/wrapper.rb +31 -0
- data/lib/jsapi/meta/schema.rb +22 -9
- data/lib/jsapi/meta/security_requirement.rb +2 -2
- data/lib/jsapi/meta/security_scheme/api_key.rb +5 -2
- data/lib/jsapi/meta/security_scheme/base.rb +7 -5
- data/lib/jsapi/meta/security_scheme/http/basic.rb +5 -7
- data/lib/jsapi/meta/security_scheme/http/bearer.rb +5 -5
- data/lib/jsapi/meta/security_scheme/http/other.rb +1 -3
- data/lib/jsapi/meta/security_scheme/mutual_tls.rb +1 -3
- data/lib/jsapi/meta/security_scheme/oauth2.rb +18 -13
- data/lib/jsapi/meta/security_scheme/open_id_connect.rb +4 -4
- data/lib/jsapi/meta/security_scheme.rb +4 -4
- data/lib/jsapi/meta/server.rb +4 -2
- data/lib/jsapi/meta/tag.rb +9 -3
- data/lib/jsapi/meta.rb +2 -1
- data/lib/jsapi/model/base.rb +1 -1
- data/lib/jsapi/status/base.rb +35 -0
- data/lib/jsapi/status/code.rb +113 -0
- data/lib/jsapi/status/default.rb +16 -0
- data/lib/jsapi/status/range.rb +35 -0
- data/lib/jsapi/status.rb +37 -0
- data/lib/jsapi/version.rb +1 -1
- data/lib/jsapi.rb +3 -3
- metadata +36 -10
- data/lib/jsapi/controller/parameters_invalid.rb +0 -27
- data/lib/jsapi/dsl/callback.rb +0 -21
- data/lib/jsapi/dsl/error.rb +0 -36
- data/lib/jsapi/invalid_argument_error.rb +0 -12
- data/lib/jsapi/invalid_value_error.rb +0 -12
- data/lib/jsapi/invalid_value_helper.rb +0 -17
- data/lib/jsapi/meta/model/type_caster.rb +0 -50
- data/lib/jsapi/meta/schema/delegator.rb +0 -26
|
@@ -21,34 +21,40 @@ module Jsapi
|
|
|
21
21
|
attribute :multiple_of, accessors: %i[reader]
|
|
22
22
|
|
|
23
23
|
def maximum=(value) # :nodoc:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
try_modify_attribute!(:maximum) do
|
|
25
|
+
boundary = Boundary.from(value)
|
|
26
|
+
|
|
27
|
+
add_validation(
|
|
28
|
+
'maximum',
|
|
29
|
+
Validation::Maximum.new(
|
|
30
|
+
boundary.value,
|
|
31
|
+
exclusive: boundary.exclusive?
|
|
32
|
+
)
|
|
31
33
|
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
@maximum = boundary
|
|
35
|
+
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def minimum=(value) # :nodoc:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
try_modify_attribute!(:minimum) do
|
|
40
|
+
boundary = Boundary.from(value)
|
|
41
|
+
|
|
42
|
+
add_validation(
|
|
43
|
+
'minimum',
|
|
44
|
+
Validation::Minimum.new(
|
|
45
|
+
boundary.value,
|
|
46
|
+
exclusive: boundary.exclusive?
|
|
47
|
+
)
|
|
44
48
|
)
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
@minimum = boundary
|
|
50
|
+
end
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def multiple_of=(value) # :nodoc:
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
try_modify_attribute!(:multiple_of) do
|
|
55
|
+
add_validation('multiple_of', Validation::MultipleOf.new(value))
|
|
56
|
+
@multiple_of = value
|
|
57
|
+
end
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
end
|
|
@@ -4,6 +4,62 @@ module Jsapi
|
|
|
4
4
|
module Meta
|
|
5
5
|
module Schema
|
|
6
6
|
class Object < Base
|
|
7
|
+
class Wrapper < Schema::Wrapper
|
|
8
|
+
def additional_properties
|
|
9
|
+
AdditionalProperties.wrap(super, definitions)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def resolve_properties(context: nil)
|
|
13
|
+
super(definitions, context: context).transform_values do |property|
|
|
14
|
+
Property.wrap(property, definitions)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Resolves the schema within +context+.
|
|
19
|
+
#
|
|
20
|
+
# Raises a +RuntimeError+ when the schema couldn't be resolved.
|
|
21
|
+
def resolve_schema(object, context: nil)
|
|
22
|
+
return self if discriminator.nil?
|
|
23
|
+
|
|
24
|
+
properties = resolve_properties(context: context)
|
|
25
|
+
|
|
26
|
+
discriminating_property = properties[discriminator.property_name]
|
|
27
|
+
if discriminating_property.nil?
|
|
28
|
+
raise Messages.invalid_value(
|
|
29
|
+
name: 'discriminator property',
|
|
30
|
+
value: discriminator.property_name,
|
|
31
|
+
valid_values: properties.keys
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
discriminating_value = discriminating_property.reader.call(object)
|
|
36
|
+
if discriminating_value.nil?
|
|
37
|
+
discriminating_value = discriminating_property.default_value(context: context)
|
|
38
|
+
|
|
39
|
+
if discriminating_value.nil? && discriminator.default_mapping.nil?
|
|
40
|
+
raise "discriminating value can't be nil"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
schema_name = discriminator.mapping(discriminating_value) || discriminating_value
|
|
45
|
+
|
|
46
|
+
schema = definitions.find_schema(schema_name)
|
|
47
|
+
if schema.nil?
|
|
48
|
+
default_mapping = discriminator.default_mapping
|
|
49
|
+
schema = definitions.find_schema(default_mapping) unless default_mapping.nil?
|
|
50
|
+
|
|
51
|
+
if schema.nil?
|
|
52
|
+
raise "inheriting schema couldn't be found: " \
|
|
53
|
+
"#{[schema_name, default_mapping].compact.map(&:inspect).join(' or ')}"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
Wrapper
|
|
58
|
+
.new(schema.resolve(definitions), definitions)
|
|
59
|
+
.resolve_schema(object, context: context)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
7
63
|
##
|
|
8
64
|
# :attr: additional_properties
|
|
9
65
|
# The AdditionalProperties.
|
|
@@ -29,11 +85,13 @@ module Jsapi
|
|
|
29
85
|
|
|
30
86
|
##
|
|
31
87
|
# :attr: properties
|
|
32
|
-
# The properties.
|
|
88
|
+
# The properties. Maps property names to Property objects.
|
|
33
89
|
attribute :properties, { String => Property }, accessors: %i[reader writer]
|
|
34
90
|
|
|
35
91
|
def add_property(name, keywords = {}) # :nodoc:
|
|
36
|
-
(
|
|
92
|
+
try_modify_attribute!(:properties) do
|
|
93
|
+
(@properties ||= {})[name.to_s] = Property.new(name, keywords)
|
|
94
|
+
end
|
|
37
95
|
end
|
|
38
96
|
|
|
39
97
|
def resolve_properties(definitions, context: nil)
|
|
@@ -49,48 +107,6 @@ module Jsapi
|
|
|
49
107
|
end
|
|
50
108
|
end
|
|
51
109
|
|
|
52
|
-
# Resolves the schema within +context+.
|
|
53
|
-
#
|
|
54
|
-
# Raises a +RuntimeError+ when the schema couldn't be resolved.
|
|
55
|
-
def resolve_schema(object, definitions, context: nil)
|
|
56
|
-
return self if discriminator.nil?
|
|
57
|
-
|
|
58
|
-
properties = resolve_properties(definitions, context: context)
|
|
59
|
-
|
|
60
|
-
discriminating_property = properties[discriminator.property_name]
|
|
61
|
-
if discriminating_property.nil?
|
|
62
|
-
raise InvalidValueError.new('discriminator property',
|
|
63
|
-
discriminator.property_name,
|
|
64
|
-
valid_values: properties.keys)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
discriminating_value = discriminating_property.reader.call(object)
|
|
68
|
-
if discriminating_value.nil?
|
|
69
|
-
discriminating_value = discriminating_property.default_value(
|
|
70
|
-
definitions,
|
|
71
|
-
context: context
|
|
72
|
-
)
|
|
73
|
-
if discriminating_value.nil? && discriminator.default_mapping.nil?
|
|
74
|
-
raise "discriminating value can't be nil"
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
schema_name = discriminator.mapping(discriminating_value) || discriminating_value
|
|
79
|
-
|
|
80
|
-
schema = definitions.find_schema(schema_name)
|
|
81
|
-
if schema.nil?
|
|
82
|
-
default_mapping = discriminator.default_mapping
|
|
83
|
-
schema = definitions.find_schema(default_mapping) unless default_mapping.nil?
|
|
84
|
-
|
|
85
|
-
if schema.nil?
|
|
86
|
-
raise "inheriting schema couldn't be found: " \
|
|
87
|
-
"#{[schema_name, default_mapping].compact.map(&:inspect).join(' or ')}"
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
schema.resolve(definitions).resolve_schema(object, definitions, context: context)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
110
|
def to_json_schema # :nodoc:
|
|
95
111
|
super.merge(
|
|
96
112
|
allOf: all_of_references.map(&:to_json_schema).presence,
|
|
@@ -7,16 +7,9 @@ module Jsapi
|
|
|
7
7
|
class Reference < Model::Reference
|
|
8
8
|
##
|
|
9
9
|
# :attr: existence
|
|
10
|
-
#
|
|
10
|
+
# Overrides the level of existence of the referred schema.
|
|
11
11
|
attribute :existence, Existence, default: Existence::ALLOW_OMITTED
|
|
12
12
|
|
|
13
|
-
def resolve(definitions) # :nodoc:
|
|
14
|
-
schema = super
|
|
15
|
-
return schema if existence < Existence::ALLOW_EMPTY
|
|
16
|
-
|
|
17
|
-
Delegator.new(schema, [existence, schema.existence].max)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
13
|
# Returns a hash representing the \JSON \Schema reference object.
|
|
21
14
|
def to_json_schema
|
|
22
15
|
{ '$ref': "#/definitions/#{ref}" }
|
|
@@ -27,18 +27,24 @@ module Jsapi
|
|
|
27
27
|
attribute :pattern, accessors: %i[reader]
|
|
28
28
|
|
|
29
29
|
def max_length=(value) # :nodoc:
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
try_modify_attribute!(:max_length) do
|
|
31
|
+
add_validation('max_length', Validation::MaxLength.new(value))
|
|
32
|
+
@max_length = value
|
|
33
|
+
end
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
def min_length=(value) # :nodoc:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
try_modify_attribute!(:min_length) do
|
|
38
|
+
add_validation('min_length', Validation::MinLength.new(value))
|
|
39
|
+
@min_length = value
|
|
40
|
+
end
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
def pattern=(value) # :nodoc:
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
try_modify_attribute!(:pattern) do
|
|
45
|
+
add_validation('pattern', Validation::Pattern.new(value))
|
|
46
|
+
@pattern = value
|
|
47
|
+
end
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def to_json_schema # :nodoc:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jsapi
|
|
4
|
+
module Meta
|
|
5
|
+
module Schema
|
|
6
|
+
class Wrapper < Model::Wrapper
|
|
7
|
+
# The level of existence.
|
|
8
|
+
attr_reader :existence
|
|
9
|
+
|
|
10
|
+
def initialize(schema, definitions)
|
|
11
|
+
@existence =
|
|
12
|
+
[schema.existence].tap do |levels|
|
|
13
|
+
s = schema
|
|
14
|
+
while s.is_a?(Reference)
|
|
15
|
+
s = s.resolve(definitions, deep: false)
|
|
16
|
+
levels << s.existence
|
|
17
|
+
end
|
|
18
|
+
end.compact.max || Existence::ALLOW_OMITTED
|
|
19
|
+
super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns the default value within +context+.
|
|
23
|
+
def default_value(context: nil)
|
|
24
|
+
return default unless default.nil?
|
|
25
|
+
|
|
26
|
+
definitions.default_value(type, context: context)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/jsapi/meta/schema.rb
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
require_relative 'schema/additional_properties'
|
|
4
4
|
require_relative 'schema/conversion'
|
|
5
5
|
require_relative 'schema/boundary'
|
|
6
|
-
require_relative 'schema/delegator'
|
|
7
6
|
require_relative 'schema/discriminator'
|
|
8
7
|
require_relative 'schema/reference'
|
|
9
8
|
require_relative 'schema/validation'
|
|
10
9
|
|
|
11
10
|
require_relative 'schema/base'
|
|
11
|
+
require_relative 'schema/wrapper'
|
|
12
12
|
require_relative 'schema/array'
|
|
13
13
|
require_relative 'schema/boolean'
|
|
14
14
|
require_relative 'schema/numeric'
|
|
@@ -20,12 +20,6 @@ require_relative 'schema/string'
|
|
|
20
20
|
module Jsapi
|
|
21
21
|
module Meta
|
|
22
22
|
module Schema
|
|
23
|
-
TYPES = %w[array boolean integer number object string].freeze # :nodoc:
|
|
24
|
-
|
|
25
|
-
TYPES.each do |type|
|
|
26
|
-
Base.define_method("#{type}?") { self.type == type }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
23
|
class << self
|
|
30
24
|
# Creates a new schema. The +:type+ keyword determines the type of the schema to be
|
|
31
25
|
# created. Possible types are:
|
|
@@ -39,7 +33,7 @@ module Jsapi
|
|
|
39
33
|
#
|
|
40
34
|
# The default type is <code>"object"</code>.
|
|
41
35
|
#
|
|
42
|
-
# Raises an
|
|
36
|
+
# Raises an ArgumentError if the given type is invalid.
|
|
43
37
|
def new(keywords = {})
|
|
44
38
|
return Reference.new(keywords) if keywords.key?(:ref)
|
|
45
39
|
|
|
@@ -58,9 +52,28 @@ module Jsapi
|
|
|
58
52
|
when 'string'
|
|
59
53
|
String
|
|
60
54
|
else
|
|
61
|
-
raise
|
|
55
|
+
raise ArgumentError, Messages.invalid_value(
|
|
56
|
+
name: 'type',
|
|
57
|
+
value: type,
|
|
58
|
+
valid_values: TYPES
|
|
59
|
+
)
|
|
62
60
|
end.new(keywords.except(:type))
|
|
63
61
|
end
|
|
62
|
+
|
|
63
|
+
# Wraps +schema+.
|
|
64
|
+
def wrap(schema, definitions)
|
|
65
|
+
return if schema.nil?
|
|
66
|
+
return schema if schema.is_a?(Wrapper)
|
|
67
|
+
|
|
68
|
+
case schema.resolve(definitions).type
|
|
69
|
+
when 'array'
|
|
70
|
+
Array::Wrapper
|
|
71
|
+
when 'object'
|
|
72
|
+
Object::Wrapper
|
|
73
|
+
else
|
|
74
|
+
Wrapper
|
|
75
|
+
end.new(schema, definitions)
|
|
76
|
+
end
|
|
64
77
|
end
|
|
65
78
|
end
|
|
66
79
|
end
|
|
@@ -7,13 +7,13 @@ module Jsapi
|
|
|
7
7
|
class Scheme < Model::Base
|
|
8
8
|
##
|
|
9
9
|
# :attr: scopes
|
|
10
|
-
# The
|
|
10
|
+
# The scopes.
|
|
11
11
|
attribute :scopes, [String]
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
##
|
|
15
15
|
# :attr_reader: schemes
|
|
16
|
-
# The schemes.
|
|
16
|
+
# The schemes. Maps strings to Scheme objects.
|
|
17
17
|
attribute :schemes, { String => Scheme }
|
|
18
18
|
|
|
19
19
|
# Returns a hash representing the \OpenAPI security requirement object.
|
|
@@ -27,8 +27,11 @@ module Jsapi
|
|
|
27
27
|
def to_openapi(version, *)
|
|
28
28
|
version = OpenAPI::Version.from(version)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
openapi_security_scheme_object(
|
|
31
|
+
'apiKey',
|
|
32
|
+
version,
|
|
33
|
+
name: name,
|
|
34
|
+
in: self.in
|
|
32
35
|
)
|
|
33
36
|
end
|
|
34
37
|
end
|
|
@@ -11,18 +11,20 @@ module Jsapi
|
|
|
11
11
|
|
|
12
12
|
##
|
|
13
13
|
# :attr: deprecated
|
|
14
|
-
# Specifies whether
|
|
14
|
+
# Specifies whether the security scheme is marked as deprecated.
|
|
15
|
+
#
|
|
15
16
|
# Applies to \OpenAPI 3.2 and higher.
|
|
16
17
|
attribute :deprecated, values: [true, false]
|
|
17
18
|
|
|
18
19
|
private
|
|
19
20
|
|
|
20
|
-
def
|
|
21
|
-
|
|
21
|
+
def openapi_security_scheme_object(type, version, **keywords)
|
|
22
|
+
with_openapi_extensions(
|
|
22
23
|
type: type,
|
|
23
24
|
description: description,
|
|
24
|
-
deprecated: (deprecated?.presence if version >= OpenAPI::V3_2)
|
|
25
|
-
|
|
25
|
+
deprecated: (deprecated?.presence if version >= OpenAPI::V3_2),
|
|
26
|
+
**keywords
|
|
27
|
+
)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -12,13 +12,11 @@ module Jsapi
|
|
|
12
12
|
def to_openapi(version, *)
|
|
13
13
|
version = OpenAPI::Version.from(version)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
)
|
|
15
|
+
if version < OpenAPI::V3_0
|
|
16
|
+
openapi_security_scheme_object('basic', version)
|
|
17
|
+
else
|
|
18
|
+
openapi_security_scheme_object('http', version, scheme: 'basic')
|
|
19
|
+
end
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
end
|
|
@@ -22,11 +22,11 @@ module Jsapi
|
|
|
22
22
|
version = OpenAPI::Version.from(version)
|
|
23
23
|
return if version < OpenAPI::V3_0
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
openapi_security_scheme_object(
|
|
26
|
+
'http',
|
|
27
|
+
version,
|
|
28
|
+
scheme: 'bearer',
|
|
29
|
+
bearerFormat: bearer_format
|
|
30
30
|
)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -23,9 +23,7 @@ module Jsapi
|
|
|
23
23
|
version = OpenAPI::Version.from(version)
|
|
24
24
|
return if version < OpenAPI::V3_0
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
base_openapi_fields('http', version).merge(scheme: scheme)
|
|
28
|
-
)
|
|
26
|
+
openapi_security_scheme_object('http', version, scheme: scheme)
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
end
|
|
@@ -25,9 +25,11 @@ module Jsapi
|
|
|
25
25
|
device_authorization
|
|
26
26
|
implicit
|
|
27
27
|
password]
|
|
28
|
+
|
|
28
29
|
##
|
|
29
30
|
# :attr: oauth2_metadata_url
|
|
30
31
|
# The URL of the OAuth2 authorization server metadata.
|
|
32
|
+
#
|
|
31
33
|
# Applies to \OpenAPI 3.2 and higher.
|
|
32
34
|
attribute :oauth2_metadata_url, String
|
|
33
35
|
|
|
@@ -35,23 +37,26 @@ module Jsapi
|
|
|
35
37
|
def to_openapi(version, *)
|
|
36
38
|
version = OpenAPI::Version.from(version)
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
flows = oauth_flows
|
|
41
|
-
flows = flows.except('device_authorization') unless version >= OpenAPI::V3_2
|
|
42
|
-
|
|
43
|
-
if version >= OpenAPI::V3_0
|
|
44
|
-
fields[:flows] = flows.to_h do |key, value|
|
|
45
|
-
[key.to_s.camelize(:lower).to_sym, value.to_openapi(version)]
|
|
46
|
-
end if flows.any?
|
|
40
|
+
flows = oauth_flows
|
|
41
|
+
flows = flows.except('device_authorization') if version < OpenAPI::V3_2
|
|
47
42
|
|
|
48
|
-
|
|
43
|
+
openapi_security_scheme_object(
|
|
44
|
+
'oauth2',
|
|
45
|
+
version,
|
|
46
|
+
**if version >= OpenAPI::V3_0
|
|
47
|
+
{
|
|
48
|
+
flows:
|
|
49
|
+
flows.to_h do |key, value|
|
|
50
|
+
[key.to_s.camelize(:lower), value.to_openapi(version)]
|
|
51
|
+
end.presence,
|
|
52
|
+
oauth2MetadataUrl: (oauth2_metadata_url if version >= OpenAPI::V3_2)
|
|
53
|
+
}
|
|
49
54
|
elsif flows.one?
|
|
50
55
|
key, flow = flows.first
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
{ flow: key, **flow.to_openapi(version) }
|
|
57
|
+
else
|
|
58
|
+
{}
|
|
53
59
|
end
|
|
54
|
-
end
|
|
55
60
|
)
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -17,10 +17,10 @@ module Jsapi
|
|
|
17
17
|
version = OpenAPI::Version.from(version)
|
|
18
18
|
return if version < OpenAPI::V3_0
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
openapi_security_scheme_object(
|
|
21
|
+
'openIdConnect',
|
|
22
|
+
version,
|
|
23
|
+
openIdConnectUrl: open_id_connect_url
|
|
24
24
|
)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -20,7 +20,7 @@ module Jsapi
|
|
|
20
20
|
# - <code>"oauth2"</code>
|
|
21
21
|
# - <code>"open_id_connect"</code>
|
|
22
22
|
#
|
|
23
|
-
# Raises an
|
|
23
|
+
# Raises an ArgumentError if the given type is invalid.
|
|
24
24
|
def new(keywords = {})
|
|
25
25
|
type = keywords[:type]
|
|
26
26
|
keywords = keywords.except(:type)
|
|
@@ -39,9 +39,9 @@ module Jsapi
|
|
|
39
39
|
when 'open_id_connect' # OpenAPI 3.0 and higher
|
|
40
40
|
OpenIDConnect.new(keywords)
|
|
41
41
|
else
|
|
42
|
-
raise
|
|
43
|
-
'type',
|
|
44
|
-
type,
|
|
42
|
+
raise ArgumentError.new(
|
|
43
|
+
name: 'type',
|
|
44
|
+
value: type,
|
|
45
45
|
valid_values: %w[api_key basic http oauth2 open_id_connect]
|
|
46
46
|
)
|
|
47
47
|
end
|
data/lib/jsapi/meta/server.rb
CHANGED
|
@@ -13,7 +13,9 @@ module Jsapi
|
|
|
13
13
|
|
|
14
14
|
##
|
|
15
15
|
# :attr: name
|
|
16
|
-
# The optional unique name of the server.
|
|
16
|
+
# The optional unique name of the server.
|
|
17
|
+
#
|
|
18
|
+
# Applies to \OpenAPI 3.2 and higher.
|
|
17
19
|
attribute :name, String
|
|
18
20
|
|
|
19
21
|
##
|
|
@@ -23,7 +25,7 @@ module Jsapi
|
|
|
23
25
|
|
|
24
26
|
##
|
|
25
27
|
# :attr_reader: variables
|
|
26
|
-
# The ServerVariable objects.
|
|
28
|
+
# The server variables. Maps strings to ServerVariable objects.
|
|
27
29
|
attribute :variables, { String => ServerVariable }
|
|
28
30
|
|
|
29
31
|
# Returns a hash representing the \OpenAPI server object.
|
data/lib/jsapi/meta/tag.rb
CHANGED
|
@@ -18,7 +18,9 @@ module Jsapi
|
|
|
18
18
|
|
|
19
19
|
##
|
|
20
20
|
# :attr: kind
|
|
21
|
-
# The category of the tag.
|
|
21
|
+
# The category of the tag.
|
|
22
|
+
#
|
|
23
|
+
# Applies to \OpenAPI 3.2 and higher.
|
|
22
24
|
attribute :kind, String
|
|
23
25
|
|
|
24
26
|
##
|
|
@@ -28,12 +30,16 @@ module Jsapi
|
|
|
28
30
|
|
|
29
31
|
##
|
|
30
32
|
# :attr: parent
|
|
31
|
-
# The name of the parent tag.
|
|
33
|
+
# The name of the parent tag.
|
|
34
|
+
#
|
|
35
|
+
# Applies to \OpenAPI 3.2 and higher.
|
|
32
36
|
attribute :parent, String
|
|
33
37
|
|
|
34
38
|
##
|
|
35
39
|
# :attr: summary
|
|
36
|
-
# The short summary of the tag.
|
|
40
|
+
# The short summary of the tag.
|
|
41
|
+
#
|
|
42
|
+
# Applies to \OpenAPI 3.2 and higher.
|
|
37
43
|
attribute :summary, String
|
|
38
44
|
|
|
39
45
|
# Returns a hash representing the \OpenAPI tag object.
|
data/lib/jsapi/meta.rb
CHANGED
|
@@ -22,12 +22,13 @@ require_relative 'meta/security_requirement'
|
|
|
22
22
|
require_relative 'meta/link'
|
|
23
23
|
require_relative 'meta/property'
|
|
24
24
|
require_relative 'meta/schema'
|
|
25
|
+
require_relative 'meta/content'
|
|
25
26
|
require_relative 'meta/request_body'
|
|
26
27
|
require_relative 'meta/parameter'
|
|
27
28
|
require_relative 'meta/pathname'
|
|
28
|
-
require_relative 'meta/path'
|
|
29
29
|
require_relative 'meta/response'
|
|
30
30
|
require_relative 'meta/operation'
|
|
31
|
+
require_relative 'meta/path'
|
|
31
32
|
require_relative 'meta/rescue_handler'
|
|
32
33
|
require_relative 'meta/definitions'
|
|
33
34
|
|
data/lib/jsapi/model/base.rb
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jsapi
|
|
4
|
+
module Status
|
|
5
|
+
class Base
|
|
6
|
+
include Comparable
|
|
7
|
+
|
|
8
|
+
attr_reader :priority, :value
|
|
9
|
+
|
|
10
|
+
delegate :hash, :to_s, to: :value
|
|
11
|
+
|
|
12
|
+
def initialize(value, priority:)
|
|
13
|
+
@priority = priority
|
|
14
|
+
@value = value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def ==(other) # :nodoc:
|
|
18
|
+
other.is_a?(self.class) && other.value == value
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias eql? ==
|
|
22
|
+
|
|
23
|
+
def <=>(other) # :nodoc:
|
|
24
|
+
result = priority <=> other.priority
|
|
25
|
+
return result unless result.zero?
|
|
26
|
+
|
|
27
|
+
value <=> other.value
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def inspect # :nodoc:
|
|
31
|
+
"#<#{self.class} #{value.inspect}>"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|