jsapi 0.3.0 → 0.4.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/controller/methods.rb +9 -0
  3. data/lib/jsapi/controller/parameters.rb +1 -1
  4. data/lib/jsapi/dsl/class_methods.rb +5 -0
  5. data/lib/jsapi/dsl/definitions.rb +7 -0
  6. data/lib/jsapi/meta/definitions.rb +20 -11
  7. data/lib/jsapi/meta/openapi/callback/model.rb +1 -1
  8. data/lib/jsapi/meta/openapi/contact.rb +1 -1
  9. data/lib/jsapi/meta/openapi/example/model.rb +44 -0
  10. data/lib/jsapi/meta/openapi/example/reference.rb +16 -0
  11. data/lib/jsapi/meta/openapi/example.rb +21 -0
  12. data/lib/jsapi/meta/openapi/external_documentation.rb +1 -1
  13. data/lib/jsapi/meta/openapi/header/model.rb +64 -0
  14. data/lib/jsapi/meta/openapi/header/reference.rb +16 -0
  15. data/lib/jsapi/meta/openapi/header.rb +21 -0
  16. data/lib/jsapi/meta/openapi/info.rb +1 -1
  17. data/lib/jsapi/meta/openapi/license.rb +1 -1
  18. data/lib/jsapi/meta/openapi/link/model.rb +1 -1
  19. data/lib/jsapi/meta/openapi/oauth_flow.rb +1 -1
  20. data/lib/jsapi/meta/openapi/root.rb +8 -0
  21. data/lib/jsapi/meta/openapi/security_requirement.rb +1 -1
  22. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +1 -1
  23. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +1 -1
  24. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +1 -1
  25. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +1 -1
  26. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +1 -1
  27. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +1 -1
  28. data/lib/jsapi/meta/openapi/server.rb +1 -1
  29. data/lib/jsapi/meta/openapi/server_variable.rb +1 -1
  30. data/lib/jsapi/meta/openapi/tag.rb +1 -1
  31. data/lib/jsapi/meta/openapi.rb +2 -0
  32. data/lib/jsapi/meta/parameter/model.rb +1 -1
  33. data/lib/jsapi/meta/request_body/model.rb +1 -1
  34. data/lib/jsapi/meta/response/model.rb +10 -1
  35. data/lib/jsapi/meta.rb +0 -1
  36. data/lib/jsapi/version.rb +1 -1
  37. metadata +8 -5
  38. data/lib/jsapi/meta/example/model.rb +0 -42
  39. data/lib/jsapi/meta/example/reference.rb +0 -14
  40. data/lib/jsapi/meta/example.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78a92c9f73f4a39ede65ad5b0b5646db67dc8b9e2b3ca444b6de32fdb75e349a
4
- data.tar.gz: e235535541854c172f578cce7cf112ceebe880971643cb33125a76cc61bbd88a
3
+ metadata.gz: d672ecea7da1c27309fe576ceacc537286529da833a37726f8e34299b33d7d48
4
+ data.tar.gz: 9d2d663c47dc498def2c9ce60b73029bfba52a0a2b15690e4a41b4a0bed3d70a
5
5
  SHA512:
6
- metadata.gz: 7c139744bacb90f772bb40779a8d149daf025dd838ffc3268c35640dfe18da1934e62ffd2e319658478ef5c4d54a4f630ed76eabf60a22df641f1ce7da218150
7
- data.tar.gz: b9e72517dea9061eaa23b5ff5631745a18769614c04d2a91ae97db2e715c30504bc5b849fdcaa89384f7fb2618e5ea639601f637b9583b5fec219bd053006f08
6
+ metadata.gz: 241798754adbc58ad39ecf1d238977ec5b7bba2f557b2d4fd5190eb9cc4b14db5afeeb61cc48a6e1435be03178b95e0728deaa4d5afa3b58758becc765ee9105
7
+ data.tar.gz: b8823805ad8cf8d09dd72a8ef930086bcb3f4554ad9f868f7a6554062f263bd450fe14f01f21fbfb58b47577681d86a8fd9e5655a0ed522833e223c7478a278e
@@ -130,6 +130,15 @@ module Jsapi
130
130
  response = operation.response(status)&.resolve(definitions)
131
131
  raise e if response.nil?
132
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
+
133
142
  ErrorResult.new(e, status: status)
134
143
  end
135
144
  render(json: Response.new(result, response, definitions), status: status)
