jsapi 0.8.0 → 0.9.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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/configuration.rb +28 -0
  3. data/lib/jsapi/controller/methods.rb +1 -1
  4. data/lib/jsapi/dsl/base.rb +92 -0
  5. data/lib/jsapi/dsl/callback.rb +21 -0
  6. data/lib/jsapi/dsl/class_methods.rb +143 -16
  7. data/lib/jsapi/dsl/definitions.rb +173 -33
  8. data/lib/jsapi/dsl/examples.rb +30 -0
  9. data/lib/jsapi/dsl/operation.rb +60 -32
  10. data/lib/jsapi/dsl/parameter.rb +2 -2
  11. data/lib/jsapi/dsl/request_body.rb +2 -2
  12. data/lib/jsapi/dsl/response.rb +35 -11
  13. data/lib/jsapi/dsl/schema.rb +16 -16
  14. data/lib/jsapi/dsl.rb +4 -4
  15. data/lib/jsapi/meta/base/attributes.rb +21 -19
  16. data/lib/jsapi/meta/base/model.rb +15 -7
  17. data/lib/jsapi/meta/callback/model.rb +34 -0
  18. data/lib/jsapi/meta/callback/reference.rb +14 -0
  19. data/lib/jsapi/meta/callback.rb +19 -0
  20. data/lib/jsapi/meta/contact.rb +30 -0
  21. data/lib/jsapi/meta/defaults.rb +2 -2
  22. data/lib/jsapi/meta/definitions.rb +230 -124
  23. data/lib/jsapi/meta/example/model.rb +43 -0
  24. data/lib/jsapi/meta/example/reference.rb +14 -0
  25. data/lib/jsapi/meta/example.rb +19 -0
  26. data/lib/jsapi/meta/external_documentation.rb +25 -0
  27. data/lib/jsapi/meta/header/model.rb +81 -0
  28. data/lib/jsapi/meta/header/reference.rb +14 -0
  29. data/lib/jsapi/meta/header.rb +19 -0
  30. data/lib/jsapi/meta/info.rb +52 -0
  31. data/lib/jsapi/meta/license.rb +25 -0
  32. data/lib/jsapi/meta/link/model.rb +48 -0
  33. data/lib/jsapi/meta/link/reference.rb +14 -0
  34. data/lib/jsapi/meta/link.rb +19 -0
  35. data/lib/jsapi/meta/oauth_flow.rb +52 -0
  36. data/lib/jsapi/meta/openapi.rb +0 -28
  37. data/lib/jsapi/meta/operation.rb +19 -18
  38. data/lib/jsapi/meta/parameter/model.rb +6 -4
  39. data/lib/jsapi/meta/parameter/reference.rb +6 -4
  40. data/lib/jsapi/meta/parameter/to_openapi.rb +13 -0
  41. data/lib/jsapi/meta/parameter.rb +2 -1
  42. data/lib/jsapi/meta/property.rb +1 -1
  43. data/lib/jsapi/meta/request_body/model.rb +6 -5
  44. data/lib/jsapi/meta/request_body.rb +1 -1
  45. data/lib/jsapi/meta/response/model.rb +16 -13
  46. data/lib/jsapi/meta/response.rb +1 -1
  47. data/lib/jsapi/meta/schema/array.rb +1 -1
  48. data/lib/jsapi/meta/schema/base.rb +5 -5
  49. data/lib/jsapi/meta/schema/discriminator.rb +2 -2
  50. data/lib/jsapi/meta/schema/object.rb +3 -3
  51. data/lib/jsapi/meta/schema/reference.rb +1 -1
  52. data/lib/jsapi/meta/schema.rb +2 -2
  53. data/lib/jsapi/meta/security_requirement.rb +25 -0
  54. data/lib/jsapi/meta/security_scheme/api_key.rb +38 -0
  55. data/lib/jsapi/meta/security_scheme/base.rb +14 -0
  56. data/lib/jsapi/meta/security_scheme/http/basic.rb +34 -0
  57. data/lib/jsapi/meta/security_scheme/http/bearer.rb +36 -0
  58. data/lib/jsapi/meta/security_scheme/http/other.rb +36 -0
  59. data/lib/jsapi/meta/security_scheme/http.rb +29 -0
  60. data/lib/jsapi/meta/security_scheme/oauth2.rb +44 -0
  61. data/lib/jsapi/meta/security_scheme/open_id_connect.rb +32 -0
  62. data/lib/jsapi/meta/security_scheme.rb +49 -0
  63. data/lib/jsapi/meta/server.rb +34 -0
  64. data/lib/jsapi/meta/server_variable.rb +34 -0
  65. data/lib/jsapi/meta/tag.rb +34 -0
  66. data/lib/jsapi/meta.rb +15 -1
  67. data/lib/jsapi/model/base.rb +5 -5
  68. data/lib/jsapi/version.rb +1 -1
  69. data/lib/jsapi.rb +1 -1
  70. metadata +39 -42
  71. data/lib/jsapi/dsl/node.rb +0 -62
  72. data/lib/jsapi/dsl/openapi/callback.rb +0 -23
  73. data/lib/jsapi/dsl/openapi/callbacks.rb +0 -34
  74. data/lib/jsapi/dsl/openapi/examples.rb +0 -32
  75. data/lib/jsapi/dsl/openapi/root.rb +0 -126
  76. data/lib/jsapi/dsl/openapi.rb +0 -6
  77. data/lib/jsapi/meta/openapi/callback/model.rb +0 -34
  78. data/lib/jsapi/meta/openapi/callback/reference.rb +0 -16
  79. data/lib/jsapi/meta/openapi/callback.rb +0 -21
  80. data/lib/jsapi/meta/openapi/contact.rb +0 -32
  81. data/lib/jsapi/meta/openapi/example/model.rb +0 -44
  82. data/lib/jsapi/meta/openapi/example/reference.rb +0 -16
  83. data/lib/jsapi/meta/openapi/example.rb +0 -21
  84. data/lib/jsapi/meta/openapi/external_documentation.rb +0 -27
  85. data/lib/jsapi/meta/openapi/header/model.rb +0 -82
  86. data/lib/jsapi/meta/openapi/header/reference.rb +0 -16
  87. data/lib/jsapi/meta/openapi/header.rb +0 -21
  88. data/lib/jsapi/meta/openapi/info.rb +0 -54
  89. data/lib/jsapi/meta/openapi/license.rb +0 -27
  90. data/lib/jsapi/meta/openapi/link/model.rb +0 -50
  91. data/lib/jsapi/meta/openapi/link/reference.rb +0 -16
  92. data/lib/jsapi/meta/openapi/link.rb +0 -21
  93. data/lib/jsapi/meta/openapi/oauth_flow.rb +0 -52
  94. data/lib/jsapi/meta/openapi/root.rb +0 -132
  95. data/lib/jsapi/meta/openapi/security_requirement.rb +0 -27
  96. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +0 -40
  97. data/lib/jsapi/meta/openapi/security_scheme/base.rb +0 -16
  98. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +0 -36
  99. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +0 -39
  100. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +0 -39
  101. data/lib/jsapi/meta/openapi/security_scheme/http.rb +0 -31
  102. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +0 -46
  103. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +0 -34
  104. data/lib/jsapi/meta/openapi/security_scheme.rb +0 -51
  105. data/lib/jsapi/meta/openapi/server.rb +0 -36
  106. data/lib/jsapi/meta/openapi/server_variable.rb +0 -36
  107. data/lib/jsapi/meta/openapi/tag.rb +0 -36
