bullet_train-api 1.3.13 → 1.3.14

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: 1806427fae0e5cd7d5f9affa3e027d0c917d29fc9596fe3ce13e25145a462659
4
- data.tar.gz: dbfab0be607282b69ee6bd50461d3dfcca7d40a2d6cb81d85e09694225fe4cd6
3
+ metadata.gz: 1afcea46978b7420ab6561c17b1d55c03cc01a85be1ca29b3bd384e371a10e5c
4
+ data.tar.gz: 26f2e5abb15ef1359f5a846232ba0c953aa31a60100466a5c4594d27eb9d0e44
5
5
  SHA512:
6
- metadata.gz: f5ecb7a22849f2e5a85d7b982f5594211f595fccfda892803f034b33c725997fbc439c3a9a296ef2be9cc812560ab2ca75c0dcda4fb0c4f080b62f04e359f5ca
7
- data.tar.gz: cb4b9abd99ea3782b991f14c2c231be60621db40c6738153f1bdd3285f4bfcec308ac2ca4484d36b5e6ce7386bec0f0f15977aaade0f350e260b9961c68242ba
6
+ metadata.gz: 2728e7625569f7a11eea0b36840d9bbc5b95a727f5fc369d7a575b092a2ece1048fd93993a798868b94a755ceec55f12504fc8eee2bb3bb24be0acad1d2c752d
7
+ data.tar.gz: cb185815afbab983770c746ccddd676956d1d8f502f795504a54d20e48c1d810a0073e1208648488d2bade4807e9323a6c1e9e37dbb38da2c1d806f0d35dc156
@@ -60,7 +60,7 @@ module Api
60
60
  }.merge(locals))
61
61
 
62
62
  schema_json = jbuilder.json(
63
- model.new,
63
+ FactoryBot.example(model.model_name.param_key.to_sym) || model.new,
64
64
  title: I18n.t("#{model.name.underscore.pluralize}.label"),
65
65
  # TODO Improve this. We don't have a generic description for models we can use here.
66
66
  description: I18n.t("#{model.name.underscore.pluralize}.label"),
@@ -92,7 +92,8 @@ module Api
92
92
 
93
93
  parameters_output = JSON.parse(schema_json)
94
94
  parameters_output["required"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
95
- parameters_output["properties"].select! { |key, value| strong_parameter_keys.include?(key.to_sym) }
95
+ parameters_output["properties"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
96
+ parameters_output["example"]&.select! { |key, value| strong_parameter_keys.include?(key.to_sym) && value.present? }
96
97
 
97
98
  (
98
99
  indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3) +
@@ -12,7 +12,7 @@
12
12
  in: path
13
13
  required: true
14
14
  schema:
15
- type: string
15
+ type: integer
16
16
  - $ref: "#/components/parameters/after"
17
17
  responses:
18
18
  "404":
@@ -44,7 +44,7 @@
44
44
  in: path
45
45
  required: true
46
46
  schema:
47
- type: string
47
+ type: integer
48
48
  requestBody:
49
49
  description: "Information about a new Tangible Thing"
50
50
  required: true
@@ -71,8 +71,17 @@ module FactoryBot
71
71
  clone.send("#{name}=", associations)
72
72
  @tables_to_reset << name
73
73
  elsif %i[belongs_to has_one].include?(reflection.macro)
74
- clone.send("#{name}=", instance.send(name).clone)
75
- @tables_to_reset << name.pluralize
74
+ # Calling e.g. address.team= throws an error,
75
+ # if address has_one team through person
76
+ # and person has_one team through company
77
+ # and company belongs_to team
78
+ # so the resulting error will be caught here and a warning logged.
79
+ begin
80
+ clone.send("#{name}=", instance.send(name).clone)
81
+ @tables_to_reset << name.pluralize
82
+ rescue ActiveRecord::HasOneThroughNestedAssociationsAreReadonly
83
+ Rails.logger.warn("ExampleBot.deep_clone ignored setting #{name} of #{instance}")
84
+ end
76
85
  end
77
86
  end
78
87
 
@@ -90,7 +99,7 @@ module FactoryBot
90
99
  else
91
100
  template, class_name, var_name, values = _set_values("get_example", model)
92
101
 
93
- unless %w[example examples].include?(method.split("_").last)
102
+ if method.end_with?("parameters")
94
103
  if has_strong_parameters?("::Api::#{version.upcase}::#{class_name.pluralize}Controller".constantize)
95
104
  strong_params_module = "::Api::#{version.upcase}::#{class_name.pluralize}Controller::StrongParameters".constantize
96
105
  strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(class_name.constantize, strong_params_module).report
@@ -103,6 +112,9 @@ module FactoryBot
103
112
  parameters_output = JSON.parse(output)
104
113
  parameters_output&.select! { |key| strong_parameter_keys.include?(key.to_sym) }
105
114
 
115
+ # Wrapping the example as parameters should be wrapped with the model name:
116
+ parameters_output = {model.to_s => parameters_output}
117
+
106
118
  return indent(parameters_output.to_yaml.delete_prefix("---\n"), 6).html_safe
107
119
  end
108
120
  return nil
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.3.13"
3
+ VERSION = "1.3.14"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ require "scaffolding"
14
14
  require "scaffolding/block_manipulator"
15
15
  require "scaffolding/transformer"
16
16
  require "jbuilder/schema"
17
+ require "jbuilder/values_transformer"
17
18
 
18
19
  module BulletTrain
19
20
  module Api
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jbuilder"
4
+
5
+ module ValuesTransformer
6
+ def _set_value(key, value)
7
+ value = value.body if value.is_a?(ActionText::RichText)
8
+
9
+ super(key, value)
10
+ end
11
+ end
12
+
13
+ ::Jbuilder.prepend ValuesTransformer
@@ -128,5 +128,21 @@ namespace :bullet_train do
128
128
  puts "Failed to download the OpenAPI Document. Status code: #{response.status}"
129
129
  end
130
130
  end
131
+
132
+ desc "Export the OpenAPI schema for the application"
133
+ task export_openapi_schema: :environment do
134
+ @version = BulletTrain::Api.current_version
135
+ File.open("openapi-#{Time.now.strftime("%Y%m%d-%H%M%S")}.yaml", "w+") do |f|
136
+ f.binmode
137
+ f.write(
138
+ ApplicationController.renderer.render(
139
+ template: "api/#{@version}/open_api/index",
140
+ layout: false,
141
+ format: :text,
142
+ assigns: {version: @version}
143
+ )
144
+ )
145
+ end
146
+ end
131
147
  end
132
148
  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.3.13
4
+ version: 1.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 2.0.0
103
+ version: 2.2.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 2.0.0
110
+ version: 2.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: factory_bot
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +212,7 @@ files:
212
212
  - lib/bullet_train/api/version.rb
213
213
  - lib/bullet_train/platform.rb
214
214
  - lib/bullet_train/platform/connection_workflow.rb
215
+ - lib/jbuilder/values_transformer.rb
215
216
  - lib/tasks/bullet_train/api_tasks.rake
216
217
  - lib/tokens_controller.rb
217
218
  homepage: https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-api