jsapi 0.7.3 → 0.9.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/controller/{error_result.rb → error.rb} +1 -1
  3. data/lib/jsapi/controller/methods.rb +49 -38
  4. data/lib/jsapi/controller/parameters.rb +4 -2
  5. data/lib/jsapi/controller/response.rb +82 -64
  6. data/lib/jsapi/controller.rb +1 -1
  7. data/lib/jsapi/dsl/base.rb +55 -0
  8. data/lib/jsapi/dsl/callback.rb +21 -0
  9. data/lib/jsapi/dsl/class_methods.rb +116 -10
  10. data/lib/jsapi/dsl/definitions.rb +173 -33
  11. data/lib/jsapi/dsl/examples.rb +30 -0
  12. data/lib/jsapi/dsl/operation.rb +60 -32
  13. data/lib/jsapi/dsl/parameter.rb +2 -2
  14. data/lib/jsapi/dsl/request_body.rb +2 -2
  15. data/lib/jsapi/dsl/response.rb +35 -11
  16. data/lib/jsapi/dsl/schema.rb +16 -16
  17. data/lib/jsapi/dsl.rb +4 -4
  18. data/lib/jsapi/{helpers/invalid_value_helper.rb → invalid_value_helper.rb} +1 -1
  19. data/lib/jsapi/json/array.rb +7 -7
  20. data/lib/jsapi/json/object.rb +6 -6
  21. data/lib/jsapi/json.rb +4 -4
  22. data/lib/jsapi/meta/base/attributes.rb +21 -19
  23. data/lib/jsapi/meta/base/model.rb +15 -7
  24. data/lib/jsapi/meta/callback/model.rb +34 -0
  25. data/lib/jsapi/meta/callback/reference.rb +14 -0
  26. data/lib/jsapi/meta/callback.rb +19 -0
  27. data/lib/jsapi/meta/contact.rb +30 -0
  28. data/lib/jsapi/meta/defaults.rb +2 -2
  29. data/lib/jsapi/meta/definitions.rb +230 -124
  30. data/lib/jsapi/meta/example/model.rb +43 -0
  31. data/lib/jsapi/meta/example/reference.rb +14 -0
  32. data/lib/jsapi/meta/example.rb +19 -0
  33. data/lib/jsapi/meta/external_documentation.rb +25 -0
  34. data/lib/jsapi/meta/header/model.rb +81 -0
  35. data/lib/jsapi/meta/header/reference.rb +14 -0
  36. data/lib/jsapi/meta/header.rb +19 -0
  37. data/lib/jsapi/meta/info.rb +52 -0
  38. data/lib/jsapi/meta/license.rb +25 -0
  39. data/lib/jsapi/meta/link/model.rb +48 -0
  40. data/lib/jsapi/meta/link/reference.rb +14 -0
  41. data/lib/jsapi/meta/link.rb +19 -0
  42. data/lib/jsapi/meta/oauth_flow.rb +52 -0
  43. data/lib/jsapi/meta/openapi.rb +0 -28
  44. data/lib/jsapi/meta/operation.rb +19 -18
  45. data/lib/jsapi/meta/parameter/model.rb +6 -4
  46. data/lib/jsapi/meta/parameter/reference.rb +6 -4
  47. data/lib/jsapi/meta/parameter/to_openapi.rb +13 -0
  48. data/lib/jsapi/meta/parameter.rb +2 -1
  49. data/lib/jsapi/meta/property.rb +1 -1
  50. data/lib/jsapi/meta/request_body/model.rb +6 -5
  51. data/lib/jsapi/meta/request_body.rb +1 -1
  52. data/lib/jsapi/meta/response/model.rb +16 -13
  53. data/lib/jsapi/meta/response.rb +1 -1
  54. data/lib/jsapi/meta/schema/array.rb +1 -1
  55. data/lib/jsapi/meta/schema/base.rb +5 -5
  56. data/lib/jsapi/meta/schema/discriminator.rb +2 -2
  57. data/lib/jsapi/meta/schema/object.rb +3 -3
  58. data/lib/jsapi/meta/schema/reference.rb +1 -1
  59. data/lib/jsapi/meta/schema.rb +2 -2
  60. data/lib/jsapi/meta/security_requirement.rb +25 -0
  61. data/lib/jsapi/meta/security_scheme/api_key.rb +38 -0
  62. data/lib/jsapi/meta/security_scheme/base.rb +14 -0
  63. data/lib/jsapi/meta/security_scheme/http/basic.rb +34 -0
  64. data/lib/jsapi/meta/security_scheme/http/bearer.rb +36 -0
  65. data/lib/jsapi/meta/security_scheme/http/other.rb +36 -0
  66. data/lib/jsapi/meta/security_scheme/http.rb +29 -0
  67. data/lib/jsapi/meta/security_scheme/oauth2.rb +44 -0
  68. data/lib/jsapi/meta/security_scheme/open_id_connect.rb +32 -0
  69. data/lib/jsapi/meta/security_scheme.rb +49 -0
  70. data/lib/jsapi/meta/server.rb +34 -0
  71. data/lib/jsapi/meta/server_variable.rb +34 -0
  72. data/lib/jsapi/meta/tag.rb +34 -0
  73. data/lib/jsapi/meta.rb +15 -1
  74. data/lib/jsapi/model/base.rb +5 -5
  75. data/lib/jsapi/version.rb +1 -1
  76. data/lib/jsapi.rb +1 -1
  77. metadata +40 -44
  78. data/lib/jsapi/dsl/node.rb +0 -62
  79. data/lib/jsapi/dsl/openapi/callback.rb +0 -23
  80. data/lib/jsapi/dsl/openapi/callbacks.rb +0 -34
  81. data/lib/jsapi/dsl/openapi/examples.rb +0 -32
  82. data/lib/jsapi/dsl/openapi/root.rb +0 -126
  83. data/lib/jsapi/dsl/openapi.rb +0 -6
  84. data/lib/jsapi/meta/openapi/callback/model.rb +0 -34
  85. data/lib/jsapi/meta/openapi/callback/reference.rb +0 -16
  86. data/lib/jsapi/meta/openapi/callback.rb +0 -21
  87. data/lib/jsapi/meta/openapi/contact.rb +0 -32
  88. data/lib/jsapi/meta/openapi/example/model.rb +0 -44
  89. data/lib/jsapi/meta/openapi/example/reference.rb +0 -16
  90. data/lib/jsapi/meta/openapi/example.rb +0 -21
  91. data/lib/jsapi/meta/openapi/external_documentation.rb +0 -27
  92. data/lib/jsapi/meta/openapi/header/model.rb +0 -82
  93. data/lib/jsapi/meta/openapi/header/reference.rb +0 -16
  94. data/lib/jsapi/meta/openapi/header.rb +0 -21
  95. data/lib/jsapi/meta/openapi/info.rb +0 -54
  96. data/lib/jsapi/meta/openapi/license.rb +0 -27
  97. data/lib/jsapi/meta/openapi/link/model.rb +0 -50
  98. data/lib/jsapi/meta/openapi/link/reference.rb +0 -16
  99. data/lib/jsapi/meta/openapi/link.rb +0 -21
  100. data/lib/jsapi/meta/openapi/oauth_flow.rb +0 -52
  101. data/lib/jsapi/meta/openapi/root.rb +0 -132
  102. data/lib/jsapi/meta/openapi/security_requirement.rb +0 -27
  103. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +0 -40
  104. data/lib/jsapi/meta/openapi/security_scheme/base.rb +0 -16
  105. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +0 -36
  106. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +0 -39
  107. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +0 -39
  108. data/lib/jsapi/meta/openapi/security_scheme/http.rb +0 -31
  109. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +0 -46
  110. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +0 -34
  111. data/lib/jsapi/meta/openapi/security_scheme.rb +0 -51
  112. data/lib/jsapi/meta/openapi/server.rb +0 -36
  113. data/lib/jsapi/meta/openapi/server_variable.rb +0 -36
  114. data/lib/jsapi/meta/openapi/tag.rb +0 -36
@@ -3,6 +3,7 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  module Response
6
+ # Defines a response.
6
7
  class Model < Base::Model
7
8
  include OpenAPI::Extensions
8
9
 
@@ -15,23 +16,23 @@ module Jsapi
15
16
 
16
17
  ##
17
18
  # :attr: description
18
- # The optional description of the response.
19
+ # The description of the response.
19
20
  attribute :description, String
20
21
 
21
22
  ##
22
23
  # :attr: examples
23
- # The optional examples.
24
- attribute :examples, { String => OpenAPI::Example }, default_key: 'default'
24
+ # The Example objects.
25
+ attribute :examples, { String => Example }, default_key: 'default'
25
26
 
26
27
  ##
27
28
  # :attr: headers
28
- # The response headers.
29
- attribute :headers, { String => OpenAPI::Header }
29
+ # The Header objects.
30
+ attribute :headers, { String => Header }
30
31
 
31
32
  ##
32
33
  # :attr: links
33
- # The optional OpenAPI::Link objects.
34
- attribute :links, { String => OpenAPI::Link }
34
+ # The Link objects.
35
+ attribute :links, { String => Link }
35
36
 
36
37
  ##
37
38
  # :attr: locale
@@ -66,11 +67,11 @@ module Jsapi
66
67
  {
67
68
  description: description,
68
69
  schema: schema.to_openapi(version),
69
- headers: headers&.transform_values do |header|
70
+ headers: headers.transform_values do |header|
70
71
  header.to_openapi(version) unless header.reference?
71
- end&.compact,
72
+ end.compact.presence,
72
73
  examples: (
73
- if (example = examples&.values&.first).present?
74
+ if (example = examples.values.first).present?
74
75
  { content_type => example.resolve(definitions).value }
75
76
  end
76
77
  )
@@ -81,11 +82,13 @@ module Jsapi
81
82
  content: {
82
83
  content_type => {
83
84
  schema: schema.to_openapi(version),
84
- examples: examples&.transform_values(&:to_openapi)
85
+ examples: examples.transform_values(&:to_openapi).presence
85
86
  }.compact
86
87
  },
87
- headers: headers&.transform_values { |header| header.to_openapi(version) },
88
- links: links&.transform_values(&:to_openapi)
88
+ headers: headers.transform_values do |header|
89
+ header.to_openapi(version)
90
+ end.presence,
91
+ links: links.transform_values(&:to_openapi).presence
89
92
  }
