jsapi 0.2.0 → 0.4.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/controller/methods.rb +13 -3
  3. data/lib/jsapi/controller/parameters.rb +2 -5
  4. data/lib/jsapi/controller/response.rb +46 -24
  5. data/lib/jsapi/dsl/class_methods.rb +5 -0
  6. data/lib/jsapi/dsl/definitions.rb +7 -0
  7. data/lib/jsapi/json/object.rb +5 -8
  8. data/lib/jsapi/meta/definitions.rb +20 -11
  9. data/lib/jsapi/meta/openapi/callback/model.rb +1 -1
  10. data/lib/jsapi/meta/openapi/contact.rb +4 -6
  11. data/lib/jsapi/meta/openapi/example/model.rb +44 -0
  12. data/lib/jsapi/meta/openapi/example/reference.rb +16 -0
  13. data/lib/jsapi/meta/openapi/example.rb +21 -0
  14. data/lib/jsapi/meta/openapi/extensions.rb +31 -0
  15. data/lib/jsapi/meta/openapi/external_documentation.rb +4 -5
  16. data/lib/jsapi/meta/openapi/header/model.rb +64 -0
  17. data/lib/jsapi/meta/openapi/header/reference.rb +16 -0
  18. data/lib/jsapi/meta/openapi/header.rb +21 -0
  19. data/lib/jsapi/meta/openapi/info.rb +5 -3
  20. data/lib/jsapi/meta/openapi/license.rb +4 -5
  21. data/lib/jsapi/meta/openapi/link/model.rb +5 -3
  22. data/lib/jsapi/meta/openapi/oauth_flow.rb +5 -3
  23. data/lib/jsapi/meta/openapi/root.rb +44 -32
  24. data/lib/jsapi/meta/openapi/security_requirement.rb +1 -1
  25. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +5 -3
  26. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +18 -13
  27. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +5 -3
  28. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +5 -3
  29. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +6 -6
  30. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +5 -3
  31. data/lib/jsapi/meta/openapi/server.rb +5 -3
  32. data/lib/jsapi/meta/openapi/server_variable.rb +5 -3
  33. data/lib/jsapi/meta/openapi/tag.rb +5 -3
  34. data/lib/jsapi/meta/openapi.rb +3 -0
  35. data/lib/jsapi/meta/operation.rb +6 -3
  36. data/lib/jsapi/meta/parameter/model.rb +54 -48
  37. data/lib/jsapi/meta/request_body/model.rb +6 -4
  38. data/lib/jsapi/meta/response/model.rb +37 -23
  39. data/lib/jsapi/meta/schema/additional_properties.rb +29 -0
  40. data/lib/jsapi/meta/schema/base.rb +34 -29
  41. data/lib/jsapi/meta/schema/object.rb +9 -1
  42. data/lib/jsapi/meta/schema.rb +2 -1
  43. data/lib/jsapi/meta.rb +0 -1
  44. data/lib/jsapi/version.rb +1 -1
  45. metadata +10 -5
  46. data/lib/jsapi/meta/example/model.rb +0 -43
  47. data/lib/jsapi/meta/example/reference.rb +0 -14
  48. data/lib/jsapi/meta/example.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72aa6ad77a99ade6acb3d5c70b6521b640e012cccc7e9ab00b9d55db3062d4d6
4
- data.tar.gz: 96ec077740dde1963ca6b448662e1f4370f3bc0b54778db2d03d9447ba69aa3b
3
+ metadata.gz: 5740302f08b361b1f70f50844a1c3858e8bf2d29b781ea245ec201c2290fb3f4
4
+ data.tar.gz: 27f401b21f5fece8a1dd675ab8597a7822d101a3d738a6f5ef76e5a8969dca8d
5
5
  SHA512:
