bullet_train-api 1.7.11 → 1.7.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aef8c20ab58036263c4aedee16b5957f9794f6db67388b88f308ad2de6eddcd2
4
- data.tar.gz: c97837332c5bf099547093477248223dd5efecc9dfe6327b10e27173bff8b981
3
+ metadata.gz: 814023b96db3c4fcc1a581825dd6c0a02858553162a36f3aa40851418ee305d6
4
+ data.tar.gz: 138b17de8d7900426fa5bdc94d78ec61c2376a2fa93b64321bd9f816ee4feb56
5
5
  SHA512:
6
- metadata.gz: f7b9c1c254e7425b2a5a48b1badf2a6b22667b4724e761291ee4a577bd048b3bfe3663864eb0a34bf653d54a4c741f044f1d6ac7a44e8b8d581e6303f082f6dc
7
- data.tar.gz: 81ff21bf84669a24a2972fcc6b6441661c18e3074b31f1c94945572b4e34dfe4923ef21985b3adaa5e1c5bdc70353d82567853e1da03f49da8c22a2053eeda55
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 = Rails.cache.fetch(cache_key) do
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, strong_parameter_keys, schema_json, "update", **options)
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 = Rails.cache.fetch(cache_key) { FactoryBot.example_list(model, count) }
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 = Rails.cache.fetch(cache_key) { FactoryBot.example(model) }
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
 
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.7.11"
3
+ VERSION = "1.7.12"
4
4
  end
5
5
  end
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.11
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-05 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard