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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/taro/declarations.rb +12 -7
- data/lib/taro/export/base.rb +7 -1
- data/lib/taro/rails/response_validator.rb +3 -0
- data/lib/taro/rails/tasks/export.rake +3 -16
- data/lib/taro/types/base_type.rb +2 -1
- data/lib/taro/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 465c83896bfdecb2b6469916e9b1bc38ede0a250a8e065e51507318bc5819b21
|
|
4
|
+
data.tar.gz: 619861477867bfb5e5aee5e2321db250c5b7bd2b77e03a26f4794b44dcd3086d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 779d566f0deae14c83c6f6ed23dd0972ce1cb4c4835f789a5ac4e53f468c4074a5b39a0ba4751efe289a66c6a5f1eacce3cd8934d37c26d867c61c336ee7ac66
|
|
7
|
+
data.tar.gz: bad4460168d908f823e66e2c7419ccedfad511fdf77eb7a37652f5221ee8da0797ce3fde5ae4ce69dd6a9bbe7e138c038f8c91e98e561804a30c5ee6fc28e284
|
data/CHANGELOG.md
CHANGED
data/lib/taro/declarations.rb
CHANGED
|
@@ -8,26 +8,31 @@ module Taro
|
|
|
8
8
|
include Enumerable
|
|
9
9
|
|
|
10
10
|
def [](key)
|
|
11
|
-
|
|
11
|
+
data[key]
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def []=(key, declaration)
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
data.key?(key) && raise(Taro::InvariantError, "#{key} already declared")
|
|
16
|
+
data[key] = declaration
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def each(&)
|
|
20
|
-
|
|
20
|
+
data.each_value(&)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def reset
|
|
24
|
-
|
|
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
|
|
30
|
-
@
|
|
34
|
+
def data
|
|
35
|
+
@data ||= {}
|
|
31
36
|
end
|
|
32
37
|
end
|
|
33
38
|
end
|
data/lib/taro/export/base.rb
CHANGED
|
@@ -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
|
-
|
|
4
|
-
Rails.application.eager_load!
|
|
3
|
+
Taro::Export::OpenAPIv3.call.write_to_file
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
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
|
data/lib/taro/types/base_type.rb
CHANGED
|
@@ -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
|
-
#
|
|
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