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,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'callback/model'
4
+ require_relative 'callback/reference'
5
+
6
+ module Jsapi
7
+ module Meta
8
+ module OpenAPI
9
+ module Callback
10
+ class << self
11
+ # Creates a callback model or reference.
12
+ def new(keywords = {})
13
+ return Reference.new(keywords) if keywords.key?(:ref)
14
+
15
+ Model.new(keywords)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents a contact object.
7
+ class Contact < Base
8
+ ##
9
+ # :attr: email
10
+ # The email address of the contact.
11
+ attribute :email, String
12
+
13
+ ##
14
+ # :attr: name
15
+ # The name of the contact.
16
+ attribute :name, String
17
+
18
+ ##
19
+ # :attr: url
20
+ # The URL of the contact.
21
+ attribute :url, String
22
+
23
+ # Returns a hash representing the contact object.
24
+ def to_openapi(*)
25
+ {
26
+ name: name,
27
+ url: url,
28
+ email: email
29
+ }.compact
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents an external documentation object.
7
+ class ExternalDocumentation < Base
8
+ ##
9
+ # :attr: description
10
+ # The optional description of the external documentation.
11
+ attribute :description, String
12
+
13
+ ##
14
+ # :attr: url
15
+ # The URL of the external documentation.
16
+ attribute :url, String
17
+
18
+ # Returns a hash representing the external documentation object.
19
+ def to_openapi(*)
20
+ {
21
+ url: url,
22
+ description: description
23
+ }.compact
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents an info object.
7
+ class Info < Base
8
+ ##
9
+ # :attr: contact
10
+ # The optional Contact object.
11
+ attribute :contact, Contact
12
+
13
+ ##
14
+ # :attr: description
15
+ # The optional description of the API.
16
+ attribute :description, String
17
+
18
+ ##
19
+ # :attr: license
20
+ # The optional License object.
21
+ attribute :license, License
22
+
23
+ ##
24
+ # :attr: terms_of_service
25
+ # The optional URL pointing to the terms of service.
26
+ attribute :terms_of_service, String
27
+
28
+ ##
29
+ # :attr: title
30
+ # The title of the API.
31
+ attribute :title, String
32
+
33
+ ##
34
+ # :attr: version
35
+ # The version of the API.
36
+ attribute :version, String
37
+
38
+ # Returns a hash representing the info object.
39
+ def to_openapi(*)
40
+ {
41
+ title: title,
42
+ version: version,
43
+ description: description,
44
+ termsOfService: terms_of_service,
45
+ contact: contact&.to_openapi,
46
+ license: license&.to_openapi
47
+ }.compact
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents a license object.
7
+ class License < Base
8
+ ##
9
+ # :attr: name
10
+ # The name of the license.
11
+ attribute :name, String
12
+
13
+ ##
14
+ # :attr: url
15
+ # The optional URL of the license.
16
+ attribute :url, String
17
+
18
+ # Returns a hash representing the license object.
19
+ def to_openapi(*)
20
+ {
21
+ name: name,
22
+ url: url
23
+ }.compact
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Link
7
+ # Represents a link object.
8
+ class Model < Base
9
+ ##
10
+ # :attr: description
11
+ # The optional description of the link.
12
+ attribute :description, String
13
+
14
+ ##
15
+ # :attr: operation_id
16
+ # The operation ID.
17
+ attribute :operation_id, String
18
+
19
+ ##
20
+ # :attr: parameters
21
+ # The optional parameters to be passed.
22
+ attribute :parameters, { String => Object }
23
+
24
+ ##
25
+ # :attr: request_body
26
+ # The optional request body to be passed.
27
+ attribute :request_body
28
+
29
+ ##
30
+ # :attr: server
31
+ # The optional Server object.
32
+ attribute :server, Server
33
+
34
+ # Returns a hash representing the link object.
35
+ def to_openapi(*)
36
+ {
37
+ operationId: operation_id,
38
+ parameters: parameters,
39
+ requestBody: request_body,
40
+ description: description,
41
+ server: server&.to_openapi
42
+ }.compact
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Link
7
+ class Reference < BaseReference
8
+ # Returns a hash representing the \OpenAPI reference object.
9
+ def to_openapi(*)
10
+ { '$ref': "#/components/links/#{ref}" }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'link/model'
4
+ require_relative 'link/reference'
5
+
6
+ module Jsapi
7
+ module Meta
8
+ module OpenAPI
9
+ module Link
10
+ class << self
11
+ # Creates a link model or reference.
12
+ def new(keywords = {})
13
+ return Reference.new(keywords) if keywords.key?(:ref)
14
+
15
+ Model.new(keywords)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents an OAuth flow object.
7
+ class OAuthFlow < Base
8
+ class Scope < Base
9
+ ##
10
+ # :attr: description
11
+ # The optional description of the scope.
12
+ attribute :description, String, default: ''
13
+ end
14
+
15
+ ##
16
+ # :attr: authorization_url
17
+ # The authorization URL to be used for the flow.
18
+ attribute :authorization_url, String
19
+
20
+ ##
21
+ # :attr: refresh_url
22
+ # The refresh URL to be used for the flow.
23
+ #
24
+ # Note that the refresh URL was introduced with \OpenAPI 3.0. It is
25
+ # skipped when generating an \OpenAPI 2.0 document.
26
+ attribute :refresh_url, String
27
+
28
+ ##
29
+ # :attr: scopes
30
+ # The hash containing the scopes.
31
+ attribute :scopes, { String => Scope }, default: {}
32
+
33
+ ##
34
+ # :attr: token_url
35
+ # The token URL to be used for the flow.
36
+ attribute :token_url, String
37
+
38
+ # Returns a hash representing the OAuth flow object.
39
+ def to_openapi(version)
40
+ {
41
+ authorizationUrl: authorization_url,
42
+ tokenUrl: token_url,
43
+ refreshUrl: (refresh_url if version.major > 2),
44
+ scopes: scopes.transform_values(&:description)
45
+ }.compact
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents an \OpenAPI object.
7
+ class Root < Base
8
+ ##
9
+ # :attr: callbacks
10
+ # The reusable Callback objects. Applies to \OpenAPI 3.x.
11
+ attribute :callbacks, { String => Callback }
12
+
13
+ ##
14
+ # :attr: base_path
15
+ # The base path of the API. Applies to \OpenAPI 2.0.
16
+ attribute :base_path, String
17
+
18
+ ##
19
+ # :attr: consumes
20
+ # The MIME types the API can consume. Applies to \OpenAPI 2.0.
21
+ attribute :consumed_mime_types, [String]
22
+
23
+ alias :consumes :consumed_mime_types
24
+ alias :consumes= :consumed_mime_types=
25
+ alias :add_consumes :add_consumed_mime_type
26
+
27
+ ##
28
+ # :attr: external_docs
29
+ # The optional ExternalDocumentation object.
30
+ attribute :external_docs, ExternalDocumentation
31
+
32
+ ##
33
+ # :attr: host
34
+ # The host serving the API. Applies to \OpenAPI 2.0.
35
+ attribute :host, String
36
+
37
+ ##
38
+ # :attr: info
39
+ # The Info object.
40
+ attribute :info, Info
41
+
42
+ ##
43
+ # :attr: links
44
+ # The reusable Link objects. Applies to \OpenAPI 3.x.
45
+ attribute :links, { String => Link }
46
+
47
+ ##
48
+ # :attr: produces
49
+ # The MIME types the API can produce. Applies to \OpenAPI 2.0.
50
+ attribute :produced_mime_types, [String]
51
+
52
+ alias :produces :produced_mime_types
53
+ alias :produces= :produced_mime_types=
54
+ alias :add_produces :add_produced_mime_type
55
+
56
+ ##
57
+ # :attr: schemes
58
+ # The array of transfer protocols supported by the API. Possible
59
+ # values are:
60
+ #
61
+ # - <code>"http"</code>
62
+ # - <code>"https"</code>
63
+ # - <code>"ws"</code>
64
+ # - <code>"wss"</code>
65
+ #
66
+ # Applies to \OpenAPI 2.0.
67
+ attribute :schemes, [String], values: %w[http https ws wss]
68
+
69
+ ##
70
+ # :attr: security_requirements
71
+ # The array of SecurityRequirement objects.
72
+ attribute :security_requirements, [SecurityRequirement]
73
+
74
+ alias add_security add_security_requirement
75
+
76
+ ##
77
+ # :attr_reader: security_schemes
78
+ # The security schemes.
79
+ attribute :security_schemes, { String => SecurityScheme }
80
+
81
+ ##
82
+ # :attr: servers
83
+ # The array of Server objects. Applies to \OpenAPI 3.x.
84
+ attribute :servers, [Server]
85
+
86
+ ##
87
+ # :attr: tags
88
+ # The array of Tag objects.
89
+ attribute :tags, [Tag]
90
+
91
+ # Returns a hash representing the \OpenAPI object.
92
+ def to_openapi(version, definitions)
93
+ version = Version.from(version)
94
+ security_schemes =
95
+ self.security_schemes&.transform_values do |value|
96
+ value.to_openapi(version)
97
+ end
98
+
99
+ if version.major == 2
100
+ {
101
+ swagger: '2.0',
102
+ info: info&.to_openapi,
103
+ host: host,
104
+ basePath: base_path,
105
+ schemes: schemes,
106
+ consumes: consumed_mime_types,
107
+ produces: produced_mime_types,
108
+ securityDefinitions: security_schemes,
109
+ security: security_requirements&.map(&:to_openapi),
110
+ tags: tags&.map(&:to_openapi),
111
+ externalDocs: external_docs&.to_openapi
112
+ }
113
+ else
114
+ {
115
+ openapi: version.minor.zero? ? '3.0.3' : '3.1.0',
116
+ info: info&.to_openapi,
117
+ servers: servers&.map(&:to_openapi),
118
+ components: {
119
+ callbacks: callbacks&.transform_values do |callback|
120
+ callback.to_openapi(version, definitions)
121
+ end,
122
+ links: links&.transform_values(&:to_openapi),
123
+ securitySchemes: security_schemes
124
+ }.compact.presence,
125
+ security: security_requirements&.map(&:to_openapi),
126
+ tags: tags&.map(&:to_openapi),
127
+ externalDocs: external_docs&.to_openapi
128
+ }
129
+ end.compact
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ # Represents a security requirement object.
7
+ class SecurityRequirement < Base
8
+ class Scheme < Base
9
+ ##
10
+ # :attr: scopes
11
+ # The array of scopes.
12
+ attribute :scopes, [String], default: []
13
+ end
14
+
15
+ ##
16
+ # :attr_reader: schemes
17
+ # The schemes.
18
+ attribute :schemes, { String => Scheme }
19
+
20
+ # Returns a hash representing the security requirement object.
21
+ def to_openapi(*)
22
+ schemes&.transform_values(&:scopes) || {}
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module SecurityScheme
7
+ # Represents a security scheme based on an API key.
8
+ class APIKey < Base
9
+ ##
10
+ # :attr: in
11
+ # The location of the API key. Possible values are:
12
+ #
13
+ # - <code>"cookie"</code>
14
+ # - <code>"header"</code>
15
+ # - <code>"query"</code>
16
+ #
17
+ attribute :in, String, values: %w[cookie header query]
18
+
19
+ ##
20
+ # :attr: name
21
+ # The name of the header, query parameter or cookie the
22
+ # API key is sent by.
23
+ attribute :name, String
24
+
25
+ # Returns a hash representing the security scheme object.
26
+ def to_openapi(*)
27
+ {
28
+ type: 'apiKey',
29
+ name: name,
30
+ in: self.in,
31
+ description: description
32
+ }.compact
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module SecurityScheme
7
+ class Base < Meta::Base
8
+ ##
9
+ # :attr: description
10
+ # The optional description of the security scheme.
11
+ attribute :description, String
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module SecurityScheme
7
+ module HTTP
8
+ # Represents a security scheme based on \HTTP basic authentication.
9
+ class Basic < Base
10
+ # Returns a hash representing the security scheme object.
11
+ def to_openapi(version)
12
+ version = OpenAPI::Version.from(version)
13
+ if version.major == 2
14
+ {
15
+ type: 'basic',
16
+ description: description
17
+ }
18
+ else
19
+ {
20
+ type: 'http',
21
+ scheme: 'basic',
22
+ description: description
23
+ }
24
+ end.compact
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module SecurityScheme
7
+ module HTTP
8
+ # Represents a security scheme based on bearer authentication.
9
+ #
10
+ # Note that Bearer authentication was introduced with \OpenAPI 3.0.
11
+ # Thus, a security scheme of this class is skipped when generating
12
+ # an \OpenAPI 2.0 document.
13
+ class Bearer < Base
14
+ ##
15
+ # :attr: bearer_format
16
+ # The optional format of the bearer token.
17
+ attribute :bearer_format, String
18
+
19
+ # Returns a hash representing the 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
+ {
26
+ type: 'http',
27
+ scheme: 'bearer',
28
+ bearerFormat: bearer_format,
29
+ description: description
30
+ }.compact
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module SecurityScheme
7
+ module HTTP
8
+ # Represents a security scheme based on any other \HTTP authentication
9
+ # than basic and bearer.
10
+ #
11
+ # Note that \OpenAPI 2.0 supports \HTTP basic authentication only. Thus,
12
+ # a security scheme of this class is skipped when generating an
13
+ # \OpenAPI 2.0 document.
14
+ class Other < Base
15
+ ##
16
+ # :attr: scheme
17
+ # The mandatory \HTTP authentication scheme.
18
+ attribute :scheme, String
19
+
20
+ # Returns a hash representing the 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
+ {
27
+ type: 'http',
28
+ scheme: scheme,
29
+ description: description
30
+ }.compact
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
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 OpenAPI
10
+ module SecurityScheme
11
+ module HTTP
12
+ class << self
13
+ # Creates a new \HTTP authentication scheme.
14
+ def new(keywords = {})
15
+ scheme = keywords[:scheme] || 'basic'
16
+
17
+ case scheme.to_s
18
+ when 'basic'
19
+ HTTP::Basic.new(keywords.except(:scheme))
20
+ when 'bearer'
21
+ HTTP::Bearer.new(keywords.except(:scheme))
22
+ else
23
+ HTTP::Other.new(keywords)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end