jsapi 0.8.0 → 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.
- checksums.yaml +4 -4
- data/lib/jsapi/dsl/base.rb +55 -0
- data/lib/jsapi/dsl/callback.rb +21 -0
- data/lib/jsapi/dsl/class_methods.rb +116 -10
- data/lib/jsapi/dsl/definitions.rb +173 -33
- data/lib/jsapi/dsl/examples.rb +30 -0
- data/lib/jsapi/dsl/operation.rb +60 -32
- data/lib/jsapi/dsl/parameter.rb +2 -2
- data/lib/jsapi/dsl/request_body.rb +2 -2
- data/lib/jsapi/dsl/response.rb +35 -11
- data/lib/jsapi/dsl/schema.rb +16 -16
- data/lib/jsapi/dsl.rb +4 -4
- data/lib/jsapi/meta/base/attributes.rb +21 -19
- data/lib/jsapi/meta/base/model.rb +15 -7
- data/lib/jsapi/meta/callback/model.rb +34 -0
- data/lib/jsapi/meta/callback/reference.rb +14 -0
- data/lib/jsapi/meta/callback.rb +19 -0
- data/lib/jsapi/meta/contact.rb +30 -0
- data/lib/jsapi/meta/defaults.rb +2 -2
- data/lib/jsapi/meta/definitions.rb +230 -124
- data/lib/jsapi/meta/example/model.rb +43 -0
- data/lib/jsapi/meta/example/reference.rb +14 -0
- data/lib/jsapi/meta/example.rb +19 -0
- data/lib/jsapi/meta/external_documentation.rb +25 -0
- data/lib/jsapi/meta/header/model.rb +81 -0
- data/lib/jsapi/meta/header/reference.rb +14 -0
- data/lib/jsapi/meta/header.rb +19 -0
- data/lib/jsapi/meta/info.rb +52 -0
- data/lib/jsapi/meta/license.rb +25 -0
- data/lib/jsapi/meta/link/model.rb +48 -0
- data/lib/jsapi/meta/link/reference.rb +14 -0
- data/lib/jsapi/meta/link.rb +19 -0
- data/lib/jsapi/meta/oauth_flow.rb +52 -0
- data/lib/jsapi/meta/openapi.rb +0 -28
- data/lib/jsapi/meta/operation.rb +19 -18
- data/lib/jsapi/meta/parameter/model.rb +6 -4
- data/lib/jsapi/meta/parameter/reference.rb +6 -4
- data/lib/jsapi/meta/parameter/to_openapi.rb +13 -0
- data/lib/jsapi/meta/parameter.rb +2 -1
- data/lib/jsapi/meta/property.rb +1 -1
- data/lib/jsapi/meta/request_body/model.rb +6 -5
- data/lib/jsapi/meta/request_body.rb +1 -1
- data/lib/jsapi/meta/response/model.rb +16 -13
- data/lib/jsapi/meta/response.rb +1 -1
- data/lib/jsapi/meta/schema/array.rb +1 -1
- data/lib/jsapi/meta/schema/base.rb +5 -5
- data/lib/jsapi/meta/schema/discriminator.rb +2 -2
- data/lib/jsapi/meta/schema/object.rb +3 -3
- data/lib/jsapi/meta/schema/reference.rb +1 -1
- data/lib/jsapi/meta/schema.rb +2 -2
- data/lib/jsapi/meta/security_requirement.rb +25 -0
- data/lib/jsapi/meta/security_scheme/api_key.rb +38 -0
- data/lib/jsapi/meta/security_scheme/base.rb +14 -0
- data/lib/jsapi/meta/security_scheme/http/basic.rb +34 -0
- data/lib/jsapi/meta/security_scheme/http/bearer.rb +36 -0
- data/lib/jsapi/meta/security_scheme/http/other.rb +36 -0
- data/lib/jsapi/meta/security_scheme/http.rb +29 -0
- data/lib/jsapi/meta/security_scheme/oauth2.rb +44 -0
- data/lib/jsapi/meta/security_scheme/open_id_connect.rb +32 -0
- data/lib/jsapi/meta/security_scheme.rb +49 -0
- data/lib/jsapi/meta/server.rb +34 -0
- data/lib/jsapi/meta/server_variable.rb +34 -0
- data/lib/jsapi/meta/tag.rb +34 -0
- data/lib/jsapi/meta.rb +15 -1
- data/lib/jsapi/model/base.rb +5 -5
- data/lib/jsapi/version.rb +1 -1
- metadata +38 -42
- data/lib/jsapi/dsl/node.rb +0 -62
- data/lib/jsapi/dsl/openapi/callback.rb +0 -23
- data/lib/jsapi/dsl/openapi/callbacks.rb +0 -34
- data/lib/jsapi/dsl/openapi/examples.rb +0 -32
- data/lib/jsapi/dsl/openapi/root.rb +0 -126
- data/lib/jsapi/dsl/openapi.rb +0 -6
- data/lib/jsapi/meta/openapi/callback/model.rb +0 -34
- data/lib/jsapi/meta/openapi/callback/reference.rb +0 -16
- data/lib/jsapi/meta/openapi/callback.rb +0 -21
- data/lib/jsapi/meta/openapi/contact.rb +0 -32
- data/lib/jsapi/meta/openapi/example/model.rb +0 -44
- data/lib/jsapi/meta/openapi/example/reference.rb +0 -16
- data/lib/jsapi/meta/openapi/example.rb +0 -21
- data/lib/jsapi/meta/openapi/external_documentation.rb +0 -27
- data/lib/jsapi/meta/openapi/header/model.rb +0 -82
- data/lib/jsapi/meta/openapi/header/reference.rb +0 -16
- data/lib/jsapi/meta/openapi/header.rb +0 -21
- data/lib/jsapi/meta/openapi/info.rb +0 -54
- data/lib/jsapi/meta/openapi/license.rb +0 -27
- data/lib/jsapi/meta/openapi/link/model.rb +0 -50
- data/lib/jsapi/meta/openapi/link/reference.rb +0 -16
- data/lib/jsapi/meta/openapi/link.rb +0 -21
- data/lib/jsapi/meta/openapi/oauth_flow.rb +0 -52
- data/lib/jsapi/meta/openapi/root.rb +0 -132
- data/lib/jsapi/meta/openapi/security_requirement.rb +0 -27
- data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +0 -40
- data/lib/jsapi/meta/openapi/security_scheme/base.rb +0 -16
- data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +0 -36
- data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +0 -39
- data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +0 -39
- data/lib/jsapi/meta/openapi/security_scheme/http.rb +0 -31
- data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +0 -46
- data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +0 -34
- data/lib/jsapi/meta/openapi/security_scheme.rb +0 -51
- data/lib/jsapi/meta/openapi/server.rb +0 -36
- data/lib/jsapi/meta/openapi/server_variable.rb +0 -36
- data/lib/jsapi/meta/openapi/tag.rb +0 -36
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Header
|
6
|
+
# Specifies a header object.
|
7
|
+
class Model < Base::Model
|
8
|
+
include OpenAPI::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).presence
|
74
|
+
}
|
75
|
+
end
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Header
|
6
|
+
class Reference < Base::Reference
|
7
|
+
# Returns a hash representing the \OpenAPI reference object.
|
8
|
+
def to_openapi(*)
|
9
|
+
{ '$ref': "#/components/headers/#{ref}" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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 Header
|
9
|
+
class << self
|
10
|
+
# Creates a Model or Reference.
|
11
|
+
def new(keywords = {})
|
12
|
+
return Reference.new(keywords) if keywords.key?(:ref)
|
13
|
+
|
14
|
+
Model.new(keywords)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
# Specifies an info object.
|
6
|
+
class Info < Base::Model
|
7
|
+
include OpenAPI::Extensions
|
8
|
+
|
9
|
+
##
|
10
|
+
# :attr: contact
|
11
|
+
# The Contact object.
|
12
|
+
attribute :contact, Contact
|
13
|
+
|
14
|
+
##
|
15
|
+
# :attr: description
|
16
|
+
# The description of the API.
|
17
|
+
attribute :description, String
|
18
|
+
|
19
|
+
##
|
20
|
+
# :attr: license
|
21
|
+
# The License object.
|
22
|
+
attribute :license, License
|
23
|
+
|
24
|
+
##
|
25
|
+
# :attr: terms_of_service
|
26
|
+
# The URL pointing to the terms of service.
|
27
|
+
attribute :terms_of_service, String
|
28
|
+
|
29
|
+
##
|
30
|
+
# :attr: title
|
31
|
+
# The title of the API.
|
32
|
+
attribute :title, String
|
33
|
+
|
34
|
+
##
|
35
|
+
# :attr: version
|
36
|
+
# The version of the API.
|
37
|
+
attribute :version, String
|
38
|
+
|
39
|
+
# Returns a hash representing the \OpenAPI info object.
|
40
|
+
def to_openapi(*)
|
41
|
+
with_openapi_extensions(
|
42
|
+
title: title,
|
43
|
+
version: version,
|
44
|
+
description: description,
|
45
|
+
termsOfService: terms_of_service,
|
46
|
+
contact: contact&.to_openapi,
|
47
|
+
license: license&.to_openapi
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
# Specifies a license object.
|
6
|
+
class License < Base::Model
|
7
|
+
include OpenAPI::Extensions
|
8
|
+
|
9
|
+
##
|
10
|
+
# :attr: name
|
11
|
+
# The name of the license.
|
12
|
+
attribute :name, String
|
13
|
+
|
14
|
+
##
|
15
|
+
# :attr: url
|
16
|
+
# The URL of the license.
|
17
|
+
attribute :url, String
|
18
|
+
|
19
|
+
# Returns a hash representing the \OpenAPI license object.
|
20
|
+
def to_openapi(*)
|
21
|
+
with_openapi_extensions(name: name, url: url)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Link
|
6
|
+
# Specifies a link object.
|
7
|
+
class Model < Base::Model
|
8
|
+
include OpenAPI::Extensions
|
9
|
+
|
10
|
+
##
|
11
|
+
# :attr: description
|
12
|
+
# The description of the link.
|
13
|
+
attribute :description, String
|
14
|
+
|
15
|
+
##
|
16
|
+
# :attr: operation_id
|
17
|
+
# The operation ID.
|
18
|
+
attribute :operation_id, String
|
19
|
+
|
20
|
+
##
|
21
|
+
# :attr: parameters
|
22
|
+
# The parameters to be passed.
|
23
|
+
attribute :parameters, { String => Object }
|
24
|
+
|
25
|
+
##
|
26
|
+
# :attr: request_body
|
27
|
+
# The request body to be passed.
|
28
|
+
attribute :request_body
|
29
|
+
|
30
|
+
##
|
31
|
+
# :attr: server
|
32
|
+
# The Server object.
|
33
|
+
attribute :server, Server
|
34
|
+
|
35
|
+
# Returns a hash representing the \OpenAPI link object.
|
36
|
+
def to_openapi(*)
|
37
|
+
with_openapi_extensions(
|
38
|
+
operationId: operation_id,
|
39
|
+
parameters: parameters.presence,
|
40
|
+
requestBody: request_body,
|
41
|
+
description: description,
|
42
|
+
server: server&.to_openapi
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Link
|
6
|
+
class Reference < Base::Reference
|
7
|
+
# Returns a hash representing the \OpenAPI reference object.
|
8
|
+
def to_openapi(*)
|
9
|
+
{ '$ref': "#/components/links/#{ref}" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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 Link
|
9
|
+
class << self
|
10
|
+
# Creates a Model or Reference.
|
11
|
+
def new(keywords = {})
|
12
|
+
return Reference.new(keywords) if keywords.key?(:ref)
|
13
|
+
|
14
|
+
Model.new(keywords)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
# Represents an OAuth flow object.
|
6
|
+
class OAuthFlow < Base::Model
|
7
|
+
include OpenAPI::Extensions
|
8
|
+
|
9
|
+
class Scope < Base::Model
|
10
|
+
##
|
11
|
+
# :attr: description
|
12
|
+
# The description of the scope.
|
13
|
+
attribute :description, String, default: ''
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: authorization_url
|
18
|
+
# The authorization URL to be used for the flow.
|
19
|
+
attribute :authorization_url, String
|
20
|
+
|
21
|
+
##
|
22
|
+
# :attr: refresh_url
|
23
|
+
# The refresh URL to be used for the flow.
|
24
|
+
#
|
25
|
+
# Note that the refresh URL was introduced with \OpenAPI 3.0. It is
|
26
|
+
# skipped when generating an \OpenAPI 2.0 document.
|
27
|
+
attribute :refresh_url, String
|
28
|
+
|
29
|
+
##
|
30
|
+
# :attr: scopes
|
31
|
+
# The hash containing the scopes.
|
32
|
+
attribute :scopes, { String => Scope }
|
33
|
+
|
34
|
+
##
|
35
|
+
# :attr: token_url
|
36
|
+
# The token URL to be used for the flow.
|
37
|
+
attribute :token_url, String
|
38
|
+
|
39
|
+
# Returns a hash representing the \OpenAPI OAuth flow object.
|
40
|
+
def to_openapi(version, *)
|
41
|
+
version = OpenAPI::Version.from(version)
|
42
|
+
|
43
|
+
with_openapi_extensions(
|
44
|
+
authorizationUrl: authorization_url,
|
45
|
+
tokenUrl: token_url,
|
46
|
+
refreshUrl: (refresh_url if version.major > 2),
|
47
|
+
scopes: scopes.transform_values(&:description)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/jsapi/meta/openapi.rb
CHANGED
@@ -2,31 +2,3 @@
|
|
2
2
|
|
3
3
|
require_relative 'openapi/extensions'
|
4
4
|
require_relative 'openapi/version'
|
5
|
-
require_relative 'openapi/callback'
|
6
|
-
require_relative 'openapi/contact'
|
7
|
-
require_relative 'openapi/license'
|
8
|
-
require_relative 'openapi/info'
|
9
|
-
require_relative 'openapi/example'
|
10
|
-
require_relative 'openapi/external_documentation'
|
11
|
-
require_relative 'openapi/header'
|
12
|
-
require_relative 'openapi/oauth_flow'
|
13
|
-
require_relative 'openapi/security_scheme'
|
14
|
-
require_relative 'openapi/security_requirement'
|
15
|
-
require_relative 'openapi/server_variable'
|
16
|
-
require_relative 'openapi/server'
|
17
|
-
require_relative 'openapi/link'
|
18
|
-
require_relative 'openapi/tag'
|
19
|
-
require_relative 'openapi/root'
|
20
|
-
|
21
|
-
module Jsapi
|
22
|
-
module Meta
|
23
|
-
module OpenAPI
|
24
|
-
class << self
|
25
|
-
# Creates a new \OpenAPI root object.
|
26
|
-
def new(keywords = {})
|
27
|
-
Root.new(keywords)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/jsapi/meta/operation.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
+
# Defines an API operation.
|
5
6
|
class Operation < Base::Model
|
6
7
|
include OpenAPI::Extensions
|
7
8
|
|
8
9
|
##
|
9
10
|
# :attr: callbacks
|
10
|
-
# The
|
11
|
-
attribute :callbacks, { String =>
|
11
|
+
# The Callback objects. Applies to \OpenAPI 3.0 and higher.
|
12
|
+
attribute :callbacks, { String => Callback }
|
12
13
|
|
13
14
|
##
|
14
15
|
# :attr: deprecated
|
@@ -22,8 +23,8 @@ module Jsapi
|
|
22
23
|
|
23
24
|
##
|
24
25
|
# :attr: external_docs
|
25
|
-
# The
|
26
|
-
attribute :external_docs,
|
26
|
+
# The ExternalDocumentation object.
|
27
|
+
attribute :external_docs, ExternalDocumentation
|
27
28
|
|
28
29
|
##
|
29
30
|
# :attr: method
|
@@ -53,7 +54,7 @@ module Jsapi
|
|
53
54
|
##
|
54
55
|
# :attr: parameters
|
55
56
|
# The parameters of the operation.
|
56
|
-
attribute :parameters, { String => Parameter }
|
57
|
+
attribute :parameters, { String => Parameter }
|
57
58
|
|
58
59
|
##
|
59
60
|
# :attr: path
|
@@ -68,7 +69,7 @@ module Jsapi
|
|
68
69
|
##
|
69
70
|
# :attr: responses
|
70
71
|
# The responses of the operation.
|
71
|
-
attribute :responses, { String => Response },
|
72
|
+
attribute :responses, { String => Response }, default_key: 'default'
|
72
73
|
|
73
74
|
##
|
74
75
|
# :attr: schemes
|
@@ -84,15 +85,15 @@ module Jsapi
|
|
84
85
|
|
85
86
|
##
|
86
87
|
# :attr: security_requirements
|
87
|
-
# The
|
88
|
-
attribute :security_requirements, [
|
88
|
+
# The SecurityRequirement objects.
|
89
|
+
attribute :security_requirements, [SecurityRequirement]
|
89
90
|
|
90
91
|
alias add_security add_security_requirement
|
91
92
|
|
92
93
|
##
|
93
94
|
# :attr: servers
|
94
|
-
# The
|
95
|
-
attribute :servers, [
|
95
|
+
# The Server objects. Applies to \OpenAPI 3.0 and higher.
|
96
|
+
attribute :servers, [Server]
|
96
97
|
|
97
98
|
##
|
98
99
|
# :attr: summary
|
@@ -104,13 +105,13 @@ module Jsapi
|
|
104
105
|
# The tags used to group operations in an \OpenAPI document.
|
105
106
|
attribute :tags, [String]
|
106
107
|
|
107
|
-
undef :add_parameter
|
108
|
-
|
109
108
|
def initialize(name = nil, keywords = {})
|
110
109
|
@name = name&.to_s
|
111
110
|
super(keywords)
|
112
111
|
end
|
113
112
|
|
113
|
+
undef add_parameter
|
114
|
+
|
114
115
|
def add_parameter(name, keywords = {}) # :nodoc:
|
115
116
|
(@parameters ||= {})[name.to_s] = Parameter.new(name, keywords)
|
116
117
|
end
|
@@ -133,12 +134,12 @@ module Jsapi
|
|
133
134
|
|
134
135
|
with_openapi_extensions(
|
135
136
|
operationId: name,
|
136
|
-
tags: tags,
|
137
|
+
tags: tags.presence,
|
137
138
|
summary: summary,
|
138
139
|
description: description,
|
139
140
|
externalDocs: external_docs&.to_openapi,
|
140
141
|
deprecated: deprecated?.presence,
|
141
|
-
security: security_requirements
|
142
|
+
security: security_requirements.map(&:to_openapi).presence
|
142
143
|
).tap do |hash|
|
143
144
|
if version.major == 2
|
144
145
|
if (consumes = consumes(definitions)).present?
|
@@ -147,13 +148,13 @@ module Jsapi
|
|
147
148
|
if (produces = produces(definitions)).present?
|
148
149
|
hash[:produces] = produces
|
149
150
|
end
|
150
|
-
hash[:schemes] = schemes if schemes
|
151
|
-
elsif servers
|
151
|
+
hash[:schemes] = schemes if schemes.present?
|
152
|
+
elsif servers.present?
|
152
153
|
hash[:servers] = servers.map(&:to_openapi)
|
153
154
|
end
|
154
155
|
# Parameters (and request body)
|
155
156
|
hash[:parameters] = parameters.values.flat_map do |parameter|
|
156
|
-
parameter.
|
157
|
+
parameter.to_openapi_parameters(version, definitions)
|
157
158
|
end
|
158
159
|
if request_body
|
159
160
|
if version.major == 2
|
@@ -167,7 +168,7 @@ module Jsapi
|
|
167
168
|
response.to_openapi(version, definitions)
|
168
169
|
end
|
169
170
|
# Callbacks
|
170
|
-
if callbacks && version.major > 2
|
171
|
+
if callbacks.present? && version.major > 2
|
171
172
|
hash[:callbacks] = callbacks.transform_values do |callback|
|
172
173
|
callback.to_openapi(version, definitions)
|
173
174
|
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
|
+
# Defines a parameter.
|
6
7
|
class Model < Base::Model
|
8
|
+
include ToOpenAPI
|
7
9
|
include OpenAPI::Extensions
|
8
10
|
|
9
11
|
delegate_missing_to :schema
|
@@ -21,7 +23,7 @@ module Jsapi
|
|
21
23
|
##
|
22
24
|
# :attr_reader: examples
|
23
25
|
# The examples.
|
24
|
-
attribute :examples, { String =>
|
26
|
+
attribute :examples, { String => Example }, default_key: 'default'
|
25
27
|
|
26
28
|
##
|
27
29
|
# :attr: in
|
@@ -74,7 +76,7 @@ module Jsapi
|
|
74
76
|
end
|
75
77
|
|
76
78
|
# Returns an array of hashes representing the \OpenAPI parameter objects.
|
77
|
-
def
|
79
|
+
def to_openapi_parameters(version, definitions)
|
78
80
|
version = OpenAPI::Version.from(version)
|
79
81
|
schema = self.schema.resolve(definitions)
|
80
82
|
|
@@ -109,7 +111,7 @@ module Jsapi
|
|
109
111
|
allowEmptyValue: allow_empty_value?.presence,
|
110
112
|
deprecated: deprecated?.presence,
|
111
113
|
schema: schema.to_openapi(version),
|
112
|
-
examples: examples
|
114
|
+
examples: examples.transform_values(&:to_openapi).presence
|
113
115
|
|
114
116
|
# NOTE: collectionFormat is replaced by style and explode.
|
115
117
|
# The default values for query parameters are:
|
@@ -165,7 +167,7 @@ module Jsapi
|
|
165
167
|
allowEmptyValue: allow_empty_value.presence,
|
166
168
|
deprecated: deprecated,
|
167
169
|
schema: property_schema.to_openapi(version).except(:deprecated),
|
168
|
-
examples: examples
|
170
|
+
examples: examples.transform_values(&:to_openapi).presence
|
169
171
|
}
|
170
172
|
end
|
171
173
|
)
|
@@ -4,18 +4,20 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
6
|
class Reference < Base::Reference
|
7
|
-
|
7
|
+
include ToOpenAPI
|
8
|
+
|
9
|
+
# Returns an array of hashes. Each hash represents an \OpenAPI parameter object
|
8
10
|
# if the type of the referred parameter is <code>"object"</code>. Otherwise the
|
9
11
|
# array contains a single hash representing the \OpenAPI reference object.
|
10
12
|
#
|
11
|
-
# Raises a ReferenceError
|
12
|
-
def
|
13
|
+
# Raises a ReferenceError when the reference could not be resolved.
|
14
|
+
def to_openapi_parameters(version, definitions)
|
13
15
|
version = OpenAPI::Version.from(version)
|
14
16
|
parameter = resolve(definitions)
|
15
17
|
|
16
18
|
if parameter.schema.resolve(definitions).object?
|
17
19
|
# Explode referred parameter
|
18
|
-
parameter.
|
20
|
+
parameter.to_openapi_parameters(version, definitions)
|
19
21
|
else
|
20
22
|
# Return an array containing the reference object
|
21
23
|
path = version.major == 2 ? 'parameters' : 'components/parameters'
|
data/lib/jsapi/meta/parameter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'parameter/to_openapi'
|
3
4
|
require_relative 'parameter/model'
|
4
5
|
require_relative 'parameter/reference'
|
5
6
|
|
@@ -7,7 +8,7 @@ module Jsapi
|
|
7
8
|
module Meta
|
8
9
|
module Parameter
|
9
10
|
class << self
|
10
|
-
# Creates a
|
11
|
+
# Creates a Model or Reference.
|
11
12
|
def new(name, keywords = {})
|
12
13
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
14
|
|
data/lib/jsapi/meta/property.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module RequestBody
|
6
|
+
# Defines a request body.
|
6
7
|
class Model < Base::Model
|
7
8
|
include OpenAPI::Extensions
|
8
9
|
|
@@ -15,13 +16,13 @@ module Jsapi
|
|
15
16
|
|
16
17
|
##
|
17
18
|
# :attr: description
|
18
|
-
# The
|
19
|
+
# The description of the request body.
|
19
20
|
attribute :description, String
|
20
21
|
|
21
22
|
##
|
22
23
|
# :attr_reader: examples
|
23
|
-
# The
|
24
|
-
attribute :examples, { String =>
|
24
|
+
# The Example objects.
|
25
|
+
attribute :examples, { String => Example }, default_key: 'default'
|
25
26
|
|
26
27
|
##
|
27
28
|
# :attr_reader: schema
|
@@ -55,13 +56,13 @@ module Jsapi
|
|
55
56
|
end
|
56
57
|
|
57
58
|
# Returns a hash representing the \OpenAPI 3.x request body object.
|
58
|
-
def to_openapi(version)
|
59
|
+
def to_openapi(version, *)
|
59
60
|
with_openapi_extensions(
|
60
61
|
description: description,
|
61
62
|
content: {
|
62
63
|
content_type => {
|
63
64
|
schema: schema.to_openapi(version),
|
64
|
-
examples: examples
|
65
|
+
examples: examples.transform_values(&:to_openapi).presence
|
65
66
|
}.compact
|
66
67
|
},
|
67
68
|
required: required?
|