bullet_train-api 1.7.11 → 1.7.12
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/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: 814023b96db3c4fcc1a581825dd6c0a02858553162a36f3aa40851418ee305d6
|
4
|
+
data.tar.gz: 138b17de8d7900426fa5bdc94d78ec61c2376a2fa93b64321bd9f816ee4feb56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6abf9d886f960bd4c5176b28a4de09865a54d016389854418a578ae2769fae463fe22700038818776bedfdb8a41a799c09b015f88446ccfc08c879fc18eacc67
|
7
|
+
data.tar.gz: caf5cc34915ad55ccc79c7d8fe48946c402d3dfdb5bb3339fd2eb01d196115013ba6b3911b54bd1a1652f66ed0a78b32c3264701ec7eff9554af52c9b5a8142e
|
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.12
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|