taro 3.0.0 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66112afc92f209f1cea91ae5483f54c37e8d5a79635ebf616afa0b868bc13637
4
- data.tar.gz: fe46dcf993a314c1b2a5a08088010c523041a90bda55c121d81cf91ed665c11d
3
+ metadata.gz: 465c83896bfdecb2b6469916e9b1bc38ede0a250a8e065e51507318bc5819b21
4
+ data.tar.gz: 619861477867bfb5e5aee5e2321db250c5b7bd2b77e03a26f4794b44dcd3086d
5
5
  SHA512:
6
- metadata.gz: 48d2ba7713e024656b49845ff1053b42076450e23367fb01063f1dce4ac3b74cd1a13351ddc43eac11e678052da76ac51508af1ba41b746e05a10cccc4c2ae4a
7
- data.tar.gz: '08bd1115dcbb4240ed10edb7dbd52471c597cf5de98c85ef87be76dce9b4aef938cdc6b38ff8089c5ccfa3b684c887f75104e5ac5f9bc42eb8e3abe72e61a61c'
6
+ metadata.gz: 779d566f0deae14c83c6f6ed23dd0972ce1cb4c4835f789a5ac4e53f468c4074a5b39a0ba4751efe289a66c6a5f1eacce3cd8934d37c26d867c61c336ee7ac66
7
+ data.tar.gz: bad4460168d908f823e66e2c7419ccedfad511fdf77eb7a37652f5221ee8da0797ce3fde5ae4ce69dd6a9bbe7e138c038f8c91e98e561804a30c5ee6fc28e284
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Added
4
+
5
+ - `Taro::Export::Base#write_to_file` for writing schema files without the rake task
6
+ - `Taro.declarations.eager_load` for ensuring all declarations are loaded in Rails
7
+
3
8
  ## [3.0.0] - 2026-03-03
4
9
 
5
10
  ### Changed
@@ -8,26 +8,31 @@ module Taro
8
8
  include Enumerable
9
9
 
10
10
  def [](key)
11
- map[key]
11
+ data[key]
12
12
  end
13
13
 
14
14
  def []=(key, declaration)
15
- map.key?(key) && raise(Taro::InvariantError, "#{key} already declared")
16
- map[key] = declaration
15
+ data.key?(key) && raise(Taro::InvariantError, "#{key} already declared")
16
+ data[key] = declaration
17
17
  end
18
18
 
19
19
  def each(&)
20
- map.each_value(&)
20
+ data.each_value(&)
21
21
  end
22
22
 
23
23
  def reset
24
- map.clear
24
+ data.clear
25
+ end
26
+
27
+ def eager_load
28
+ ::Rails.application.eager_load! if defined?(::Rails.application.eager_load!)
29
+ self
25
30
  end
26
31
 
27
32
  private
28
33
 
29
- def map
30
- @map ||= {}
34
+ def data
35
+ @data ||= {}
31
36
  end
32
37
  end
33
38
  end
@@ -1,10 +1,16 @@
1
1
  class Taro::Export::Base
2
2
  attr_reader :result
3
3
 
4
- def self.call(declarations: Taro.declarations, title: Taro.config.api_name, version: Taro.config.api_version, **)
4
+ def self.call(declarations: Taro.declarations.eager_load, title: Taro.config.api_name, version: Taro.config.api_version, **)
5
5
  new.call(declarations:, title:, version:, **)
6
6
  end
7
7
 
8
+ def write_to_file(path: Taro.config.export_path, format: Taro.config.export_format)
9
+ data = __send__("to_#{format}") # e.g. to_json, to_yaml
10
+ FileUtils.mkdir_p(File.dirname(path))
11
+ File.write(path, data)
12
+ end
13
+
8
14
  def to_json(*)
9
15
  require 'json'
10
16
  JSON.pretty_generate(result)
@@ -1,3 +1,6 @@
1
+ # This runs on for every response,
2
+ # so we are using Struct instead of Data here for performance reasons:
3
+ # https://bugs.ruby-lang.org/issues/19693
1
4
  Taro::Rails::ResponseValidator = Struct.new(:controller, :declaration, :rendered) do
2
5
  def self.call(controller, declaration, rendered)
3
6
  new(controller, declaration, rendered).call
@@ -1,20 +1,7 @@
1
1
  desc 'Export all taro API declarations to a file'
2
2
  task 'taro:export' => :environment do
3
- # make sure all declarations have been seen
4
- Rails.application.eager_load!
3
+ Taro::Export::OpenAPIv3.call.write_to_file
5
4
 
6
- title = Taro.config.api_name
7
- version = Taro.config.api_version
8
- format = Taro.config.export_format
9
- path = Taro.config.export_path
10
- # the generator / openapi version might become a config option later
11
-
12
- export = Taro::Export::OpenAPIv3.call(title:, version:)
13
-
14
- data = export.send("to_#{format}")
15
-
16
- FileUtils.mkdir_p(File.dirname(path))
17
- File.write(path, data)
18
-
19
- puts "Exported the API #{title} v#{version} to #{path}"
5
+ puts "Exported the API #{Taro.config.api_name} " \
6
+ "v#{Taro.config.api_version} to #{Taro.config.export_path}"
20
7
  end
@@ -7,7 +7,8 @@
7
7
  # The object is a parameter hash for inputs and a manually passed hash
8
8
  # or object when rendering a response.
9
9
  #
10
- # Using Struct instead of Data here for performance reasons:
10
+ # The type initializer is a hot path for param parsing and response rendering,
11
+ # so we are using Struct instead of Data here for performance reasons:
11
12
  # https://bugs.ruby-lang.org/issues/19693
12
13
  Taro::Types::BaseType = Struct.new(:object) do
13
14
  require_relative "shared"
data/lib/taro/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # :nocov:
2
2
  module Taro
3
- VERSION = "3.0.0"
3
+ VERSION = "3.1.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taro
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller