bullet_train-api 1.1.6 → 1.1.9

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: f474623bb0f011c89b57e3d4b0c6b8dbce5dc388772dfa5373155b2216a39b8e
4
- data.tar.gz: cc167320a1f660301b3beab289db2fd29c2c6b72361d47c5276fe24a28f27eec
3
+ metadata.gz: 025106c2fcb07750bfc155c42ee8afd86b47c9af4e8c53fb0712ecb8863e7962
4
+ data.tar.gz: 3a1143eb0701e39bd35882fb3ced4cf4790fa9856d053a83f63a9b097eb2d828
5
5
  SHA512:
6
- metadata.gz: cf49807aecaa0e1814fce504b214c41b6606f36dbd69814b520c45eb5ad7bf75af2b593befd2617cff8198572d0a0b3c8256f38aba78dcc5874cbae021939db5
7
- data.tar.gz: 1ba92be181ff6faa0bbcfb0e480105e31222076d48bd213710200772403328492391a0247023cb0eff6f4c2b2e1d54f40a1dd8427d57d256ba2d5f91467bebff
6
+ metadata.gz: '03408df50352ba3073d8d59753bade0890b3a4bf05671a19d9a8e6d6fcaf289d28b302c40dfb066c39121501b9c61dd70d68e7063a290f7743987d85ebe95330'
7
+ data.tar.gz: 8e8c25227791d7587855cc4892af15fa8df165362624238685c907cb85aeb7d7512923dcfbb544b0b743a4b92b0578131ed23f98df7445f23b482572b9f0a3bb
@@ -24,6 +24,47 @@ module OpenApiHelper
24
24
  result
25
25
  end
26
26
 