90
93
  end
91
94
  )
@@ -7,7 +7,7 @@ module Jsapi
7
7
  module Meta
8
8
  module Response
9
9
  class << self
10
- # Creates a new response model or reference.
10
+ # Creates a Model or Reference.
11
11
  def new(keywords = {})
12
12
  return Reference.new(keywords) if keywords.key?(:ref)
13
13
 
@@ -43,7 +43,7 @@ module Jsapi
43
43
  super.merge(items: items&.to_json_schema || {})
44
44
  end
45
45
 
46
- def to_openapi(version) # :nodoc:
46
+ def to_openapi(version, *) # :nodoc:
47
47
  super.merge(items: items&.to_openapi(version) || {})
48
48
  end
49
49
  end
@@ -34,7 +34,7 @@ module Jsapi
34
34
  ##
35
35
  # :attr: external_docs
36
36
  # The OpenAPI::ExternalDocumentation object.
37
- attribute :external_docs, OpenAPI::ExternalDocumentation
37
+ attribute :external_docs, ExternalDocumentation
38
38
 
39
39
  ##
40
40
  # :attr: existence
@@ -104,7 +104,7 @@ module Jsapi
104
104
  end
105
105
 
106
106
  # Returns a hash representing the \OpenAPI schema object.
107
- def to_openapi(version)
107
+ def to_openapi(version, *)
108
108
  version = OpenAPI::Version.from(version)
