explicit 0.2.16 → 0.2.17

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: 6ea020d82544c742432038439630cad304e496fb33335e44de226db513feacbe
4
- data.tar.gz: f733ee198a502d8962e5e726527153f28e924e275ddbe7f965e7b8dc89ee74f9
3
+ metadata.gz: 28e91e624223bafc22d197130a6ae5973f6a2364f6dd192d8e2f70b74fe88968
4
+ data.tar.gz: 3fcacbe34bd45dc3b988f703f05928a65af46f284b498a64e83f12539cc2ef86
5
5
  SHA512:
6
- metadata.gz: 31c95c4c1751c84cc4e02a2141bc209005700ac8aba906caecfbaf38193e92d43ad42832bd37a844487ccfc0f7ed433689e078545baf5b35d2db267bff419eff
7
- data.tar.gz: fcbdf61db1ed115b8d0e8c28ff0ba7ea434f4c6c4096dda5e3b238777709a2797d4279906deba7cea11364b90ee2bb43bfeb4b846aad12098b1f2ce84ae6c0de
6
+ metadata.gz: bc53aeced2b49c6667fb723a681d8e01b8e2529713a07f142281d2b2bcd40dc619c435c08ad7d7aee38aeceac7e053fd2d46a8e2d438bf82211a4fbd63ba12b7
7
+ data.tar.gz: cf4995522dab379e5277ac328e55968d0bc30b8850d64fcf7fb25b7afb9eae0c0c865df0813b7578dbff0d91f179b10a32e51b4c9b797932ab1aec95091c54ba
data/README.md CHANGED
@@ -45,6 +45,7 @@ documented types at runtime.
45
45
  - [Customizing error messages](#customizing-error-messages)
46
46
  - [Customizing error serialization](#customizing-error-serialization)
47
47
  - [Raise on invalid example](#raise-on-invalid-example)
48
+ - [CORS](#cors)
48
49
 
49
50
  # Installation
50
51
 
@@ -841,7 +842,20 @@ end
841
842
 
842
843
  ### Raise on invalid example
843
844
 
845
+ When adding a request example with `example(params:, response:)`, the response
846
+ must match the documented types. If it doesn't match, Explicit logs a warning,
847
+ but you can choose a more strict behaviour that raises an error instead.
848
+
844
849
  ```ruby
845
850
  config.raise_on_invalid_example = true # default is false
846
851
  config.raise_on_invalid_example = ::Rails.env.development? # recommended
847
852
  ```
853
+
854
+ ### CORS
855
+
856
+ Enable/disable [CORS headers](https://github.com/luizpvas/explicit/blob/main/lib/explicit/documentation/output/swagger.rb#L67-L74)
857
+ support.
858
+
859
+ ```ruby
860
+ config.cors_enabled = true
861
+ ```
@@ -6,6 +6,7 @@ module Explicit
6
6
  class Configuration
7
7
  def initialize
8
8
  @rescue_from_invalid_params = true
9
+ @cors_enabled = !defined?(::Rack::Cors)
9
10
  end
10
11
 
11
12
  def request_examples_file_path=(path)
@@ -36,6 +37,14 @@ module Explicit
36
37
  @raise_on_invalid_example
37
38
  end
38
39
 
40
+ def cors_enabled=(enabled)
41
+ @cors_enabled = enabled
42
+ end
43
+
44
+ def cors_enabled?
45
+ @cors_enabled
46
+ end
47
+
39
48
  def test_runner=(test_runner)
40
49
  @test_runner = test_runner
41
50
  end
@@ -65,6 +65,8 @@ module Explicit::Documentation::Output
65
65
  end
66
66
 
67
67
  def cors_access_control_headers
68
+ return {} if !::Explicit.configuration.cors_enabled?
69
+
68
70
  {
69
71
  "Access-Control-Allow-Origin" => "*",
70
72
  "Access-Control-Allow-Methods" => "GET, OPTIONS",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Explicit
4
- VERSION = "0.2.16"
4
+ VERSION = "0.2.17"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: explicit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Vasconcellos