jsapi 1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d62e2c954028d8795f7e82dc2f0cde0310120f7e2a545102f53acefb42bfc603
4
- data.tar.gz: ed65cf2695f95d4ff4622680ac54c601620974997f5cd2b5408fbe3deee62aef
3
+ metadata.gz: a24c58c515109ade6015fbd712e6d08f8ea0dc3e1b747ecd1e2430de0ad157d2
4
+ data.tar.gz: 98112b68df57d56b51f9edcaa2283069481fb0c2a494cde18cb35d0205917423
5
5
  SHA512:
6
- metadata.gz: f2cca6b7b9a4d37979d7350ed24b171c0557e11d13968bea7cc7d7ca39418d4cfa39099b68fcf9a00249151f27362e677318ab8223c64d66cbf20ca9b6576045
7
- data.tar.gz: cca09add16c901c819327e5391ab7a7d627434c3c1e4efdb6802fde5e053741b955748bce4708d0bcf8bee9ef46c9babf60949ef3d6f726e5f5f7feca7ef5d85
6
+ metadata.gz: e4e08e06bcfe77edb6b356a0f2aa00bc141bf1aae3c1fac09fdb61be36b7be27b24a8c698fcad63374936d2defa345cbb9328f5a6f486a9816ae21be0cd52853
7
+ data.tar.gz: 8b671d32824bdb6e924fd7bd11f16c3baeac90c8bd3ef7a3796d8a8220b574740f750cad6e79f986f4950b8659ca9bb151ad95d6cfe63beb95e6ed63e76e4a3a
@@ -15,7 +15,7 @@ module Jsapi
15
15
  # Performs an API operation by calling the given block. The request parameters are
16
16
  # passed as an instance of the operation's model class to the block. The object
17
17
  # returned by the block is implicitly rendered according to the appropriate +response+
18
- # specification.
18
+ # specification when the content type is a JSON MIME type.
19
19
  #
20
20
  # api_operation('foo') do |api_params|
21
21
  # # ...
@@ -151,9 +151,11 @@ module Jsapi
151
151
 
152
152
  Error.new(e, status: status)
153
153
  end
154
- response = Response.new(result, response_model, definitions, omit: omit)
155
154
 
156
155
  # Write response
156
+ return unless response_model.json_type?
157
+
158
+ response = Response.new(result, response_model, definitions, omit: omit)
157
159
  self.content_type = response_model.content_type
158
160
  render(json: response, status: status)
159
161
  end
@@ -7,6 +7,8 @@ module Jsapi
7
7
  class Base < Model::Base
8
8
  include OpenAPI::Extensions
9
9
 
10
+ JSON_TYPE = %r{(^application/|^text/|\+)json$}.freeze # :nodoc:
11
+
10
12
  delegate_missing_to :schema
11
13
 
12
14
  ##
@@ -58,6 +60,12 @@ module Jsapi
58
60
  @schema = Schema.new(keywords)
59
61
  end
60
62
 
63
+ # Returns true if content type is a JSON MIME type as specified by
64
+ # https://mimesniff.spec.whatwg.org/#json-mime-type.
65
+ def json_type?
66
+ content_type.match?(JSON_TYPE)
67
+ end
68
+
61
69
  # Returns a hash representing the \OpenAPI response object.
62
70
  def to_openapi(version, definitions)
63
71
  version = OpenAPI::Version.from(version)
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 = '1.0'
8
+ VERSION = '1.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: '1.0'
4
+ version: '1.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-11-01 00:00:00.000000000 Z
11
+ date: 2025-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: denis@dmgoeller.de