apia 3.7.0 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3488b6d92d65ff71eff5ec22b944622042981311d6a7505fc09578093a9e4402
4
- data.tar.gz: aff3ff29a9674a4eb622e91a89e74d380e11728e683407e3e9bc1546641ea483
3
+ metadata.gz: 5516f53625b231f86ae297b41c2b3939058685ec3ab69ce6cd210c2fc25c277a
4
+ data.tar.gz: 051c427ba4ba188b61a14071f2c36ca4c90509a109126c8336e43b4a3c59b435
5
5
  SHA512:
6
- metadata.gz: 749d596efa11efc2965952a4ae2fc6af4c62fb9189e1839675ca3e00040fb4c4a99ab888d2e1589b546b002434e019735c1896398d494404d8cc7bd8a7e6f944
7
- data.tar.gz: 682ff1cf40fe2399ae2754ef9e78388282cfe8c28b38b7153425565ab568084826d7d49fccdbaf5a539e80bd4b4cfa79e1b968258ebb5e23525f14b4d3051c58
6
+ metadata.gz: 43a29e0260f50c640a34c88d3224f446911dc5defdb4e21e5a617e80af27b1c87d1495f8d8a5a164d49ab747836f5d19dc6303bff916e0f7c4eae24c1f704209
7
+ data.tar.gz: ed2d4c4f0c69b0455f16948f811e82dfc1f2867a1edaef9850151c693d3642c9bcbf5c7e9eb6a4df2c4334a2dd16e324e44ee7adc30a1685c301a2a832aa6d6f
@@ -37,7 +37,7 @@ module Apia
37
37
  # API.
38
38
  #
39
39
  # @param errors [Apia::ManifestErrors]
40
- # @reeturn [void]
40
+ # @return [void]
41
41
  def validate(errors)
42
42
  unless code.is_a?(Symbol)
43
43
  errors.add self, 'InvalidCode', 'Code must be a symbol'
@@ -69,7 +69,7 @@ module Apia
69
69
 
70
70
  field :pagination, type: PaginationObject
71
71
  end
72
- super(name, *args, type: type, **options, &block)
72
+ super
73
73
  end
74
74
 
75
75
  def fields(fieldset)
data/lib/apia/endpoint.rb CHANGED
@@ -47,7 +47,7 @@ module Apia
47
47
  response = Response.new(request, self)
48
48
  environment = RequestEnvironment.new(request, response)
49
49
 
50
- catch_errors(response) do
50
+ catch_errors(response, environment) do
51
51
  # Determine an authenticator for this endpoint
52
52
  request.authenticator = definition.authenticator || request.controller&.definition&.authenticator || request.api&.definition&.authenticator
53
53
 
@@ -92,10 +92,14 @@ module Apia
92
92
  #
93
93
  # @param response [Apia::Response]
94
94
  # @return [void]
95
- def catch_errors(response)
95
+ def catch_errors(response, environment)
96
96
  yield
97
97
  rescue Apia::RuntimeError => e
98
- catch_errors(response) do
98
+ # If the error was triggered by the authenticator, the cors headers wont yet have been merged
99
+ # so ensure cors headers are merged here
100
+ response.headers.merge!(environment.cors.to_headers)
101
+
102
+ catch_errors(response, environment) do
99
103
  response.body = { error: e.hash }
100
104
  response.status = e.http_status
101
105
  response.headers['x-api-schema'] = 'json-error'
data/lib/apia/request.rb CHANGED
@@ -36,7 +36,7 @@ module Apia
36
36
  end
37
37
 
38
38
  def body?
39
- has_header?('rack.input')
39
+ has_header?(::Rack::RACK_INPUT)
40
40
  end
41
41
 
42
42
  def params
data/lib/apia/response.rb CHANGED
@@ -70,11 +70,14 @@ module Apia
70
70
  #
71
71
  # @return [Array]
72
72
  def rack_triplet
73
- case @type
74
- when JSON
75
- Rack.json_triplet(body, headers: headers, status: status)
76
- when PLAIN
73
+ # Errors will always be sent as a hash intended for JSON encoding,
74
+ # even if the endpoint specifies a plain text response, so only
75
+ # send a pain response if the type is plaintext _and_ the body is
76
+ # a string
77
+ if @type == PLAIN && body.is_a?(String)
77
78
  Rack.plain_triplet(body, headers: headers, status: status)
79
+ else
80
+ Rack.json_triplet(body, headers: headers, status: status)
78
81
  end
79
82
  end
80
83
 
data/lib/apia/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apia
4
4
 
5
- VERSION = '3.7.0'
5
+ VERSION = '3.7.2'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apia
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json