109
109
 
110
110
  with_openapi_extensions(
@@ -112,21 +112,21 @@ module Jsapi
112
112
  # OpenAPI 2.0
113
113
  {
114
114
  type: type,
115
- example: examples&.first
115
+ example: examples.first
116
116
  }
117
117
  elsif version.minor.zero?
118
118
  # OpenAPI 3.0
119
119
  {
120
120
  type: type,
121
121
  nullable: nullable?.presence,
122
- examples: examples,
122
+ examples: examples.presence,
123
123
  deprecated: deprecated?.presence
124
124
  }
125
125
  else
126
126
  # OpenAPI 3.1
127
127
  {
128
128
  type: nullable? ? [type, 'null'] : type,
129
- examples: examples,
129
+ examples: examples.presence,
130
130
  deprecated: deprecated?.presence
131
131
  }
132
132
  end.tap do |hash|
@@ -13,13 +13,13 @@ module Jsapi
13
13
  attribute :property_name, String
14
14
 
15
15
  # Returns a hash representing the \OpenAPI discriminator object.
16
- def to_openapi(version)
16
+ def to_openapi(version, *)
17
17
  version = OpenAPI::Version.from(version)
18
18
  return property_name if version.major == 2
19
19
 
20
20
  {
21
21
  propertyName: property_name,
22
- mapping: mappings&.transform_keys(&:to_s)
22
+ mapping: mappings.transform_keys(&:to_s).presence
23
23
  }.compact
24
24
  end
25
25
  end
@@ -11,7 +11,7 @@ module Jsapi
11
11
 
12
12
  ##
13
13
  # :attr: all_of_references
14
- attribute :all_of_references, [Reference], default: []
14
+ attribute :all_of_references, [Reference]
15
15
 
16
16
  alias :all_of= :all_of_references= # :nodoc:
17
17
  alias :add_all_of :add_all_of_reference
@@ -30,7 +30,7 @@ module Jsapi
30
30
  ##
31
31
  # :attr: properties
32
32
  # The properties.
33
- attribute :properties, { String => Property }, default: {}
33
+ attribute :properties, { String => Property }
34
34
 
35
35
  undef add_property
36
36
 
@@ -83,7 +83,7 @@ module Jsapi
83
83
  ).compact
84
84
  end
85
85
 