@@ -1,31 +0,0 @@
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
@@ -1,46 +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 \OAuth2.
8
- class OAuth2 < Base
9
- include Extensions
10
-
11
- ##
12
- # :attr: oauth_flows
13
- # The hash containing the OAuth flows. Possible keys are:
14
- #
15
- # - <code>"authorization_code"</code>
16
- # - <code>"client_credentials"</code>
17
- # - <code>"implicit"</code>
18
- # - <code>"password"</code>
19
- #
20
- # Values are OAuthFlow objects.
21
- attribute :oauth_flows, { String => OAuthFlow },
22
- keys: %w[authorization_code client_credentials implicit password]
23
-
24
- # Returns a hash representing the \OpenAPI security scheme object.
25
- def to_openapi(version)
26
- version = Version.from(version)
27
-
28
- with_openapi_extensions(type: 'oauth2', description: description).tap do |h|
29
- if oauth_flows&.any?
30
- if version.major == 2
31
- key, oauth_flow = oauth_flows.first
32
- h[:flow] = key.to_s
33
- h.merge!(oauth_flow.to_openapi(version))
34
- else
35
- h[:flows] = oauth_flows.to_h do |key, value|
36
- [key.to_s.camelize(:lower).to_sym, value.to_openapi(version)]
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,34 +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 OpenID Connect.
8
- #
9
- # OpenID Connect was introduced with \OpenAPI 3.0. Thus, a security scheme of
10
- # this class is skipped when generating an \OpenAPI 2.0 document.
11
- class OpenIDConnect < Base
12
- include Extensions
13
-
14
- ##
15
- # :attr: open_id_connect_url
16
- attribute :open_id_connect_url, String
17
-
18
- # Returns a hash representing the \OpenAPI security scheme object, or +nil+
19
- # if <code>version.major</code> is 2.
20
- def to_openapi(version)
21
- version = Version.from(version)
22
- return if version.major == 2
23
-
24
- with_openapi_extensions(
25
- type: 'openIdConnect',
26
- openIdConnectUrl: open_id_connect_url,
27
- description: description
28
- )
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,51 +0,0 @@
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 OpenAPI
12
- module SecurityScheme
13
- class << self
14
- # Creates a security scheme. The +:type+ keyword specifies the type
15
- # of the security scheme to be created. Possible types are:
16
- #
17
- # - <code>"api_key"</code>
18
- # - <code>"basic"</code>
19
- # - <code>"http"</code>
20
- # - <code>"oauth2"</code>
21
- # - <code>"open_id_connect"</code>
22
- #
23
- # Raises an InvalidArgumentError if the given type is invalid.
24
- def new(keywords = {})
25
- type = keywords[:type]
26
- keywords = keywords.except(:type)
27
-
28
- case type&.to_s
29
- when 'api_key'
30
- APIKey.new(keywords)
31
- when 'basic' # OpenAPI 2.0
32
- HTTP.new(keywords.merge(scheme: 'basic'))
33
- when 'http' # OpenAPI 3.0 and higher
34
- HTTP.new(keywords)
35
- when 'oauth2'
36
- OAuth2.new(keywords)
37
- when 'open_id_connect' # OpenAPI 3.0 and higher
38
- OpenIDConnect.new(keywords)
39
- else
40
- raise InvalidArgumentError.new(
41
- 'type',
42
- type,
43
- valid_values: %w[api_key basic http oauth2 open_id_connect]
44
- )
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents a server object.
7
- class Server < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: description
12
- # The optional description of the server.
13
- attribute :description, String
14
-
15
- ##
16
- # :attr: url
17
- # The absolute or relative URL of the server.
18
- attribute :url, String
19
-
20
- ##
21
- # :attr_reader: variables
22
- # The optional server variables.
23
- attribute :variables, { String => ServerVariable }
24
-
25
- # Returns a hash representing the \OpenAPI server object.
26
- def to_openapi(*)
27
- with_openapi_extensions(
28
- url: url,
29
- description: description,
30
- variables: variables&.transform_values(&:to_openapi)
31
- )
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents a server variable object.
7
- class ServerVariable < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: default
12
- # The default value of the server variable.
13
- attribute :default, String
14
-
15
- ##
16
- # :attr: description
17
- # The optional description of the server variable.
18
- attribute :description, String
19
-
20
- ##
21
- # :attr: enum
22
- # The values of the server variable.
23
- attribute :enum, [String]
24
-
25
- # Returns a hash representing the \OpenAPI server variable object.
26
- def to_openapi(*)
27
- with_openapi_extensions(
28
- default: default,
29
- enum: enum.presence, # must not be empty
30
- description: description
31
- )
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module OpenAPI
6
- # Represents a tag object.
7
- class Tag < Meta::Base::Model
8
- include Extensions
9
-
10
- ##
11
- # :attr: description
12
- # The description of the tag.
13
- attribute :description, String
14
-
15
- ##
16
- # :attr: external_docs
17
- # The ExternalDocumentation object.
18
- attribute :external_docs, ExternalDocumentation
19
-
20
- ##
21
- # :attr: name
22
- # The name of the tag.
23
- attribute :name, String
24
-
25
- # Returns a hash representing the \OpenAPI tag object.
26
- def to_openapi(*)
27
- with_openapi_extensions(
28
- name: name,
29
- description: description,
30
- externalDocs: external_docs&.to_openapi
31
- )
32
- end
33
- end
34
- end
35
- end
36
- end