bullet_train-api 1.7.11 → 1.7.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/app/helpers/api/open_api_helper.rb +7 -4
- data/lib/bullet_train/api/example_bot.rb +12 -2
- data/lib/bullet_train/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f25415ab895e6e3902966a043b957b9ed3917e87ff78de05bd2a0d4630ec4f
|
4
|
+
data.tar.gz: d9574bf5e9e0ae1465fcf1852f5e7be4f69748b35d12adab97e6de521c6c75fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 047631da3c86a5d6e27821a9295446b40e8bf4f4ca6fe4fc74e45f8543515b0a88bb7a919047e0db8621416f96ed7a5de9ed31bd11fe9ecb0c3e0d8d906aebfa
|
7
|
+
data.tar.gz: 72ac0e0be45b53fcdbe89b35a853f6a27c86c9c18c56532f699f1b9a3a574c69e7b20b684c93f98f64581ea47a91d0026c9f45adb1f3eead983f753383e44034
|
data/README.md
CHANGED
@@ -208,6 +208,10 @@ If the methods defined in the `automatic_paths_for` for the endpoints support
|
|
208
208
|
a write action (i.e. create or update), then doc generation uses the `strong_parameters`
|
209
209
|
defined in the corresponding controller to generate the Parameters section in the schema.
|
210
210
|
|
211
|
+
If your endpoint accepts different parameters for the create and update actions, if you define `<model>_update_params` in the
|
212
|
+
corresponding controller to define the update parameters, these will be used to generate the Parameter for the
|
213
|
+
update method in the schema.
|
214
|
+
|
211
215
|
Automatic paths are generated for basic REST actions. You can customize those paths or add your own by creating a
|
212
216
|
file at `app/views/api/<version>/open_api/<Model.underscore.plural>/_paths.yaml.erb`. For REST paths there's no need to
|
213
217
|
duplicate all the schema, you can specify only what differs from auto-generated code.
|
@@ -65,8 +65,10 @@ module Api
|
|
65
65
|
|
66
66
|
factory_path = "test/factories/#{model.model_name.collection}.rb"
|
67
67
|
cache_key = [:example, model.model_name.param_key, File.ctime(factory_path)]
|
68
|
-
example =
|
68
|
+
example = if model.name.constantize.singleton_methods.any?
|
69
69
|
FactoryBot.example(model.model_name.param_key.to_sym)
|
70
|
+
else
|
71
|
+
Rails.cache.fetch(cache_key) { FactoryBot.example(model.model_name.param_key.to_sym) }
|
70
72
|
end
|
71
73
|
|
72
74
|
schema_json = jbuilder.json(
|
@@ -101,10 +103,11 @@ module Api
|
|
101
103
|
|
102
104
|
if has_strong_parameters?("Api::#{@version.upcase}::#{model.name.pluralize}Controller".constantize)
|
103
105
|
strong_parameter_keys = strong_parameter_keys_for(model.name, @version)
|
106
|
+
strong_parameter_keys_for_update = strong_parameter_keys_for(model.name, @version, "update")
|
104
107
|
|
105
108
|
# Create separate parameter schema for create and update methods
|
106
109
|
create_parameters_output = process_strong_parameters(model, strong_parameter_keys, schema_json, "create", **options)
|
107
|
-
update_parameters_output = process_strong_parameters(model,
|
110
|
+
update_parameters_output = process_strong_parameters(model, strong_parameter_keys_for_update, schema_json, "update", **options)
|
108
111
|
|
109
112
|
# We need to skip TeamParameters, UserParameters & InvitationParametersUpdate as they are not present in
|
110
113
|
# the bullet train api schema
|
@@ -144,10 +147,10 @@ module Api
|
|
144
147
|
parameters_output
|
145
148
|
end
|
146
149
|
|
147
|
-
def strong_parameter_keys_for(model_name, version)
|
150
|
+
def strong_parameter_keys_for(model_name, version, method_type = "create")
|
148
151
|
strong_params_module = "::Api::#{version.upcase}::#{model_name.pluralize}Controller::StrongParameters".constantize
|
149
152
|
strong_params_reporter = BulletTrain::Api::StrongParametersReporter.new(model_name.constantize, strong_params_module)
|
150
|
-
strong_parameter_keys = strong_params_reporter.report
|
153
|
+
strong_parameter_keys = strong_params_reporter.report(method_type)
|
151
154
|
|
152
155
|
if strong_parameter_keys.last.is_a?(Hash)
|
153
156
|
strong_parameter_keys += strong_parameter_keys.pop.keys
|
@@ -66,13 +66,23 @@ module FactoryBot
|
|
66
66
|
model_name = ActiveRecord::Base.descendants.find { |klass| klass.model_name.param_key == model.to_s }&.model_name
|
67
67
|
factory_path = "test/factories/#{model_name.collection}.rb"
|
68
68
|
|
69
|
+
model_class = model_name.name.constantize
|
70
|
+
|
69
71
|
if count > 1
|
70
72
|
cache_key = [:example_list, model_name.param_key, File.ctime(factory_path)]
|
71
|
-
values =
|
73
|
+
values = if model_class.singleton_methods.any?
|
74
|
+
FactoryBot.example_list(model, count)
|
75
|
+
else
|
76
|
+
Rails.cache.fetch(cache_key) { FactoryBot.example_list(model, count) }
|
77
|
+
end
|
72
78
|
var_name = model_name.element.pluralize
|
73
79
|
else
|
74
80
|
cache_key = [:example, model_name.param_key, File.ctime(factory_path)]
|
75
|
-
values =
|
81
|
+
values = if model_class.singleton_methods.any?
|
82
|
+
FactoryBot.example(model)
|
83
|
+
else
|
84
|
+
Rails.cache.fetch(cache_key) { FactoryBot.example(model) }
|
85
|
+
end
|
76
86
|
var_name = model_name.element
|
77
87
|
end
|
78
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|