27
+ def automatic_paths_for(model, parent, except: [])
28
+ output = render("api/v1/open_api/shared/paths", except: except)
29
+ output = Scaffolding::Transformer.new(model.name, [parent&.name]).transform_string(output).html_safe
30
+ indent(output, 1)
31
+ end
32
+
33
+ def automatic_components_for(model, locals: {})
34
+ extend JbuilderSchema
35
+
36
+ schema_json = jbuilder_schema("api/v1/#{model.name.underscore.pluralize}/_#{model.name.underscore.split("/").last}",
37
+ title: I18n.t("#{model.name.underscore.pluralize}.label"),
38
+ # TODO Improve this. We don't have a generic description for models we can use here.
39
+ description: I18n.t("#{model.name.underscore.pluralize}.label"),
40
+ format: :json,
41
+ paths: view_paths.map(&:path),
42
+ model: model,
43
+ locals: {
44
+ # If we ever get to the point where we need a real model here, we should implement an example team in seeds that we can source it from.
45
+ model.name.underscore.split("/").last.to_sym => model.new,
46
+ # Same here, if we ever need this to be a real object, this should be `test@example.com` with an `SecureRandom.hex` password.
47
+ :current_user => User.new
48
+ }.merge(locals))
49
+
50
+ attributes_output = JSON.parse(schema_json)
51
+
52
+ strong_params_module = "Api::V1::#{model.name.pluralize}Controller::StrongParameters".constantize
53
+ strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(model, strong_params_module).report
54
+ if strong_parameter_keys.last.is_a?(Hash)
55
+ strong_parameter_keys += strong_parameter_keys.pop.keys
56
+ end
57
+
58
+ parameters_output = JSON.parse(schema_json)
59
+ parameters_output["required"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
60
+ parameters_output["properties"].select! { |key, value| strong_parameter_keys.include?(key.to_sym) }
61
+
62
+ (
63
+ indent(attributes_output.to_yaml.gsub("---", "#{model.name}::Attributes:"), 3) +
64
+ indent(" " + parameters_output.to_yaml.gsub("---", "#{model.name}::Parameters:"), 3)
65
+ ).html_safe
66
+ end
67
+
27
68
  def paths_for(model)
28
69
  for_model model do
29
70
  indent(render("api/#{@version}/open_api/#{model.name.underscore.pluralize}/paths"), 1)
@@ -0,0 +1,108 @@
1
+ <% except ||= [] %>
2
+ <% unless except.include?(:index) && except.include?(:create) %>
3
+ /scaffolding/absolutely_abstract/creative_concepts/{absolutely_abstract_creative_concept_id}/completely_concrete/tangible_things:
4
+ <% unless except.include?(:index) %>
5
+ get:
6
+ tags:
7
+ - "Scaffolding/Completely Concrete/Tangible Things"
8
+ summary: "List Tangible Things"
9
+ operationId: listScaffoldingCompletelyConcreteTangibleThings
10
+ parameters:
11
+ - name: absolutely_abstract_creative_concept_id
12
+ in: path
13
+ required: true
14
+ schema:
15
+ type: string
16
+ responses:
17
+ "404":
18
+ description: "Not Found"
19
+ "200":
20
+ description: "OK"
21
+ content:
22
+ application/json:
23
+ schema:
24
+ type: object
25
+ properties:
26
+ data:
27
+ type: array
28
+ items:
29
+ $ref: "#/components/schemas/Scaffolding::CompletelyConcrete::TangibleThing::Attributes"
30
+ has_more:
31
+ type: boolean
32
+ <% end %>
33
+ <% unless except.include?(:create) %>
34
+ post:
35
+ tags:
36
+ - "Scaffolding/Completely Concrete/Tangible Things"
37
+ summary: "Create Tangible Thing"
38
+ operationId: createScaffoldingCompletelyConcreteTangibleThings
39
+ parameters:
40
+ - name: absolutely_abstract_creative_concept_id
41
+ in: path
42
+ required: true
43
+ schema:
44
+ type: string
45
+ responses:
46
+ "404":
47
+ description: "Not Found"
48
+ "201":
49
+ description: "Created"
50
+ content:
51
+ application/json:
52
+ schema:
53
+ $ref: "#/components/schemas/Scaffolding::CompletelyConcrete::TangibleThing::Parameters"
54
+ <% end %>
55
+ <% end %>
56
+ <% unless except.include?(:show) && except.include?(:update) && except.include?(:destroy) %>
57
+ /scaffolding/completely_concrete/tangible_things/{id}:
58
+ <% unless except.include?(:show) %>
59
+ get:
60
+ tags:
61
+ - "Scaffolding/Completely Concrete/Tangible Things"
62
+ summary: "Fetch Tangible Thing"
63
+ operationId: getScaffoldingCompletelyConcreteTangibleThings
64
+ parameters:
65
+ - $ref: "#/components/parameters/id"
66
+ responses:
67
+ "404":
68
+ description: "Not Found"
69
+ "200":
70
+ description: "OK"
71
+ content:
72
+ application/json:
73
+ schema:
74
+ $ref: "#/components/schemas/Scaffolding::CompletelyConcrete::TangibleThing::Attributes"
75
+ <% end %>
76
+ <% unless except.include?(:update) %>
77
+ put:
78
+ tags:
79
+ - "Scaffolding/Completely Concrete/Tangible Things"
80
+ summary: "Update Tangible Thing"
81
+ operationId: updateScaffoldingCompletelyConcreteTangibleThings
82
+ parameters:
83
+ - $ref: "#/components/parameters/id"
84
+ responses:
85
+ "404":
86
+ description: "Not Found"
87
+ "200":
88
+ description: "OK"
89
+ content:
90
+ application/json:
91
+ schema:
92
+ $ref: "#/components/schemas/Scaffolding::CompletelyConcrete::TangibleThing::Parameters"
93
+ <% end %>
94
+ <% unless except.include?(:destroy) %>
95
+ delete:
96
+ tags:
97
+ - "Scaffolding/Completely Concrete/Tangible Things"
98
+ summary: "Remove Tangible Thing"
99
+ operationId: removeScaffoldingCompletelyConcreteTangibleThings
100
+ parameters:
101
+ - $ref: "#/components/parameters/id"
102
+ responses:
103
+ "404":
104
+ description: "Not Found"
105
+ "200":
106
+ description: "OK"
107
+ <% end %>
108
+ <% end %>
@@ -16,7 +16,7 @@
16
16
  properties:
17
17
  data:
18
18
  type: array
19
- items:
19
+ items:
20
20
  $ref: "#/components/schemas/User::Attributes"
21
21
  has_more:
22
22
  type: boolean
@@ -0,0 +1,52 @@
1
+ module BulletTrain
2
+ module Api
3
+ class StrongParametersReporter
4
+ def initialize(model, strong_params_module)
5
+ @model = model
6
+ @module = strong_params_module
7
+ @filters = []
8
+ extend @module
9
+ end
10
+
11
+ def require(namespace)
12
+ @namespace = namespace
13
+ self
14
+ end
15
+
16
+ def permit(*filters)
17
+ @filters = filters
18
+ end
19
+
20
+ def params
21
+ self
22
+ end
23
+
24
+ def permitted_fields
25
+ defined?(super) ? super : []
26
+ end
27
+
28
+ def permitted_arrays
29
+ defined?(super) ? super : {}
30
+ end
31
+
32
+ def process_params(params)
33
+ end
34
+
35
+ # def method_missing(method_name, *args)
36
+ # if method_name.match?(/^assign_/)
37
+ # # It's typically the second argument that represents the parameter that would be set.
38
+ # @filters << args[1]
39
+ # else
40
+ # raise NoMethodError, message
41
+ # end
42
+ # end
43
+
44
+ def report
45
+ @filters = send("#{@model.name.split("::").last.underscore}_params".to_sym)
46
+
47
+ # There's a reason I'm doing it this way.
48
+ @filters
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.1.6"
3
+ VERSION = "1.1.9"
4
4
  end
5
5
  end
@@ -1,11 +1,16 @@
1
1
  require "bullet_train/api/version"
2
2
  require "bullet_train/api/engine"
3
+ require "bullet_train/api/strong_parameters_reporter"
3
4
 
4
5
  # require "wine_bouncer"
5
6
  require "pagy"
6
7
  require "pagy_cursor"
7
8
  require "rack/cors"
8
9
  require "doorkeeper"
10
+ require "scaffolding"
11
+ require "scaffolding/block_manipulator"
12
+ require "scaffolding/transformer"
13
+ require "jbuilder/schema"
9
14
 
10
15
  module BulletTrain
11
16
  module Api
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.1.6
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jbuilder-schema
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bullet_train
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +162,7 @@ files:
148
162
  - app/views/account/platform/applications/new.html.erb
149
163
  - app/views/account/platform/applications/show.html.erb
150
164
  - app/views/account/platform/applications/show.json.jbuilder
151
- - app/views/api/v1/open_api/index.yaml.erb
165
+ - app/views/api/v1/open_api/shared/_paths.yaml.erb
152
166
  - app/views/api/v1/open_api/teams/_paths.yaml.erb
153
167
  - app/views/api/v1/open_api/users/_paths.yaml.erb
154
168
  - app/views/api/v1/platform/access_tokens/_access_token.json.jbuilder
@@ -165,6 +179,7 @@ files:
165
179
  - config/routes.rb
166
180
  - lib/bullet_train/api.rb
167
181
  - lib/bullet_train/api/engine.rb
182
+ - lib/bullet_train/api/strong_parameters_reporter.rb
168
183
  - lib/bullet_train/api/version.rb
169
184
  - lib/tasks/bullet_train/api_tasks.rake
170
185
  homepage: https://github.com/bullet-train-co/bullet_train-api
@@ -1,29 +0,0 @@
1
- openapi: 3.1.0
2
- info:
3
- title: Bullet Train API
4
- description: |
5
- The baseline API of a new Bullet Train application.
6
- license:
7
- name: MIT
8
- url: https://opensource.org/licenses/MIT
9
- version: "<%= @version.upcase %>"
10
- servers:
11
- - url: <%= ENV["BASE_URL"] %>/api/<%= @version %>
12
- components:
13
- schemas:
14
- <%= components_for Team %>
15
- <%= components_for User %>
16
- <%= components_for Scaffolding::CompletelyConcrete::TangibleThing unless scaffolding_things_disabled? %>
17
- <%# 🚅 super scaffolding will insert new components above this line. %>
18
- parameters:
19
- id:
20
- name: id
21
- in: path
22
- required: true
23
- schema:
24
- type: string
25
- paths:
26
- <%= paths_for Team %>
27
- <%= paths_for User %>
28
- <%= paths_for Scaffolding::CompletelyConcrete::TangibleThing unless scaffolding_things_disabled? %>
29
- <%# 🚅 super scaffolding will insert new paths above this line. %>