@@ -45,7 +45,7 @@ module Jsapi
45
45
  [
46
46
  validate_attributes(errors),
47
47
  !@strong || validate_parameters(
48
- @params.except(:controller, :action),
48
+ @params.except(:controller, :action, :format),
49
49
  attributes,
50
50
  errors
51
51
  )
@@ -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
@@ -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) }
@@ -22,7 +22,7 @@ module Jsapi
22
22
  # The URL of the contact.
23
23
  attribute :url, String
24
24
 
25
- # Returns a hash representing the contact object.
25
+ # Returns a hash representing the \OpenAPI contact object.
26
26
  def to_openapi(*)
27
27
  with_openapi_extensions(name: name, url: url, email: email)
28
28
  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
@@ -17,7 +17,7 @@ module Jsapi
17
17
  # The URL of the external documentation.
18
18
  attribute :url, String
19
19
 
20
- # Returns a hash representing the external documentation object.
20
+ # Returns a hash representing the \OpenAPI external documentation object.
21
21
  def to_openapi(*)
22
22
  with_openapi_extensions(url: url, description: description)
23
23
  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
@@ -37,7 +37,7 @@ module Jsapi
37
37
  # The version of the API.
38
38
  attribute :version, String
39
39
 
40
- # Returns a hash representing the info object.
40
+ # Returns a hash representing the \OpenAPI info object.
41
41
  def to_openapi(*)