86
- def to_openapi(version) # :nodoc:
86
+ def to_openapi(version, *) # :nodoc:
87
87
  super.merge(
88
88
  allOf: all_of_references.map do |schema|
89
89
  schema.to_openapi(version)
@@ -22,7 +22,7 @@ module Jsapi
22
22
  end
23
23
 
24
24
  # Returns a hash representing the \OpenAPI reference object.
25
- def to_openapi(version)
25
+ def to_openapi(version, *)
26
26
  version = OpenAPI::Version.from(version)
27
27
  path = version.major == 2 ? 'definitions' : 'components/schemas'
28
28
 
@@ -27,8 +27,8 @@ module Jsapi
27
27
  end
28
28
 
29
29
  class << self
30
- # Creates a new schema model or reference. The +:type+ keyword determines
31
- # the type of the schema to be created. Possible types are:
30
+ # Creates a new schema. The +:type+ keyword determines the type of the schema to be
31
+ # created. Possible types are:
32
32
  #
33
33
  # - <code>"array"</code>
34
34
  # - <code>"boolean"</code>
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ # Specifies a security requirement object.
6
+ class SecurityRequirement < Base::Model
7
+ class Scheme < Base::Model
8
+ ##
9
+ # :attr: scopes
10
+ # The array of scopes.
11
+ attribute :scopes, [String]
12
+ end
13
+
14
+ ##
15
+ # :attr_reader: schemes
16
+ # The schemes.
17
+ attribute :schemes, { String => Scheme }
18
+
19
+ # Returns a hash representing the \OpenAPI security requirement object.
20
+ def to_openapi(*)
21
+ schemes.transform_values(&:scopes)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ # Specifies a security scheme based on an API key.
7
+ class APIKey < Base
8
+ include OpenAPI::Extensions
9
+
10
+ ##
11
+ # :attr: in
12
+ # The location of the API key. Possible values are:
13
+ #
14
+ # - <code>"cookie"</code>
15
+ # - <code>"header"</code>
16
+ # - <code>"query"</code>
17
+ #
18
+ attribute :in, String, values: %w[cookie header query]
19
+
20
+ ##
21
+ # :attr: name
22
+ # The name of the header, query parameter or cookie the
23
+ # API key is sent by.
24
+ attribute :name, String
25
+
26
+ # Returns a hash representing the \OpenAPI security scheme object.
27
+ def to_openapi(*)
28
+ with_openapi_extensions(
29
+ type: 'apiKey',
30
+ name: name,
31
+ in: self.in,
32
+ description: description
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ class Base < Meta::Base::Model
7
+ ##
8
+ # :attr: description
9
+ # The description of the security scheme.
10
+ attribute :description, String
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ module HTTP
7
+ # Specifies a security scheme based on \HTTP basic authentication.
8
+ class Basic < Base
9
+ include OpenAPI::Extensions
10
+
11
+ # Returns a hash representing the \OpenAPI security scheme object.
12
+ def to_openapi(version, *)
13
+ version = OpenAPI::Version.from(version)
14
+
15
+ with_openapi_extensions(
16
+ if version.major == 2
17
+ {
18
+ type: 'basic',
19
+ description: description
20
+ }
21
+ else
22
+ {
23
+ type: 'http',
24
+ scheme: 'basic',
25
+ description: description
26
+ }
27
+ end
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ module HTTP
7
+ # Specifies a security scheme based on bearer authentication.
8
+ #
9
+ # Note that Bearer authentication was introduced with \OpenAPI 3.0. Thus, a security
10
+ # scheme of this class is skipped when generating an \OpenAPI 2.0 document.
11
+ class Bearer < Base
12
+ include OpenAPI::Extensions
13
+
14
+ ##
15
+ # :attr: bearer_format
16
+ # The format of the bearer token.
17
+ attribute :bearer_format, String
18
+
19
+ # Returns a hash representing the \OpenAPI security scheme object, or
20
+ # +nil+ if <code>version.major</code> is 2.
21
+ def to_openapi(version, *)
22
+ version = OpenAPI::Version.from(version)
23
+ return if version.major == 2
24
+
25
+ with_openapi_extensions(
26
+ type: 'http',
27
+ scheme: 'bearer',
28
+ bearerFormat: bearer_format,
29
+ description: description
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ module HTTP
7
+ # Specifies a security scheme based on any other \HTTP authentication than basic
8
+ # and bearer.
9
+ #
10
+ # Note that \OpenAPI 2.0 supports \HTTP basic authentication only. Thus, a security
11
+ # scheme of this class is skipped when generating an \OpenAPI 2.0 document.
12
+ class Other < Base
13
+ include OpenAPI::Extensions
14
+
15
+ ##
16
+ # :attr: scheme
17
+ # The mandatory \HTTP authentication scheme.
18
+ attribute :scheme, String
19
+
20
+ # Returns a hash representing the \OpenAPI security scheme object, or +nil+
21
+ # if <code>version.major</code> is 2.
22
+ def to_openapi(version, *)
23
+ version = OpenAPI::Version.from(version)
24
+ return if version.major == 2
25
+
26
+ with_openapi_extensions(
27
+ type: 'http',
28
+ scheme: scheme,
29
+ description: description
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'http/basic'
4
+ require_relative 'http/bearer'
5
+ require_relative 'http/other'
6
+
7
+ module Jsapi
8
+ module Meta
9
+ module SecurityScheme
10
+ module HTTP
11
+ class << self
12
+ # Creates a new \HTTP authentication scheme.
13
+ def new(keywords = {})
14
+ scheme = keywords[:scheme] || 'basic'
15
+
16
+ case scheme.to_s
17
+ when 'basic'
18
+ HTTP::Basic.new(keywords.except(:scheme))
19
+ when 'bearer'
20
+ HTTP::Bearer.new(keywords.except(:scheme))
21
+ else
22
+ HTTP::Other.new(keywords)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ # Specifies a security scheme based on \OAuth2.
7
+ class OAuth2 < Base
8
+ include OpenAPI::Extensions
9
+
10
+ ##
11
+ # :attr: oauth_flows
12
+ # The hash containing the OAuth flows. Possible keys are:
13
+ #
14
+ # - <code>"authorization_code"</code>
15
+ # - <code>"client_credentials"</code>
16
+ # - <code>"implicit"</code>
17
+ # - <code>"password"</code>
18
+ #
19
+ # Values are OAuthFlow objects.
20
+ attribute :oauth_flows, { String => OAuthFlow },
21
+ keys: %w[authorization_code client_credentials implicit password]
22
+
23
+ # Returns a hash representing the \OpenAPI security scheme object.
24
+ def to_openapi(version, *)
25
+ version = OpenAPI::Version.from(version)
26
+
27
+ with_openapi_extensions(type: 'oauth2', description: description).tap do |h|
28
+ if oauth_flows.any?
29
+ if version.major == 2
30
+ key, oauth_flow = oauth_flows.first
31
+ h[:flow] = key.to_s
32
+ h.merge!(oauth_flow.to_openapi(version))
33
+ else
34
+ h[:flows] = oauth_flows.to_h do |key, value|
35
+ [key.to_s.camelize(:lower).to_sym, value.to_openapi(version)]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module SecurityScheme
6
+ # Specifies a security scheme based on OpenID Connect.
7
+ #
8
+ # OpenID Connect was introduced with \OpenAPI 3.0. Thus, a security scheme of
9
+ # this class is skipped when generating an \OpenAPI 2.0 document.
10
+ class OpenIDConnect < Base
11
+ include OpenAPI::Extensions
12
+
13
+ ##
14
+ # :attr: open_id_connect_url
15
+ attribute :open_id_connect_url, String
16
+
17
+ # Returns a hash representing the \OpenAPI security scheme object, or +nil+
18
+ # if <code>version.major</code> is 2.
19
+ def to_openapi(version, *)
20
+ version = OpenAPI::Version.from(version)
21
+ return if version.major == 2
22
+
23
+ with_openapi_extensions(
24
+ type: 'openIdConnect',
25
+ openIdConnectUrl: open_id_connect_url,
26
+ description: description
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'security_scheme/base'
4
+ require_relative 'security_scheme/api_key'
5
+ require_relative 'security_scheme/http'
6
+ require_relative 'security_scheme/oauth2'
7
+ require_relative 'security_scheme/open_id_connect'
8
+
9
+ module Jsapi
10
+ module Meta
11
+ module SecurityScheme
12
+ class << self
13
+ # Creates a security scheme. The +:type+ keyword specifies the type
14
+ # of the security scheme to be created. Possible types are:
15
+ #
16
+ # - <code>"api_key"</code>
17
+ # - <code>"basic"</code>
18
+ # - <code>"http"</code>
19
+ # - <code>"oauth2"</code>
20
+ # - <code>"open_id_connect"</code>
21
+ #
22
+ # Raises an InvalidArgumentError if the given type is invalid.
23
+ def new(keywords = {})
24
+ type = keywords[:type]
25
+ keywords = keywords.except(:type)
26
+
27
+ case type&.to_s
28
+ when 'api_key'
29
+ APIKey.new(keywords)
30
+ when 'basic' # OpenAPI 2.0
31
+ HTTP.new(keywords.merge(scheme: 'basic'))
32
+ when 'http' # OpenAPI 3.0 and higher
33
+ HTTP.new(keywords)
34
+ when 'oauth2'
35
+ OAuth2.new(keywords)
36
+ when 'open_id_connect' # OpenAPI 3.0 and higher
37
+ OpenIDConnect.new(keywords)
38
+ else
39
+ raise InvalidArgumentError.new(
40
+ 'type',
41
+ type,
42
+ valid_values: %w[api_key basic http oauth2 open_id_connect]
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ # Specifiess a server object.
6
+ class Server < Base::Model
7
+ include OpenAPI::Extensions
8
+
9
+ ##
10
+ # :attr: description
11
+ # The description of the server.
12
+ attribute :description, String
13
+
14
+ ##
15
+ # :attr: url
16
+ # The absolute or relative URL of the server.
17
+ attribute :url, String
18
+
19
+ ##
20
+ # :attr_reader: variables
21
+ # The ServerVariable objects.
22
+ attribute :variables, { String => ServerVariable }
23
+
24
+ # Returns a hash representing the \OpenAPI server object.
25
+ def to_openapi(*)
26
+ with_openapi_extensions(
27
+ url: url,
28
+ description: description,
29
+ variables: variables.transform_values(&:to_openapi).presence
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ # Specifies a server variable object.
6
+ class ServerVariable < Base::Model
7
+ include OpenAPI::Extensions
8
+
9
+ ##
10
+ # :attr: default
11
+ # The default value of the server variable.
12
+ attribute :default, String
13
+
14
+ ##
15
+ # :attr: description
16
+ # The description of the server variable.
17
+ attribute :description, String
18
+
19
+ ##
20
+ # :attr: enum
21
+ # The values of the server variable.
22
+ attribute :enum, [String]
23
+
24
+ # Returns a hash representing the \OpenAPI server variable object.
25
+ def to_openapi(*)
26
+ with_openapi_extensions(
27
+ default: default,
28
+ enum: enum.presence,
29
+ description: description
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ # Specifies a tag object.
6
+ class Tag < Base::Model
7
+ include OpenAPI::Extensions
8
+
9
+ ##
10
+ # :attr: description
11
+ # The description of the tag.
12
+ attribute :description, String
13
+
14
+ ##
15
+ # :attr: external_docs
16
+ # The ExternalDocumentation object.
17
+ attribute :external_docs, ExternalDocumentation
18
+
19
+ ##
20
+ # :attr: name
21
+ # The name of the tag.
22
+ attribute :name, String
23
+
24
+ # Returns a hash representing the \OpenAPI tag object.
25
+ def to_openapi(*)
26
+ with_openapi_extensions(
27
+ name: name,
28
+ description: description,
29
+ externalDocs: external_docs&.to_openapi
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/jsapi/meta.rb CHANGED
@@ -3,9 +3,23 @@
3
3
  require_relative 'meta/reference_error'
4
4
  require_relative 'meta/callable'
5
5
  require_relative 'meta/existence'
6
+ require_relative 'meta/openapi'
6
7
  require_relative 'meta/base'
7
8
  require_relative 'meta/defaults'
8
- require_relative 'meta/openapi'
9
+ require_relative 'meta/example'
10
+ require_relative 'meta/external_documentation'
11
+ require_relative 'meta/tag'
12
+ require_relative 'meta/server_variable'
13
+ require_relative 'meta/server'
14
+ require_relative 'meta/callback'
15
+ require_relative 'meta/contact'
16
+ require_relative 'meta/license'
17
+ require_relative 'meta/info'
18
+ require_relative 'meta/header'
19
+ require_relative 'meta/oauth_flow'
20
+ require_relative 'meta/security_scheme'
21
+ require_relative 'meta/security_requirement'
22
+ require_relative 'meta/link'
9
23
  require_relative 'meta/property'
10
24
  require_relative 'meta/schema'
11
25
  require_relative 'meta/request_body'