bullet_train-api 1.3.12 → 1.3.14
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/app/helpers/api/open_api_helper.rb +7 -20
- data/app/views/api/v1/open_api/shared/_paths.yaml.erb +4 -4
- data/lib/bullet_train/api/example_bot.rb +20 -4
- data/lib/bullet_train/api/version.rb +1 -1
- data/lib/bullet_train/api.rb +1 -0
- data/lib/jbuilder/values_transformer.rb +13 -0
- data/lib/tasks/bullet_train/api_tasks.rake +16 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1afcea46978b7420ab6561c17b1d55c03cc01a85be1ca29b3bd384e371a10e5c
|
|
4
|
+
data.tar.gz: 26f2e5abb15ef1359f5a846232ba0c953aa31a60100466a5c4594d27eb9d0e44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2728e7625569f7a11eea0b36840d9bbc5b95a727f5fc369d7a575b092a2ece1048fd93993a798868b94a755ceec55f12504fc8eee2bb3bb24be0acad1d2c752d
|
|
7
|
+
data.tar.gz: cb185815afbab983770c746ccddd676956d1d8f502f795504a54d20e48c1d810a0073e1208648488d2bade4807e9323a6c1e9e37dbb38da2c1d806f0d35dc156
|
|
@@ -40,24 +40,10 @@ module Api
|
|
|
40
40
|
# There are some placeholders specific to this method that we still need to transform.
|
|
41
41
|
model_symbol = model.name.underscore.tr("/", "_").to_sym
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (post_parameters = FactoryBot.post_parameters(model_symbol, version: @version))
|
|
48
|
-
output.gsub!("🚅 post_parameters", post_parameters)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
if (post_examples = FactoryBot.post_examples(model_symbol, version: @version))
|
|
52
|
-
output.gsub!("🚅 post_examples", post_examples)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
if (put_parameters = FactoryBot.put_parameters(model_symbol, version: @version))
|
|
56
|
-
output.gsub!("🚅 put_parameters", put_parameters)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
if (put_example = FactoryBot.put_example(model_symbol, version: @version))
|
|
60
|
-
output.gsub!("🚅 put_example", put_example)
|
|
43
|
+
FactoryBot::ExampleBot::REST_METHODS.each do |method|
|
|
44
|
+
if (code = FactoryBot.send(method, model_symbol, version: @version))
|
|
45
|
+
output.gsub!("🚅 #{method}", code)
|
|
46
|
+
end
|
|
61
47
|
end
|
|
62
48
|
|
|
63
49
|
indent(output, 1)
|
|
@@ -74,7 +60,7 @@ module Api
|
|
|
74
60
|
}.merge(locals))
|
|
75
61
|
|
|
76
62
|
schema_json = jbuilder.json(
|
|
77
|
-
model.new,
|
|
63
|
+
FactoryBot.example(model.model_name.param_key.to_sym) || model.new,
|
|
78
64
|
title: I18n.t("#{model.name.underscore.pluralize}.label"),
|
|
79
65
|
# TODO Improve this. We don't have a generic description for models we can use here.
|
|
80
66
|
description: I18n.t("#{model.name.underscore.pluralize}.label"),
|
|
@@ -106,7 +92,8 @@ module Api
|
|
|
106
92
|
|
|
107
93
|
parameters_output = JSON.parse(schema_json)
|
|
108
94
|
parameters_output["required"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
|
|
109
|
-
parameters_output["properties"].select! { |key
|
|
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? }
|
|
110
97
|
|
|
111
98
|
(
|
|
112
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:
|
|
15
|
+
type: integer
|
|
16
16
|
- $ref: "#/components/parameters/after"
|
|
17
17
|
responses:
|
|
18
18
|
"404":
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
items:
|
|
32
32
|
$ref: "#/components/schemas/ScaffoldingCompletelyConcreteTangibleThingAttributes"
|
|
33
33
|
example:
|
|
34
|
-
🚅
|
|
34
|
+
🚅 get_examples
|
|
35
35
|
<% end %>
|
|
36
36
|
<% unless except.include?(:create) %>
|
|
37
37
|
post:
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
in: path
|
|
45
45
|
required: true
|
|
46
46
|
schema:
|
|
47
|
-
type:
|
|
47
|
+
type: integer
|
|
48
48
|
requestBody:
|
|
49
49
|
description: "Information about a new Tangible Thing"
|
|
50
50
|
required: true
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
schema:
|
|
69
69
|
$ref: "#/components/schemas/ScaffoldingCompletelyConcreteTangibleThingAttributes"
|
|
70
70
|
example:
|
|
71
|
-
🚅
|
|
71
|
+
🚅 post_example
|
|
72
72
|
<% end %>
|
|
73
73
|
<% end %>
|
|
74
74
|
<% unless except.include?(:show) && except.include?(:update) && except.include?(:destroy) %>
|
|
@@ -39,7 +39,9 @@ module FactoryBot
|
|
|
39
39
|
objects
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
%i[get_examples get_example
|
|
42
|
+
REST_METHODS = %i[get_examples get_example post_example post_parameters put_example put_parameters patch_example patch_parameters]
|
|
43
|
+
|
|
44
|
+
REST_METHODS.each do |method|
|
|
43
45
|
define_method(method) do |model, **options|
|
|
44
46
|
_path_examples(method.to_s, model, **options)
|
|
45
47
|
end
|
|
@@ -53,6 +55,8 @@ module FactoryBot
|
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
def reset_tables!
|
|
58
|
+
# This is only availble for postgres
|
|
59
|
+
return unless ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
|
|
56
60
|
@tables_to_reset.each do |name|
|
|
57
61
|
ActiveRecord::Base.connection.reset_pk_sequence!(name) if ActiveRecord::Base.connection.table_exists?(name)
|
|
58
62
|
end
|
|
@@ -67,8 +71,17 @@ module FactoryBot
|
|
|
67
71
|
clone.send("#{name}=", associations)
|
|
68
72
|
@tables_to_reset << name
|
|
69
73
|
elsif %i[belongs_to has_one].include?(reflection.macro)
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
72
85
|
end
|
|
73
86
|
end
|
|
74
87
|
|
|
@@ -86,7 +99,7 @@ module FactoryBot
|
|
|
86
99
|
else
|
|
87
100
|
template, class_name, var_name, values = _set_values("get_example", model)
|
|
88
101
|
|
|
89
|
-
|
|
102
|
+
if method.end_with?("parameters")
|
|
90
103
|
if has_strong_parameters?("::Api::#{version.upcase}::#{class_name.pluralize}Controller".constantize)
|
|
91
104
|
strong_params_module = "::Api::#{version.upcase}::#{class_name.pluralize}Controller::StrongParameters".constantize
|
|
92
105
|
strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(class_name.constantize, strong_params_module).report
|
|
@@ -99,6 +112,9 @@ module FactoryBot
|
|
|
99
112
|
parameters_output = JSON.parse(output)
|
|
100
113
|
parameters_output&.select! { |key| strong_parameter_keys.include?(key.to_sym) }
|
|
101
114
|
|
|
115
|
+
# Wrapping the example as parameters should be wrapped with the model name:
|
|
116
|
+
parameters_output = {model.to_s => parameters_output}
|
|
117
|
+
|
|
102
118
|
return indent(parameters_output.to_yaml.delete_prefix("---\n"), 6).html_safe
|
|
103
119
|
end
|
|
104
120
|
return nil
|
data/lib/bullet_train/api.rb
CHANGED
|
@@ -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.
|
|
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-
|
|
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.
|
|
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.
|
|
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
|