42
42
  with_openapi_extensions(
43
43
  title: title,
@@ -17,7 +17,7 @@ module Jsapi
17
17
  # The optional URL of the license.
18
18
  attribute :url, String
19
19
 
20
- # Returns a hash representing the license object.
20
+ # Returns a hash representing the \OpenAPI license object.
21
21
  def to_openapi(*)
22
22
  with_openapi_extensions(name: name, url: url)
23
23
  end
@@ -33,7 +33,7 @@ module Jsapi
33
33
  # The optional Server object.
34
34
  attribute :server, Server
35
35
 
36
- # Returns a hash representing the link object.
36
+ # Returns a hash representing the \OpenAPI link object.
37
37
  def to_openapi(*)
38
38
  with_openapi_extensions(
39
39
  operationId: operation_id,
@@ -37,7 +37,7 @@ module Jsapi
37
37
  # The token URL to be used for the flow.
38
38
  attribute :token_url, String
39
39
 
40
- # Returns a hash representing the OAuth flow object.
40
+ # Returns a hash representing the \OpenAPI OAuth flow object.
41
41
  def to_openapi(version)
42
42
  with_openapi_extensions(
43
43
  authorizationUrl: authorization_url,
@@ -31,6 +31,11 @@ module Jsapi
31
31
  # The optional ExternalDocumentation object.
32
32
  attribute :external_docs, ExternalDocumentation
33
33
 
34
+ ##
35
+ # :attr: headers
36
+ # The reusable Header objects. Applies to \OpenAPI 3.0 and higher.
37
+ attribute :headers, { String => Header }
38
+
34
39
  ##
35
40
  # :attr: host
36
41
  # The host serving the API. Applies to \OpenAPI 2.0.
@@ -122,6 +127,9 @@ module Jsapi
122
127
  callbacks: callbacks&.transform_values do |callback|
123
128
  callback.to_openapi(version, definitions)
124
129
  end,
130
+ headers: headers&.transform_values do |header|
131
+ header.to_openapi(version)
132
+ end,
125
133
  links: links&.transform_values(&:to_openapi),
126
134
  securitySchemes: security_schemes
127
135
  }.compact.presence,
@@ -17,7 +17,7 @@ module Jsapi
17
17
  # The schemes.
18
18
  attribute :schemes, { String => Scheme }
19
19
 
20
- # Returns a hash representing the security requirement object.
20
+ # Returns a hash representing the \OpenAPI security requirement object.
21
21
  def to_openapi(*)
22
22
  schemes&.transform_values(&:scopes) || {}
23
23
  end
@@ -24,7 +24,7 @@ module Jsapi
24
24
  # API key is sent by.
25
25
  attribute :name, String
26
26
 
27
- # Returns a hash representing the security scheme object.
27
+ # Returns a hash representing the \OpenAPI security scheme object.
28
28
  def to_openapi(*)
29
29
  with_openapi_extensions(
30
30
  type: 'apiKey',
@@ -9,7 +9,7 @@ module Jsapi
9
9
  class Basic < Base
10
10
  include Extensions
11
11
 
12
- # Returns a hash representing the security scheme object.
12
+ # Returns a hash representing the \OpenAPI security scheme object.
13
13
  def to_openapi(version)
14
14
  version = OpenAPI::Version.from(version)
15
15
 
@@ -18,7 +18,7 @@ module Jsapi
18
18
  # The optional format of the bearer token.
19
19
  attribute :bearer_format, String
20
20
 
21
- # Returns a hash representing the security scheme object, or
21
+ # Returns a hash representing the \OpenAPI security scheme object, or
22
22
  # +nil+ if <code>version.major</code> is 2.
23
23
  def to_openapi(version)
24
24
  version = OpenAPI::Version.from(version)
@@ -19,7 +19,7 @@ module Jsapi
19
19
  # The mandatory \HTTP authentication scheme.
20
20
  attribute :scheme, String
21
21
 
22
- # Returns a hash representing the security scheme object, or +nil+
22
+ # Returns a hash representing the \OpenAPI security scheme object, or +nil+
23
23
  # if <code>version.major</code> is 2.
24
24
  def to_openapi(version)
25
25
  version = OpenAPI::Version.from(version)
@@ -21,7 +21,7 @@ module Jsapi
21
21
  attribute :oauth_flows, { String => OAuthFlow },
22
22
  keys: %w[authorization_code client_credentials implicit password]
23
23
 
24
- # Returns a hash representing the security scheme object.
24
+ # Returns a hash representing the \OpenAPI security scheme object.
25
25
  def to_openapi(version)
26
26
  version = Version.from(version)
27
27
 
@@ -15,7 +15,7 @@ module Jsapi
15
15
  # :attr: open_id_connect_url
16
16
  attribute :open_id_connect_url, String
17
17
 
18
- # Returns a hash representing the security scheme object, or +nil+
18
+ # Returns a hash representing the \OpenAPI security scheme object, or +nil+
19
19
  # if <code>version.major</code> is 2.
20
20
  def to_openapi(version)
21
21
  version = Version.from(version)
@@ -22,7 +22,7 @@ module Jsapi
22
22
  # The optional server variables.
23
23
  attribute :variables, { String => ServerVariable }
24
24
 
25
- # Returns a hash representing the server object.
25
+ # Returns a hash representing the \OpenAPI server object.
26
26
  def to_openapi(*)
27
27
  with_openapi_extensions(
28
28
  url: url,
@@ -22,7 +22,7 @@ module Jsapi
22
22
  # The values of the server variable.
23
23
  attribute :enum, [String]
24
24
 
25
- # Returns a hash representing the server variable object.
25
+ # Returns a hash representing the \OpenAPI server variable object.
26
26
  def to_openapi(*)
27
27
  with_openapi_extensions(
28
28
  default: default,
@@ -22,7 +22,7 @@ module Jsapi
22
22
  # The name of the tag.
23
23
  attribute :name, String
24
24
 
25
- # Returns a hash representing the tag object.
25
+ # Returns a hash representing the \OpenAPI tag object.
26
26
  def to_openapi(*)
27
27
  with_openapi_extensions(
28
28
  name: name,
@@ -6,7 +6,9 @@ require_relative 'openapi/callback'
6
6
  require_relative 'openapi/contact'
7
7
  require_relative 'openapi/license'
8
8
  require_relative 'openapi/info'
9
+ require_relative 'openapi/example'
9
10
  require_relative 'openapi/external_documentation'
11
+ require_relative 'openapi/header'
10
12
  require_relative 'openapi/oauth_flow'
11
13
  require_relative 'openapi/security_scheme'
12
14
  require_relative 'openapi/security_requirement'
@@ -19,7 +19,7 @@ module Jsapi
19
19
  ##
20
20
  # :attr_reader: examples
21
21
  # The examples.
22
- attribute :examples, { String => Example }, default_key: 'default'
22
+ attribute :examples, { String => OpenAPI::Example }, default_key: 'default'
23
23
 
24
24
  ##
25
25
  # :attr: in
@@ -14,7 +14,7 @@ module Jsapi
14
14
  ##
15
15
  # :attr_reader: examples
16
16
  # The optional examples.
17
- attribute :examples, { String => Example }, default_key: 'default'
17
+ attribute :examples, { String => OpenAPI::Example }, default_key: 'default'
18
18
 
19
19
  ##
20
20
  # :attr_reader: schema
@@ -14,7 +14,12 @@ module Jsapi
14
14
  ##
15
15
  # :attr: examples
16
16
  # The optional examples.
17
- attribute :examples, { String => Example }, default_key: 'default'
17
+ attribute :examples, { String => OpenAPI::Example }, default_key: 'default'
18
+
19
+ ##
20
+ # :attr: headers
21
+ # The response headers.
22
+ attribute :headers, { String => OpenAPI::Header }
18
23
 
19
24
  ##
20
25
  # :attr: links
@@ -52,6 +57,9 @@ module Jsapi
52
57
  {
53
58
  description: description,
54
59
  schema: schema.to_openapi(version),
60
+ headers: headers&.transform_values do |header|
61
+ header.to_openapi(version) unless header.reference?
62
+ end&.compact,
55
63
  examples: (
56
64
  if (example = examples&.values&.first).present?
57
65
  { 'application/json' => example.resolve(definitions).value }
@@ -67,6 +75,7 @@ module Jsapi
67
75
  examples: examples&.transform_values(&:to_openapi)
68
76
  }.compact
69
77
  },
78
+ headers: headers&.transform_values { |header| header.to_openapi(version) },
70
79
  links: links&.transform_values(&:to_openapi)
71
80
  }
72
81
  end
data/lib/jsapi/meta.rb CHANGED
@@ -6,7 +6,6 @@ require_relative 'meta/attributes'
6
6
  require_relative 'meta/base'
7
7
  require_relative 'meta/base_reference'
8
8
  require_relative 'meta/openapi'
9
- require_relative 'meta/example'
10
9
  require_relative 'meta/existence'
11
10
  require_relative 'meta/property'
12
11
  require_relative 'meta/schema'
data/lib/jsapi/version.rb CHANGED
@@ -5,6 +5,6 @@ module Jsapi
5
5
  # NOTE: See https://bundler.io/guides/creating_gem.html
6
6
 
7
7
  # The current GEM version.
8
- VERSION = '0.3.0'
8
+ VERSION = '0.4.1'
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Göller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-14 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Jsapi can be used to read requests, produce responses and create OpenAPI
14
14
  documents
@@ -56,9 +56,6 @@ files:
56
56
  - lib/jsapi/meta/base.rb
57
57
  - lib/jsapi/meta/base_reference.rb
58
58
  - lib/jsapi/meta/definitions.rb
59
- - lib/jsapi/meta/example.rb
60
- - lib/jsapi/meta/example/model.rb
61
- - lib/jsapi/meta/example/reference.rb
62
59
  - lib/jsapi/meta/existence.rb
63
60
  - lib/jsapi/meta/invalid_argument_error.rb
64
61
  - lib/jsapi/meta/openapi.rb
@@ -66,8 +63,14 @@ files:
66
63
  - lib/jsapi/meta/openapi/callback/model.rb
67
64
  - lib/jsapi/meta/openapi/callback/reference.rb
68
65
  - lib/jsapi/meta/openapi/contact.rb
66
+ - lib/jsapi/meta/openapi/example.rb
67
+ - lib/jsapi/meta/openapi/example/model.rb
68
+ - lib/jsapi/meta/openapi/example/reference.rb
69
69
  - lib/jsapi/meta/openapi/extensions.rb
70
70
  - lib/jsapi/meta/openapi/external_documentation.rb
71
+ - lib/jsapi/meta/openapi/header.rb
72
+ - lib/jsapi/meta/openapi/header/model.rb
73
+ - lib/jsapi/meta/openapi/header/reference.rb
71
74
  - lib/jsapi/meta/openapi/info.rb
72
75
  - lib/jsapi/meta/openapi/license.rb
73
76
  - lib/jsapi/meta/openapi/link.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module Example
6
- class Model < Base
7
- include OpenAPI::Extensions
8
-
9
- ##
10
- # :attr: description
11
- # The optional description of the example.
12
- attribute :description, String
13
-
14
- ##
15
- # :attr: external
16
- # If true, +value+ is interpreted as a URI pointing to an external sample value.
17
- attribute :external, values: [true, false]
18
-
19
- ##
20
- # :attr: summary
21
- # The optional summary of the example.
22
- attribute :summary, String
23
-
24
- ##
25
- # :attr: value
26
- # The sample value.
27
- attribute :value
28
-
29
- # Returns a hash representing the \OpenAPI example object.
30
- def to_openapi(*)
31
- with_openapi_extensions(summary: summary, description: description).tap do |hash|
32
- if external?
33
- hash[:external_value] = value
34
- else
35
- hash[:value] = value
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jsapi
4
- module Meta
5
- module Example
6
- class Reference < BaseReference
7
- # Returns a hash representing the \OpenAPI reference object.
8
- def to_openapi(*)
9
- { '$ref': "#/components/examples/#{ref}" }
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,19 +0,0 @@
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 Example
9
- class << self
10
- # Creates a new example 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