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
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents an external documentation object.
7
- class ExternalDocumentation < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: description
12
- # The optional description of the external documentation.
13
- attribute :description, String
14
-
15
- ##
16
- # :attr: url
17
- # The URL of the external documentation.
18
- attribute :url, String
19
-
20
- # Returns a hash representing the \OpenAPI external documentation object.
21
- def to_openapi(*)
22
- with_openapi_extensions(url: url, description: description)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- module Header
7
- class Model < Meta::Base::Model
8
- include Extensions
9
-
10
- delegate_missing_to :schema
11
-
12
- ##
13
- # :attr: collection_format
14
- # The collection format of a header whose values are arrays. Possible values are:
15
- #
16
- # - <code>"csv"</code> - comma separated values
17
- # - <code>"pipes"</code> - pipe separated values
18
- # - <code>"ssv"</code> - space separated values
19
- # - <code>"tsv"</code> - tab separated values
20
- #
21
- # Applies to \OpenAPI 2.0.
22
- attribute :collection_format, values: %w[csv pipes ssv tsv]
23
-
24
- ##
25
- # :attr: deprecated
26
- # Specifies whether or not the header is deprecated.
27
- attribute :deprecated, values: [true, false]
28
-
29
- ##
30
- # :attr: description
31
- # The description of the header.
32
- attribute :description, String
33
-
34
- ##
35
- # :attr_reader: examples
36
- # One or more example values.
37
- attribute :examples, { String => Example }, default_key: 'default'
38
-
39
- ##
40
- # :attr_reader: schema
41
- # The Schema of the header.
42
- attribute :schema, read_only: true
43
-
44
- def initialize(keywords = {})
45
- raise ArgumentError, "type can't be object" if keywords[:type] == 'object'
46
-
47
- keywords = keywords.dup
48
- super(
49
- keywords.extract!(
50
- :collection_format, :deprecated, :description, :examples, :openapi_extensions
51
- )
52
- )
53
- add_example(value: keywords.delete(:example)) if keywords.key?(:example)
54
-
55
- @schema = Schema.new(keywords)
56
- end
57
-
58
- # Returns a hash representing the \OpenAPI header object.
59
- def to_openapi(version)
60
- version = OpenAPI::Version.from(version)
61
-
62
- with_openapi_extensions(
63
- if version.major == 2
64
- schema.to_openapi(version).merge(
65
- collection_format: (collection_format if array?),
66
- description: description
67
- )
68
- else
69
- {
70
- description: description,
71
- deprecated: deprecated?.presence,
72
- schema: schema.to_openapi(version),
73
- examples: examples&.transform_values(&:to_openapi)
74
- }
75
- end
76
- )
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- module Header
7
- class Reference < Meta::Base::Reference
8
- # Returns a hash representing the \OpenAPI reference object.
9
- def to_openapi(*)
10
- { '$ref': "#/components/headers/#{ref}" }
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'header/model'
4
- require_relative 'header/reference'
5
-
6
- module Jsapi
7
- module Meta
8
- module OpenAPI
9
- module Header
10
- class << self
11
- # Creates a header 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
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents an info object.
7
- class Info < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: contact
12
- # The optional Contact object.
13
- attribute :contact, Contact
14
-
15
- ##
16
- # :attr: description
17
- # The optional description of the API.
18
- attribute :description, String
19
-
20
- ##
21
- # :attr: license
22
- # The optional License object.
23
- attribute :license, License
24
-
25
- ##
26
- # :attr: terms_of_service
27
- # The optional URL pointing to the terms of service.
28
- attribute :terms_of_service, String
29
-
30
- ##
31
- # :attr: title
32
- # The title of the API.
33
- attribute :title, String
34
-
35
- ##
36
- # :attr: version
37
- # The version of the API.
38
- attribute :version, String
39
-
40
- # Returns a hash representing the \OpenAPI info object.
41
- def to_openapi(*)
42
- with_openapi_extensions(
43
- title: title,
44
- version: version,
45
- description: description,
46
- termsOfService: terms_of_service,
47
- contact: contact&.to_openapi,
48
- license: license&.to_openapi
49
- )
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents a license object.
7
- class License < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: name
12
- # The name of the license.
13
- attribute :name, String
14
-
15
- ##
16
- # :attr: url
17
- # The optional URL of the license.
18
- attribute :url, String
19
-
20
- # Returns a hash representing the \OpenAPI license object.
21
- def to_openapi(*)
22
- with_openapi_extensions(name: name, url: url)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,50 +0,0 @@
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 < Meta::Base::Model
9
- include Extensions
10
-
11
- ##
12
- # :attr: description
13
- # The optional description of the link.
14
- attribute :description, String
15
-
16
- ##
17
- # :attr: operation_id
18
- # The operation ID.
19
- attribute :operation_id, String
20
-
21
- ##
22
- # :attr: parameters
23
- # The optional parameters to be passed.
24
- attribute :parameters, { String => Object }
25
-
26
- ##
27
- # :attr: request_body
28
- # The optional request body to be passed.
29
- attribute :request_body
30
-
31
- ##
32
- # :attr: server
33
- # The optional Server object.
34
- attribute :server, Server
35
-
36
- # Returns a hash representing the \OpenAPI link object.
37
- def to_openapi(*)
38
- with_openapi_extensions(
39
- operationId: operation_id,
40
- parameters: parameters,
41
- requestBody: request_body,
42
- description: description,
43
- server: server&.to_openapi
44
- )
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- module Link
7
- class Reference < Meta::Base::Reference
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
@@ -1,21 +0,0 @@
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
@@ -1,52 +0,0 @@
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::Model
8
- include Extensions
9
-
10
- class Scope < Meta::Base::Model
11
- ##
12
- # :attr: description
13
- # The optional description of the scope.
14
- attribute :description, String, default: ''
15
- end
16
-
17
- ##
18
- # :attr: authorization_url
19
- # The authorization URL to be used for the flow.
20
- attribute :authorization_url, String
21
-
22
- ##
23
- # :attr: refresh_url
24
- # The refresh URL to be used for the flow.
25
- #
26
- # Note that the refresh URL was introduced with \OpenAPI 3.0. It is
27
- # skipped when generating an \OpenAPI 2.0 document.
28
- attribute :refresh_url, String
29
-
30
- ##
31
- # :attr: scopes
32
- # The hash containing the scopes.
33
- attribute :scopes, { String => Scope }, default: {}
34
-
35
- ##
36
- # :attr: token_url
37
- # The token URL to be used for the flow.
38
- attribute :token_url, String
39
-
40
- # Returns a hash representing the \OpenAPI OAuth flow object.
41
- def to_openapi(version)
42
- with_openapi_extensions(
43
- authorizationUrl: authorization_url,
44
- tokenUrl: token_url,
45
- refreshUrl: (refresh_url if version.major > 2),
46
- scopes: scopes.transform_values(&:description)
47
- )
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents an \OpenAPI object.
7
- class Root < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: callbacks
12
- # The reusable Callback objects. Applies to \OpenAPI 3.0 and higher.
13
- attribute :callbacks, { String => Callback }
14
-
15
- ##
16
- # :attr: base_path
17
- # The base path of the API. Applies to \OpenAPI 2.0.
18
- attribute :base_path, String
19
-
20
- ##
21
- # :attr: examples
22
- # The reusable Example objects. Applies to \OpenAPI 3.0 and higher.
23
- attribute :examples, { String => Example }
24
-
25
- ##
26
- # :attr: external_docs
27
- # The ExternalDocumentation object.
28
- attribute :external_docs, ExternalDocumentation
29
-
30
- ##
31
- # :attr: headers
32
- # The reusable Header objects. Applies to \OpenAPI 3.0 and higher.
33
- attribute :headers, { String => Header }
34
-
35
- ##
36
- # :attr: host
37
- # The host serving the API. Applies to \OpenAPI 2.0.
38
- attribute :host, String
39
-
40
- ##
41
- # :attr: info
42
- # The Info object.
43
- attribute :info, Info
44
-
45
- ##
46
- # :attr: links
47
- # The reusable Link objects. Applies to \OpenAPI 3.0 and higher.
48
- attribute :links, { String => Link }
49
-
50
- ##
51
- # :attr: schemes
52
- # The array of transfer protocols supported by the API. Possible values are:
53
- #
54
- # - <code>"http"</code>
55
- # - <code>"https"</code>
56
- # - <code>"ws"</code>
57
- # - <code>"wss"</code>
58
- #
59
- # Applies to \OpenAPI 2.0.
60
- attribute :schemes, [String], values: %w[http https ws wss]
61
-
62
- ##
63
- # :attr: security_requirements
64
- # The array of SecurityRequirement objects.
65
- attribute :security_requirements, [SecurityRequirement]
66
-
67
- alias add_security add_security_requirement
68
-
69
- ##
70
- # :attr_reader: security_schemes
71
- # The security schemes.
72
- attribute :security_schemes, { String => SecurityScheme }
73
-
74
- ##
75
- # :attr: servers
76
- # The array of Server objects. Applies to \OpenAPI 3.0 and higher.
77
- attribute :servers, [Server]
78
-
79
- ##
80
- # :attr: tags
81
- # The array of Tag objects.
82
- attribute :tags, [Tag]
83
-
84
- # Returns a hash representing the \OpenAPI object.
85
- def to_openapi(version, definitions)
86
- version = Version.from(version)
87
- security_schemes =
88
- self.security_schemes&.transform_values do |value|
89
- value.to_openapi(version)
90
- end
91
-
92
- with_openapi_extensions(
93
- if version.major == 2
94
- uri = servers&.first&.then { |server| URI(server.url) }
95
- {
96
- swagger: '2.0',
97
- info: info&.to_openapi,
98
- host: host || uri&.hostname,
99
- basePath: base_path || uri&.path,
100
- schemes: schemes || uri&.scheme&.then { |scheme| [scheme] },
101
- securityDefinitions: security_schemes,
102
- security: security_requirements&.map(&:to_openapi),
103
- tags: tags&.map(&:to_openapi),
104
- externalDocs: external_docs&.to_openapi
105
- }
106
- else
107
- {
108
- openapi: version.minor.zero? ? '3.0.3' : '3.1.0',
109
- info: info&.to_openapi,
110
- servers: servers&.map(&:to_openapi),
111
- components: {
112
- callbacks: callbacks&.transform_values do |callback|
113
- callback.to_openapi(version, definitions)
114
- end,
115
- examples: examples&.transform_values(&:to_openapi),
116
- headers: headers&.transform_values do |header|
117
- header.to_openapi(version)
118
- end,
119
- links: links&.transform_values(&:to_openapi),
120
- securitySchemes: security_schemes
121
- }.compact.presence,
122
- security: security_requirements&.map(&:to_openapi),
123
- tags: tags&.map(&:to_openapi),
124
- externalDocs: external_docs&.to_openapi
125
- }
126
- end
127
- )
128
- end
129
- end
130
- end
131
- end
132
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents a security requirement object.
7
- class SecurityRequirement < Meta::Base::Model
8
- class Scheme < Meta::Base::Model
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 \OpenAPI security requirement object.
21
- def to_openapi(*)
22
- schemes&.transform_values(&:scopes) || {}
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,40 +0,0 @@
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
- include Extensions
10
-
11
- ##
12
- # :attr: in
13
- # The location of the API key. Possible values are:
14
- #
15
- # - <code>"cookie"</code>
16
- # - <code>"header"</code>
17
- # - <code>"query"</code>
18
- #
19
- attribute :in, String, values: %w[cookie header query]
20
-
21
- ##
22
- # :attr: name
23
- # The name of the header, query parameter or cookie the
24
- # API key is sent by.
25
- attribute :name, String
26
-
27
- # Returns a hash representing the \OpenAPI security scheme object.
28
- def to_openapi(*)
29
- with_openapi_extensions(
30
- type: 'apiKey',
31
- name: name,
32
- in: self.in,
33
- description: description
34
- )
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- module SecurityScheme
7
- class Base < Meta::Base::Model
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
@@ -1,36 +0,0 @@
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
- include Extensions
11
-
12
- # Returns a hash representing the \OpenAPI security scheme object.
13
- def to_openapi(version)
14
- version = OpenAPI::Version.from(version)
15
-
16
- with_openapi_extensions(
17
- if version.major == 2
18
- {
19
- type: 'basic',
20
- description: description
21
- }
22
- else
23
- {
24
- type: 'http',
25
- scheme: 'basic',
26
- description: description
27
- }
28
- end
29
- )
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,39 +0,0 @@
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
- include Extensions
15
-
16
- ##
17
- # :attr: bearer_format
18
- # The optional format of the bearer token.
19
- attribute :bearer_format, String
20
-
21
- # Returns a hash representing the \OpenAPI security scheme object, or
22
- # +nil+ if <code>version.major</code> is 2.
23
- def to_openapi(version)
24
- version = OpenAPI::Version.from(version)
25
- return if version.major == 2
26
-
27
- with_openapi_extensions(
28
- type: 'http',
29
- scheme: 'bearer',
30
- bearerFormat: bearer_format,
31
- description: description
32
- )
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end