taro 0.0.0 → 1.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/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +10 -0
- data/README.md +257 -1
- data/Rakefile +11 -0
- data/lib/taro/config.rb +22 -0
- data/lib/taro/errors.rb +12 -0
- data/lib/taro/export/base.rb +29 -0
- data/lib/taro/export/open_api_v3.rb +190 -0
- data/lib/taro/export.rb +3 -0
- data/lib/taro/rails/active_declarations.rb +19 -0
- data/lib/taro/rails/declaration.rb +118 -0
- data/lib/taro/rails/declaration_buffer.rb +24 -0
- data/lib/taro/rails/dsl.rb +18 -0
- data/lib/taro/rails/generators/install_generator.rb +19 -0
- data/lib/taro/rails/generators/templates/enum_type.erb +4 -0
- data/lib/taro/rails/generators/templates/error_type.erb +10 -0
- data/lib/taro/rails/generators/templates/errors_type.erb +25 -0
- data/lib/taro/rails/generators/templates/input_type.erb +4 -0
- data/lib/taro/rails/generators/templates/no_content_type.erb +4 -0
- data/lib/taro/rails/generators/templates/object_type.erb +4 -0
- data/lib/taro/rails/generators/templates/scalar_type.erb +4 -0
- data/lib/taro/rails/generators.rb +3 -0
- data/lib/taro/rails/normalized_route.rb +29 -0
- data/lib/taro/rails/param_parsing.rb +19 -0
- data/lib/taro/rails/railtie.rb +15 -0
- data/lib/taro/rails/response_validation.rb +13 -0
- data/lib/taro/rails/response_validator.rb +109 -0
- data/lib/taro/rails/route_finder.rb +35 -0
- data/lib/taro/rails/tasks/export.rake +15 -0
- data/lib/taro/rails.rb +17 -0
- data/lib/taro/types/base_type.rb +17 -0
- data/lib/taro/types/coercion.rb +73 -0
- data/lib/taro/types/enum_type.rb +43 -0
- data/lib/taro/types/field.rb +78 -0
- data/lib/taro/types/field_validation.rb +27 -0
- data/lib/taro/types/input_type.rb +13 -0
- data/lib/taro/types/list_type.rb +30 -0
- data/lib/taro/types/object_type.rb +19 -0
- data/lib/taro/types/object_types/free_form_type.rb +13 -0
- data/lib/taro/types/object_types/no_content_type.rb +16 -0
- data/lib/taro/types/object_types/page_info_type.rb +6 -0
- data/lib/taro/types/object_types/page_type.rb +45 -0
- data/lib/taro/types/scalar/boolean_type.rb +19 -0
- data/lib/taro/types/scalar/float_type.rb +15 -0
- data/lib/taro/types/scalar/integer_type.rb +11 -0
- data/lib/taro/types/scalar/iso8601_date_type.rb +23 -0
- data/lib/taro/types/scalar/iso8601_datetime_type.rb +25 -0
- data/lib/taro/types/scalar/string_type.rb +15 -0
- data/lib/taro/types/scalar/timestamp_type.rb +23 -0
- data/lib/taro/types/scalar/uuid_v4_type.rb +22 -0
- data/lib/taro/types/scalar_type.rb +7 -0
- data/lib/taro/types/shared/additional_properties.rb +12 -0
- data/lib/taro/types/shared/custom_field_resolvers.rb +33 -0
- data/lib/taro/types/shared/derivable_types.rb +9 -0
- data/lib/taro/types/shared/description.rb +9 -0
- data/lib/taro/types/shared/errors.rb +13 -0
- data/lib/taro/types/shared/fields.rb +57 -0
- data/lib/taro/types/shared/item_type.rb +16 -0
- data/lib/taro/types/shared/object_coercion.rb +16 -0
- data/lib/taro/types/shared/openapi_name.rb +30 -0
- data/lib/taro/types/shared/openapi_type.rb +27 -0
- data/lib/taro/types/shared/rendering.rb +22 -0
- data/lib/taro/types/shared.rb +3 -0
- data/lib/taro/types.rb +3 -0
- data/lib/taro/version.rb +2 -3
- data/lib/taro.rb +1 -6
- data/tasks/benchmark.rake +40 -0
- data/tasks/benchmark_1kb.json +23 -0
- metadata +91 -7
@@ -0,0 +1,22 @@
|
|
1
|
+
# The `::render` method is intended for use in controllers.
|
2
|
+
# Special types (e.g. PageType) may accept kwargs for `#coerce_response`.
|
3
|
+
module Taro::Types::Shared::Rendering
|
4
|
+
def render(object, opts = {})
|
5
|
+
result = new(object).coerce_response(**opts)
|
6
|
+
self.last_render = [self, result.__id__]
|
7
|
+
result
|
8
|
+
end
|
9
|
+
|
10
|
+
def last_render=(info)
|
11
|
+
ActiveSupport::IsolatedExecutionState[:taro_last_render] = info
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_render
|
15
|
+
ActiveSupport::IsolatedExecutionState[:taro_last_render]
|
16
|
+
end
|
17
|
+
|
18
|
+
# get the last used type for assertions in tests/specs
|
19
|
+
def used_in_response
|
20
|
+
last_render.to_a.first
|
21
|
+
end
|
22
|
+
end
|
data/lib/taro/types.rb
ADDED
data/lib/taro/version.rb
CHANGED
data/lib/taro.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
task :benchmark do
|
2
|
+
require 'benchmark/ips'
|
3
|
+
require 'json'
|
4
|
+
require_relative '../lib/taro'
|
5
|
+
|
6
|
+
data = JSON.load_file("#{__dir__}/benchmark_1kb.json", symbolize_names: true)
|
7
|
+
|
8
|
+
item_type = Class.new(Taro::Types::ObjectType) do
|
9
|
+
field :name, type: 'String', null: false
|
10
|
+
field :language, type: 'String', null: false
|
11
|
+
field :id, type: 'String', null: false
|
12
|
+
field :bio, type: 'String', null: false
|
13
|
+
field :version, type: 'Float', null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
type = Taro::Types::ListType.for(item_type)
|
17
|
+
|
18
|
+
# 143.889k (± 2.7%) i/s - 723.816k in 5.034247s
|
19
|
+
Benchmark.ips do |x|
|
20
|
+
x.report('parse 1 KB of params') { type.new(data).coerce_input }
|
21
|
+
end
|
22
|
+
|
23
|
+
# 103.382k (± 6.5%) i/s - 522.550k in 5.087725s
|
24
|
+
Benchmark.ips do |x|
|
25
|
+
x.report('validate a 1 KB response') { type.new(data).coerce_response }
|
26
|
+
end
|
27
|
+
|
28
|
+
big_data = data * 1000
|
29
|
+
big_data.each { |el| el.merge('version' => rand) }
|
30
|
+
|
31
|
+
# 101.359 (± 5.9%) i/s - 513.000 in 5.078335s
|
32
|
+
Benchmark.ips do |x|
|
33
|
+
x.report('parse 1 MB of params') { type.new(big_data).coerce_input }
|
34
|
+
end
|
35
|
+
|
36
|
+
# 84.412 (± 2.4%) i/s - 427.000 in 5.061117s
|
37
|
+
Benchmark.ips do |x|
|
38
|
+
x.report('validate a 1 MB response') { type.new(big_data).coerce_response }
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"name": "Adeel Solangi",
|
4
|
+
"language": "Sindhi",
|
5
|
+
"id": "V59OF92YF627HFY0",
|
6
|
+
"bio": "Donec lobortis eleifend condimentum. Cras dictum dolor lacinia lectus vehicula rutrum. Maecenas quis nisi nunc. Nam tristique feugiat est vitae mollis. Maecenas quis nisi nunc.",
|
7
|
+
"version": 6.1
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"name": "Afzal Ghaffar",
|
11
|
+
"language": "Sindhi",
|
12
|
+
"id": "ENTOCR13RSCLZ6KU",
|
13
|
+
"bio": "Aliquam sollicitudin ante ligula, eget malesuada nibh efficitur et. Pellentesque massa sem, scelerisque sit amet odio id, cursus tempor urna. Etiam congue dignissim volutpat. Vestibulum pharetra libero et velit gravida euismod.",
|
14
|
+
"version": 1.88
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "Aamir Solangi",
|
18
|
+
"language": "Sindhi",
|
19
|
+
"id": "IAKPO3R4761JDRVG",
|
20
|
+
"bio": "Vestibulum pharetra libero et velit gravida euismod. Quisque mauris ligula, efficitur porttitor sodales ac, lacinia non ex. Fusce eu ultrices elit, vel posuere neque.",
|
21
|
+
"version": 7.27
|
22
|
+
}
|
23
|
+
]
|
metadata
CHANGED
@@ -1,31 +1,115 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2024-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: This library provides an object-based type system for RESTful Ruby APIs,
|
28
|
+
with built-in parameter parsing, response rendering, and OpenAPI schema export.
|
14
29
|
email:
|
15
30
|
- janosch84@gmail.com
|
16
31
|
executables: []
|
17
32
|
extensions: []
|
18
33
|
extra_rdoc_files: []
|
19
34
|
files:
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
20
38
|
- LICENSE.txt
|
21
39
|
- README.md
|
22
40
|
- Rakefile
|
23
41
|
- lib/taro.rb
|
42
|
+
- lib/taro/config.rb
|
43
|
+
- lib/taro/errors.rb
|
44
|
+
- lib/taro/export.rb
|
45
|
+
- lib/taro/export/base.rb
|
46
|
+
- lib/taro/export/open_api_v3.rb
|
47
|
+
- lib/taro/rails.rb
|
48
|
+
- lib/taro/rails/active_declarations.rb
|
49
|
+
- lib/taro/rails/declaration.rb
|
50
|
+
- lib/taro/rails/declaration_buffer.rb
|
51
|
+
- lib/taro/rails/dsl.rb
|
52
|
+
- lib/taro/rails/generators.rb
|
53
|
+
- lib/taro/rails/generators/install_generator.rb
|
54
|
+
- lib/taro/rails/generators/templates/enum_type.erb
|
55
|
+
- lib/taro/rails/generators/templates/error_type.erb
|
56
|
+
- lib/taro/rails/generators/templates/errors_type.erb
|
57
|
+
- lib/taro/rails/generators/templates/input_type.erb
|
58
|
+
- lib/taro/rails/generators/templates/no_content_type.erb
|
59
|
+
- lib/taro/rails/generators/templates/object_type.erb
|
60
|
+
- lib/taro/rails/generators/templates/scalar_type.erb
|
61
|
+
- lib/taro/rails/normalized_route.rb
|
62
|
+
- lib/taro/rails/param_parsing.rb
|
63
|
+
- lib/taro/rails/railtie.rb
|
64
|
+
- lib/taro/rails/response_validation.rb
|
65
|
+
- lib/taro/rails/response_validator.rb
|
66
|
+
- lib/taro/rails/route_finder.rb
|
67
|
+
- lib/taro/rails/tasks/export.rake
|
68
|
+
- lib/taro/types.rb
|
69
|
+
- lib/taro/types/base_type.rb
|
70
|
+
- lib/taro/types/coercion.rb
|
71
|
+
- lib/taro/types/enum_type.rb
|
72
|
+
- lib/taro/types/field.rb
|
73
|
+
- lib/taro/types/field_validation.rb
|
74
|
+
- lib/taro/types/input_type.rb
|
75
|
+
- lib/taro/types/list_type.rb
|
76
|
+
- lib/taro/types/object_type.rb
|
77
|
+
- lib/taro/types/object_types/free_form_type.rb
|
78
|
+
- lib/taro/types/object_types/no_content_type.rb
|
79
|
+
- lib/taro/types/object_types/page_info_type.rb
|
80
|
+
- lib/taro/types/object_types/page_type.rb
|
81
|
+
- lib/taro/types/scalar/boolean_type.rb
|
82
|
+
- lib/taro/types/scalar/float_type.rb
|
83
|
+
- lib/taro/types/scalar/integer_type.rb
|
84
|
+
- lib/taro/types/scalar/iso8601_date_type.rb
|
85
|
+
- lib/taro/types/scalar/iso8601_datetime_type.rb
|
86
|
+
- lib/taro/types/scalar/string_type.rb
|
87
|
+
- lib/taro/types/scalar/timestamp_type.rb
|
88
|
+
- lib/taro/types/scalar/uuid_v4_type.rb
|
89
|
+
- lib/taro/types/scalar_type.rb
|
90
|
+
- lib/taro/types/shared.rb
|
91
|
+
- lib/taro/types/shared/additional_properties.rb
|
92
|
+
- lib/taro/types/shared/custom_field_resolvers.rb
|
93
|
+
- lib/taro/types/shared/derivable_types.rb
|
94
|
+
- lib/taro/types/shared/description.rb
|
95
|
+
- lib/taro/types/shared/errors.rb
|
96
|
+
- lib/taro/types/shared/fields.rb
|
97
|
+
- lib/taro/types/shared/item_type.rb
|
98
|
+
- lib/taro/types/shared/object_coercion.rb
|
99
|
+
- lib/taro/types/shared/openapi_name.rb
|
100
|
+
- lib/taro/types/shared/openapi_type.rb
|
101
|
+
- lib/taro/types/shared/rendering.rb
|
24
102
|
- lib/taro/version.rb
|
25
|
-
|
103
|
+
- tasks/benchmark.rake
|
104
|
+
- tasks/benchmark_1kb.json
|
105
|
+
homepage: https://github.com/taro-rb/taro
|
26
106
|
licenses:
|
27
107
|
- MIT
|
28
|
-
metadata:
|
108
|
+
metadata:
|
109
|
+
rubygems_mfa_required: 'true'
|
110
|
+
homepage_uri: https://github.com/taro-rb/taro
|
111
|
+
source_code_uri: https://github.com/taro-rb/taro
|
112
|
+
changelog_uri: https://github.com/taro-rb/taro/CHANGELOG.md
|
29
113
|
post_install_message:
|
30
114
|
rdoc_options: []
|
31
115
|
require_paths:
|
@@ -44,5 +128,5 @@ requirements: []
|
|
44
128
|
rubygems_version: 3.5.16
|
45
129
|
signing_key:
|
46
130
|
specification_version: 4
|
47
|
-
summary:
|
131
|
+
summary: Typed Api using Ruby Objects.
|
48
132
|
test_files: []
|