6
- metadata.gz: ec7997fbedc7c9035f9e36d5426b23502b87f4c4c654b1e02f93db711f514a8a434d371dc4761156165c439256ad3f339c7a151b1b35c8dcbf3d1e14f1fd4628
7
- data.tar.gz: 1f2952e80bf883302fd835f9425bae0bd2e7629b2746d3abec4b19a259c5abbd9869534b18eb6c69afd94a9397e13c7d86d78720f3573d92ef355b1e66b99fb0
6
+ metadata.gz: fe84b39402a26fa951058ba59fab7cc20e0e0321c74826b672bd65b87a4975d68f37517bfa54f62549f2287c3221702d4d338e312ae01551481f5a529a865f40
7
+ data.tar.gz: 476347dfb1a27d43dc42835d87a845a75806a7a6c6f721ad9e372d53d435650c685b9cf7c8cb70f34718dffc675e1536475851b841e549b50789f9f08965aa33
@@ -13,9 +13,9 @@ module Jsapi
13
13
  end
14
14
 
15
15
  # Performs an API operation by calling the given block. The request parameters are
16
- # passed as an instance of the operation's model class to the block. The object
17
- # returned by the block is implicitly rendered according to the appropriate
18
- # +response+ specification.
16
+ # passed as an instance of the operation's model class to the block. Parameter names
17
+ # are converted to snake case. The object returned by the block is implicitly rendered
18
+ # according to the appropriate +response+ specification.
19
19
  #
20
20
  # api_operation('foo') do |api_params|
21
21
  # # ...
@@ -53,6 +53,7 @@ module Jsapi
53
53
  end
54
54
 
55
55
  # Returns the request parameters as an instance of the operation's model class.
56
+ # Parameter names are converted to snake case.
56
57
  #
57
58
  # params = api_params('foo')
58
59
  #
@@ -129,6 +130,15 @@ module Jsapi
129
130
  response = operation.response(status)&.resolve(definitions)
130
131
  raise e if response.nil?
131
132
 
133
+ # Call on_rescue callbacks
134
+ definitions.on_rescue_callbacks.each do |callback|
135
+ if callback.respond_to?(:call)
136
+ callback.call(e)
137
+ else
138
+ send(callback, e)
139
+ end
140
+ end
141
+
132
142
  ErrorResult.new(e, status: status)
133
143
  end
134
144
  render(json: Response.new(result, response, definitions), status: status)
@@ -25,15 +25,12 @@ module Jsapi
25
25
  end
26
26
  request_body = operation.request_body&.resolve(definitions)
27
27
  if request_body && request_body.schema.respond_to?(:properties)
28
- meta_models.merge!(
29
- request_body.schema.resolve_properties(:write, definitions)
30
- )
28
+ meta_models.merge!(request_body.schema.resolve_properties(:write, definitions))
31
29
  end
32
30
 
33
31
  # Wrap params
34
32
  meta_models.each do |name, meta_model|
35
- @raw_attributes[name] =
36
- JSON.wrap(params[name], meta_model.schema, definitions)
33
+ @raw_attributes[name.underscore] = JSON.wrap(params[name], meta_model.schema, definitions)
37
34
  end
38
35
  end
39
36
 
@@ -5,8 +5,8 @@ module Jsapi
5
5
  # Used to serialize a response.
6
6
  class Response
7
7
 
8
- # Creates a new instance to serialize +object+ according to +response+. References are
9
- # resolved to API components in +definitions+.
8
+ # Creates a new instance to serialize +object+ according to +response+. References
9
+ # are resolved to API components in +definitions+.
10
10
  def initialize(object, response, definitions)
11
11
  @object = object
12
12
  @response = response
@@ -37,33 +37,13 @@ module Jsapi
37
37
 
38
38
  case schema.type
39
39
  when 'array'
40
- item_schema = schema.items.resolve(@definitions)
41
- Array(object).map { |item| serialize(item, item_schema, path) }
40
+ serialize_array(object, schema, path)
42
41
  when 'integer'
43
42
  schema.convert(object.to_i)
44
43
  when 'number'
45
44
  schema.convert(object.to_f)
46
45
  when 'object'
47
- return if object.blank? # {}
48
-
49
- # Select inherriting schema on polymorphism
50
- if (discriminator = schema.discriminator)
51
- discriminator_property = schema.properties[discriminator.property_name]
52
- schema = discriminator.resolve(
53
- object.public_send(
54
- discriminator_property.source || discriminator_property.name
55
- ),
56
- @definitions
57
- )
58
- end
59
- # Serialize properties
60
- schema.resolve_properties(:read, @definitions).transform_values do |property|
61
- serialize(
62
- object.public_send(property.source || property.name),
63
- property.schema.resolve(@definitions),
64
- path.nil? ? property.name : "#{path}.#{property.name}"
65
- )
66
- end
46
+ serialize_object(object, schema, path)
67
47
  when 'string'
68
48
  schema.convert(
69
49
  case schema.format
@@ -81,6 +61,48 @@ module Jsapi
81
61
  object
82
62
  end
83
63
  end
64
+
65
+ def serialize_array(array, schema, path)
66
+ item_schema = schema.items.resolve(@definitions)
67
+ Array(array).map { |item| serialize(item, item_schema, path) }
68
+ end
69
+
70
+ def serialize_object(object, schema, path)
71
+ return if object.blank? # {}
72
+
73
+ # Select inherriting schema on polymorphism
74
+ if (discriminator = schema.discriminator)
75
+ discriminator_property = schema.properties[discriminator.property_name]
76
+ schema = discriminator.resolve(
77
+ object.public_send(discriminator_property.source || discriminator_property.name.underscore),
78
+ @definitions
79
+ )
80
+ end
81
+ # Serialize properties
82
+ properties = schema.resolve_properties(:read, @definitions).transform_values do |property|
83
+ serialize(
84
+ object.public_send(property.source || property.name.underscore),
85
+ property.schema.resolve(@definitions),
86
+ path.nil? ? property.name : "#{path}.#{property.name}"
87
+ )
88
+ end
89
+ if (additional_properties = schema.additional_properties&.resolve(@definitions))
90
+ additional_properties_schema = additional_properties.schema.resolve(@definitions)
91
+
92
+ object.public_send(additional_properties.source)&.each do |key, value|
93
+ # Don't replace the property with the same key
94
+ next if properties.key?(key = key.to_s)
95
+
96
+ # Serialize the additional property
97
+ properties[key] = serialize(
98
+ value,
99
+ additional_properties_schema,
100
+ path.nil? ? key : "#{path}.#{key}"
101
+ )
102
+ end
103
+ end
104
+ properties
105
+ end
84
106
  end
85
107
  end
86
108
  end
@@ -15,6 +15,11 @@ module Jsapi
15
15
  api_definitions { include(*klasses) }
16
16
  end
17
17
 
18
+ # Registers a callback to be called when rescuing an exception.
19
+ def api_on_rescue(method = nil, &block)
20
+ api_definitions { on_rescue(method, &block) }
21
+ end
22
+
18
23
  # Defines an operation.
19
24
  #
20
25
  # api_operation 'foo', path: '/foo' do
@@ -12,6 +12,13 @@ module Jsapi
12
12
  end
13
13
  end
14
14
 
15
+ # Registers a callback to be called when rescuing an exception.
16
+ def on_rescue(method = nil, &block)
17
+ _define('on_rescue') do
18
+ _meta_model.add_on_rescue(method || block)
19
+ end
20
+ end
21
+
15
22
  # Defines the root of an \OpenAPI document.
16
23
  #
17
24
  # openapi do
@@ -11,16 +11,13 @@ module Jsapi
11
11
  def initialize(attributes, schema, definitions)
12
12
  # Select inherriting schema on polymorphism
13
13
  if (discriminator = schema.discriminator)
14
- schema = discriminator.resolve(
15
- attributes[discriminator.property_name],
16
- definitions
17
- )
14
+ schema = discriminator.resolve(attributes[discriminator.property_name], definitions)
18
15
  end
19
16
  # Wrap attribute values
20
- @raw_attributes = schema.resolve_properties(:write, definitions)
21
- .transform_values do |property|
22
- JSON.wrap(attributes[property.name], property.schema, definitions)
23
- end
17
+ @raw_attributes =
18
+ schema.resolve_properties(:write, definitions).transform_values do |property|
19
+ JSON.wrap(attributes[property.name], property.schema, definitions)
20
+ end
24
21
 
25
22
  super(schema)
26
23
  end
@@ -3,10 +3,11 @@
3
3
  module Jsapi
4
4
  module Meta
5
5
  class Definitions
6
- attr_reader :examples, :openapi_root, :operations, :parameters,
6
+ attr_reader :callbacks, :examples, :openapi_root, :operations, :parameters,
7
7
  :request_bodies, :rescue_handlers, :responses, :schemas
8
8
 
9
9
  def initialize(owner = nil)
10
+ @callbacks = { on_rescue: [] }
10
11
  @owner = owner
11
12
  @examples = {}
12
13
  @operations = {}
@@ -19,7 +20,11 @@ module Jsapi
19
20
  end
20
21
 
21
22
  def add_example(name, keywords = {})
22
- @examples[name.to_s] = Example.new(keywords)
23
+ @examples[name.to_s] = OpenAPI::Example.new(keywords)
24
+ end
25
+
26
+ def add_on_rescue(method_or_proc)
27
+ @callbacks[:on_rescue] << method_or_proc
23
28
  end
24
29
 
25
30
  def add_operation(name = nil, keywords = {})
@@ -86,6 +91,12 @@ module Jsapi
86
91
  end
87
92
  end
88
93
 
94
+ def on_rescue_callbacks
95
+ @self_and_included.flat_map do |definitions|
96
+ definitions.callbacks[:on_rescue]
97
+ end
98
+ end
99
+
89
100
  # Returns a hash representing the OpenAPI document for +version+.
90
101
  # Raises an +ArgumentError+ if +version+ is not supported.
91
102
  def openapi_document(version = nil)
@@ -101,15 +112,13 @@ module Jsapi
101
112
  responses: openapi_responses(version)
102
113
  )
