bullet_train-api 1.1.6 → 1.1.8
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/controllers/api/open_api_controller.rb +41 -0
- data/app/views/api/v1/open_api/shared/_paths.yaml.erb +108 -0
- data/app/views/api/v1/open_api/users/_paths.yaml.erb +1 -1
- data/lib/bullet_train/api/strong_parameters_reporter.rb +54 -0
- data/lib/bullet_train/api/version.rb +1 -1
- data/lib/bullet_train/api.rb +5 -0
- metadata +18 -3
- data/app/views/api/v1/open_api/index.yaml.erb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 780a5449da6bedaab86b5be1a02ceb612585cc766ebcd74ae033821ad8c8c055
|
4
|
+
data.tar.gz: 367778ea70927d9dc9d9f3431e69a75d0993de1e4d8138cb51c686149bf392f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe6b2e6bd9da345bf380c0c11498490f74dc758fb50a05e8b9068a55eca33d01b86bcbcba085317c28bc8ea2b007e148ec020458285a4f7284ec865ee514b34
|
7
|
+
data.tar.gz: f5667fff9265ce6b01b4d48230eb3c7aa6db77121103728a549e5c04968e9c7533cb363e34a100ae5b8ec44969d15f831aeae125ba3b66e542b2c92c63fb9c40
|
@@ -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 %>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "pry"
|
2
|
+
|
3
|
+
module BulletTrain
|
4
|
+
module Api
|
5
|
+
class StrongParametersReporter
|
6
|
+
def initialize(model, strong_params_module)
|
7
|
+
@model = model
|
8
|
+
@module = strong_params_module
|
9
|
+
@filters = []
|
10
|
+
extend @module
|
11
|
+
end
|
12
|
+
|
13
|
+
def require(namespace)
|
14
|
+
@namespace = namespace
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def permit(*filters)
|
19
|
+
@filters = filters
|
20
|
+
end
|
21
|
+
|
22
|
+
def params
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def permitted_fields
|
27
|
+
defined?(super) ? super : []
|
28
|
+
end
|
29
|
+
|
30
|
+
def permitted_arrays
|
31
|
+
defined?(super) ? super : {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def process_params(params)
|
35
|
+
end
|
36
|
+
|
37
|
+
# def method_missing(method_name, *args)
|
38
|
+
# if method_name.match?(/^assign_/)
|
39
|
+
# # It's typically the second argument that represents the parameter that would be set.
|
40
|
+
# @filters << args[1]
|
41
|
+
# else
|
42
|
+
# raise NoMethodError, message
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
def report
|
47
|
+
@filters = send("#{@model.name.split("::").last.underscore}_params".to_sym)
|
48
|
+
|
49
|
+
# There's a reason I'm doing it this way.
|
50
|
+
@filters
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/bullet_train/api.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.1.8
|
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-
|
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/
|
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. %>
|