103
114
  else
104
- h.deep_merge!(
105
- components: {
106
- schemas: openapi_schemas(version),
107
- parameters: openapi_parameters(version),
108
- requestBodies: openapi_request_bodies(version),
109
- responses: openapi_responses(version),
110
- examples: openapi_examples
111
- }.compact.presence
112
- )
115
+ h[:components] = (h[:components] || {}).merge(
116
+ schemas: openapi_schemas(version),
117
+ parameters: openapi_parameters(version),
118
+ requestBodies: openapi_request_bodies(version),
119
+ responses: openapi_responses(version),
120
+ examples: openapi_examples
121
+ ).compact.presence
113
122
  end
114
123
  end.compact
115
124
  end
@@ -23,7 +23,7 @@ module Jsapi
23
23
  @operations&.[](expression&.to_s)
24
24
  end
25
25
 
26
- # Returns a hash representing the callback object.
26
+ # Returns a hash representing the \OpenAPI callback object.
27
27
  def to_openapi(version, definitions)
28
28
  operations.transform_values do |operation|
29
29
  { operation.method => operation.to_openapi(version, definitions) }
@@ -5,6 +5,8 @@ module Jsapi
5
5
  module OpenAPI
6
6
  # Represents a contact object.
7
7
  class Contact < Base
8
+ include Extensions
9
+
8
10
  ##
9
11
  # :attr: email
10
12
  # The email address of the contact.
@@ -20,13 +22,9 @@ module Jsapi
20
22
  # The URL of the contact.
21
23
  attribute :url, String
22
24
 
23
- # Returns a hash representing the contact object.
25
+ # Returns a hash representing the \OpenAPI contact object.
24
26
  def to_openapi(*)
25
- {
26
- name: name,
27
- url: url,
28
- email: email
29
- }.compact
27
+ with_openapi_extensions(name: name, url: url, email: email)
30
28
  end
31
29
  end
32
30
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Example
7
+ class Model < Base
8
+ include Extensions
9
+
10
+ ##
11
+ # :attr: description
12
+ # The optional description of the example.
13
+ attribute :description, String
14
+
15
+ ##
16
+ # :attr: external
17
+ # If true, +value+ is interpreted as a URI pointing to an external sample value.
18
+ attribute :external, values: [true, false]
19
+
20
+ ##
21
+ # :attr: summary
22
+ # The optional summary of the example.
23
+ attribute :summary, String
24
+
25
+ ##
26
+ # :attr: value
27
+ # The sample value.
28
+ attribute :value
29
+
30
+ # Returns a hash representing the \OpenAPI example object.
31
+ def to_openapi(*)
32
+ with_openapi_extensions(summary: summary, description: description).tap do |hash|
33
+ if external?
34
+ hash[:external_value] = value
35
+ else
36
+ hash[:value] = value
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Example
7
+ class Reference < BaseReference
8
+ # Returns a hash representing the \OpenAPI reference object.
9
+ def to_openapi(*)
10
+ { '$ref': "#/components/examples/#{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 'example/model'
4
+ require_relative 'example/reference'
5
+
6
+ module Jsapi
7
+ module Meta
8
+ module OpenAPI
9
+ module Example
10
+ class << self
11
+ # Creates a new example 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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Extensions
7
+ # Adds an \OpenAPI extension.
8
+ #
9
+ # Raises an +ArgumentError+ if +name+ is blank.
10
+ def add_openapi_extension(name, value = nil)
11
+ raise ArgumentError, "name can't be blank" if name.blank?
12
+
13
+ openapi_extensions["x-#{name}".to_sym] = value
14
+ end
15
+
16
+ # Returns a hash containing the \OpenAPI extensions.
17
+ def openapi_extensions
18
+ @openapi_extensions ||= {}
19
+ end
20
+
21
+ private
22
+
23
+ def with_openapi_extensions(keywords = {}) # :nodoc:
24
+ keywords.merge!(openapi_extensions)
25
+ keywords.compact!
26
+ keywords
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -5,6 +5,8 @@ module Jsapi
5
5
  module OpenAPI
6
6
  # Represents an external documentation object.
7
7
  class ExternalDocumentation < Base
8
+ include Extensions
9
+
8
10
  ##
9
11
  # :attr: description
10
12
  # The optional description of the external documentation.
@@ -15,12 +17,9 @@ module Jsapi
15
17
  # The URL of the external documentation.
16
18
  attribute :url, String
17
19
 
18
- # Returns a hash representing the external documentation object.
20
+ # Returns a hash representing the \OpenAPI external documentation object.
19
21
  def to_openapi(*)
20
- {
21
- url: url,
22
- description: description
23
- }.compact
22
+ with_openapi_extensions(url: url, description: description)
24
23
  end
25
24
  end
26
25
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Header
7
+ class Model < Base
8
+ include Extensions
9
+
10
+ ##
11
+ # :attr: deprecated
12
+ # Specifies whether or not the header is deprecated.
13
+ attribute :deprecated, values: [true, false]
14
+
15
+ ##
16
+ # :attr: description
17
+ # The description of the header.
18
+ attribute :description, String
19
+
20
+ ##
21
+ # :attr_reader: examples
22
+ # One or more example values.
23
+ attribute :examples, { String => Example }, default_key: 'default'
24
+
25
+ ##
26
+ # :attr_reader: schema
27
+ # The Schema of the header.
28
+ attribute :schema, writer: false
29
+
30
+ delegate_missing_to :schema
31
+
32
+ def initialize(keywords = {})
33
+ keywords = keywords.dup
34
+ super(keywords.extract!(:deprecated, :description, :examples))
35
+
36
+ add_example(value: keywords.delete(:example)) if keywords.key?(:example)
37
+
38
+ @schema = Schema.new(keywords)
39
+ end
40
+
41
+ # Returns a hash representing the \OpenAPI header object.
42
+ def to_openapi(version)
43
+ version = OpenAPI::Version.from(version)
44
+
45
+ with_openapi_extensions(
46
+ if version.major == 2
47
+ schema.to_openapi(version).merge(
48
+ description: description
49
+ )
50
+ else
51
+ {
52
+ description: description,
53
+ deprecated: deprecated?.presence,
54
+ schema: schema.to_openapi(version),
55
+ examples: examples&.transform_values(&:to_openapi)
56
+ }
57
+ end
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module Meta
5
+ module OpenAPI
6
+ module Header
7
+ class Reference < BaseReference
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
@@ -0,0 +1,21 @@
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
@@ -5,6 +5,8 @@ module Jsapi
5
5
  module OpenAPI
6
6
  # Represents an info object.
7
7
  class Info < Base
8
+ include Extensions
9
+
8
10
  ##
9
11
  # :attr: contact
10
12
  # The optional Contact object.
@@ -35,16 +37,16 @@ module Jsapi
35
37
  # The version of the API.
36
38
  attribute :version, String
37
39
 
38
- # Returns a hash representing the info object.
40
+ # Returns a hash representing the \OpenAPI info object.
39
41
  def to_openapi(*)
40
- {
42
+ with_openapi_extensions(
41
43
  title: title,
42
44
  version: version,
43
45
  description: description,
44
46
  termsOfService: terms_of_service,
45
47
  contact: contact&.to_openapi,
46
48
  license: license&.to_openapi
47
- }.compact
49
+ )
48
50
  end
49
51
  end
50
52
  end
@@ -5,6 +5,8 @@ module Jsapi
5
5
  module OpenAPI
6
6
  # Represents a license object.
7
7
  class License < Base
8
+ include Extensions
9
+
8
10
  ##
9
11
  # :attr: name
10
12
  # The name of the license.
@@ -15,12 +17,9 @@ module Jsapi
15
17
  # The optional URL of the license.
16
18
  attribute :url, String
17
19
 
18
- # Returns a hash representing the license object.
20
+ # Returns a hash representing the \OpenAPI license object.
19
21
  def to_openapi(*)
20
- {
21
- name: name,
22
- url: url
23
- }.compact
22
+ with_openapi_extensions(name: name, url: url)
24
23
  end
25
24
  end
26
25
  end
@@ -6,6 +6,8 @@ module Jsapi
6
6
  module Link
7
7
  # Represents a link object.
8
8
  class Model < Base
9
+ include Extensions
10
+
9
11
  ##
10
12
  # :attr: description
11
13
  # The optional description of the link.
@@ -31,15 +33,15 @@ module Jsapi
31
33
  # The optional Server object.
32
34
  attribute :server, Server
33
35
 
34
- # Returns a hash representing the link object.
36
+ # Returns a hash representing the \OpenAPI link object.
35
37
  def to_openapi(*)
36
- {
38
+ with_openapi_extensions(
37
39
  operationId: operation_id,
38
40
  parameters: parameters,
39
41
  requestBody: request_body,
40
42
  description: description,
41
43
  server: server&.to_openapi
42
- }.compact
44
+ )
43
45
  end
44
46
  end
45
47
  end
@@ -5,6 +5,8 @@ module Jsapi
5
5
  module OpenAPI
6
6
  # Represents an OAuth flow object.
7
7
  class OAuthFlow < Base
8
+ include Extensions
9
+
8
10
  class Scope < Base
9
11
  ##
10
12
  # :attr: description
@@ -35,14 +37,14 @@ module Jsapi
35
37
  # The token URL to be used for the flow.
36
38
  attribute :token_url, String
37
39
 
38
- # Returns a hash representing the OAuth flow object.
40
+ # Returns a hash representing the \OpenAPI OAuth flow object.
39
41
  def to_openapi(version)
40
- {
42
+ with_openapi_extensions(
41
43
  authorizationUrl: authorization_url,
42
44
  tokenUrl: token_url,
43
45
  refreshUrl: (refresh_url if version.major > 2),
44
46
  scopes: scopes.transform_values(&:description)
45
- }.compact
47
+ )
46
48
  end
47
49
  end
48
50
  end