bullet_train-api 1.0.8 → 1.0.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/MIT-LICENSE +1 -1
- data/app/controllers/api/base.rb +12 -7
- data/app/controllers/api/model_parser.rb +42 -0
- data/app/controllers/api/v1/me_endpoint.rb +4 -3
- data/app/controllers/concerns/api/v1/base.rb +8 -1
- data/app/controllers/concerns/api/v1/teams/endpoint_base.rb +1 -1
- data/config/locales/en/me.en.yml +5 -0
- data/lib/bullet_train/api/engine.rb +2 -2
- data/lib/bullet_train/api/version.rb +1 -1
- data/lib/bullet_train/api.rb +12 -0
- metadata +40 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f8599c5782cc6d6bbc75ac56c21630781a78a74f7ea2eed9ea52a1b02075d1b
|
4
|
+
data.tar.gz: f21ff5faab0e451c593519671f5ead35063a7ced971e95ab7d741f35fd654265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce2e86ed0de69b74859f69be71f516317c0b2ca46986e9faa1d11a39f375101fbcf351521f40da25241b88088ed242b9d01e699a35aa786040d3dd9a5a16aec
|
7
|
+
data.tar.gz: 1ee449d6858dd7e7d5ba5a72f1c28ba1cbbb45063ad444390a8bca73c01e8a441564162169aab9b63b69eb85dde242e21a9c88f205480848c64ad6de48547237
|
data/MIT-LICENSE
CHANGED
data/app/controllers/api/base.rb
CHANGED
@@ -8,19 +8,24 @@ class Api::Base < Grape::API
|
|
8
8
|
format :jsonapi
|
9
9
|
default_error_formatter :json
|
10
10
|
|
11
|
-
# TODO Shouldn't this be in V1 or not versioned?
|
12
|
-
include Api::V1::ExceptionsHandler
|
13
|
-
|
14
11
|
mount Api::V1::Root
|
15
12
|
|
16
|
-
# Swagger docs are available at `/api/
|
13
|
+
# Swagger docs are available at `/api/docs/swagger.json`.
|
17
14
|
add_swagger_documentation \
|
18
|
-
hide_documentation_path: true,
|
19
|
-
array_use_braces: true,
|
20
15
|
api_version: "v1",
|
16
|
+
array_use_braces: true,
|
17
|
+
base_path: "/api",
|
18
|
+
doc_version: "1.0",
|
19
|
+
endpoint_auth_wrapper: ::WineBouncer::OAuth2,
|
20
|
+
hide_documentation_path: true,
|
21
21
|
info: {
|
22
22
|
title: I18n.t("application.name"),
|
23
23
|
description: I18n.t("application.description")
|
24
24
|
},
|
25
|
-
|
25
|
+
mount_path: "/docs/swagger"
|
26
|
+
|
27
|
+
# TODO Reintroduce this once we've got `context` in current attributes.
|
28
|
+
# before do
|
29
|
+
# Current.context = :api
|
30
|
+
# end
|
26
31
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Api::ModelParser < GrapeSwagger::Jsonapi::Parser
|
2
|
+
attr_reader :model, :endpoint
|
3
|
+
|
4
|
+
alias_method :schema, :call
|
5
|
+
|
6
|
+
def initialize(model, endpoint)
|
7
|
+
@model = model
|
8
|
+
@endpoint = endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
# first let's grab the schema generated by the JSON:API parser
|
13
|
+
schema_json = schema.to_json
|
14
|
+
|
15
|
+
# From Nick Schneble:
|
16
|
+
|
17
|
+
# we can easily override these types for our API endpoints in the documentation
|
18
|
+
# but we can't do the same thing for the relationship objects that are auto-generated
|
19
|
+
# thus the fancy affair below
|
20
|
+
|
21
|
+
# if you want to learn more about what's happening here, read these:
|
22
|
+
# https://stackoverflow.com/a/17918118/1322386
|
23
|
+
# https://swagger.io/docs/specification/data-models/data-types/
|
24
|
+
|
25
|
+
# Swagger 3.0 only supports a subset of Ruby data types
|
26
|
+
schema_json.gsub!("\"type\":\"binary\"", "\"type\":\"string\", \"format\":\"binary\"")
|
27
|
+
schema_json.gsub!("\"type\":\"date\"", "\"type\":\"string\", \"format\":\"date\"")
|
28
|
+
schema_json.gsub!("\"type\":\"datetime\"", "\"type\":\"string\", \"format\":\"date-time\"")
|
29
|
+
schema_json.gsub!("\"type\":\"decimal\"", "\"type\":\"number\", \"format\":\"double\"")
|
30
|
+
schema_json.gsub!("\"type\":\"float\"", "\"type\":\"number\", \"format\":\"float\"")
|
31
|
+
schema_json.gsub!("\"type\":\"bigint\"", "\"type\":\"integer\", \"format\":\"int64\"")
|
32
|
+
schema_json.gsub!("\"type\":\"primary_key\"", "\"type\":\"integer\", \"format\":\"int64\"")
|
33
|
+
schema_json.gsub!("\"type\":\"references\"", "\"type\":\"object\"")
|
34
|
+
schema_json.gsub!("\"type\":\"text\"", "\"type\":\"string\"")
|
35
|
+
schema_json.gsub!("\"type\":\"time\"", "\"type\":\"string\", \"format\":\"time\"")
|
36
|
+
schema_json.gsub!("\"type\":\"timestamp\"", "\"type\":\"string\", \"format\":\"timestamp\"")
|
37
|
+
schema_json.gsub!("\"type\":\"json\"", "\"type\":\"array\", \"items\":{\"type\":\"string\"}")
|
38
|
+
|
39
|
+
# returns a Hash as if nothing fancy happened
|
40
|
+
JSON.parse(schema_json)
|
41
|
+
end
|
42
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class Api::V1::MeEndpoint < Api::V1::Root
|
2
|
-
resource :me do
|
2
|
+
resource :me, desc: Api.title(:actions) do
|
3
|
+
desc Api.title(:show), &Api.show_desc
|
3
4
|
oauth2
|
4
|
-
get
|
5
|
-
render
|
5
|
+
get do
|
6
|
+
render current_user, include: [:teams, :memberships], serializer: "Api::V1::UserSerializer", adapter: :attributes
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
@@ -4,9 +4,11 @@ module Api::V1::Base
|
|
4
4
|
included do
|
5
5
|
include Api::V1::Defaults
|
6
6
|
include Api::V1::LoadsAndAuthorizesApiResource
|
7
|
+
include Api::V1::ExceptionsHandler
|
7
8
|
|
8
9
|
version "v1"
|
9
|
-
|
10
|
+
|
11
|
+
use ::WineBouncer::OAuth2, message: "Doorkeeper OAuth2 Authentication"
|
10
12
|
|
11
13
|
rescue_from :all do |error|
|
12
14
|
handle_api_error(error)
|
@@ -15,6 +17,11 @@ module Api::V1::Base
|
|
15
17
|
BulletTrain::Api.endpoints.each do |endpoint_class|
|
16
18
|
mount endpoint_class.constantize
|
17
19
|
end
|
20
|
+
|
21
|
+
after_validation do
|
22
|
+
# Ensure responses never get cached.
|
23
|
+
header "Cache-Control", "no-store"
|
24
|
+
end
|
18
25
|
end
|
19
26
|
|
20
27
|
class_methods do
|
@@ -16,7 +16,7 @@ module Api::V1::Teams::EndpointBase
|
|
16
16
|
# `Api::V1::TeamsEndpoint`, but since we can get the latter, we'll use that to fetch whatever proc is defined
|
17
17
|
# in ADDITIONAL_PARAMS.
|
18
18
|
if defined?(@api.to_s.constantize::PARAMS)
|
19
|
-
instance_eval
|
19
|
+
instance_eval(&@api.to_s.constantize::PARAMS)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/bullet_train/api.rb
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
require "bullet_train/api/version"
|
2
2
|
require "bullet_train/api/engine"
|
3
3
|
|
4
|
+
require "grape"
|
5
|
+
require "grape-cancan"
|
6
|
+
require "grape_jsonapi"
|
7
|
+
require "grape-swagger"
|
8
|
+
require "grape_on_rails_routes"
|
9
|
+
# require "wine_bouncer"
|
10
|
+
require "pagy"
|
11
|
+
require "api-pagination"
|
12
|
+
require "rack/cors"
|
13
|
+
require "jsonapi/serializer"
|
14
|
+
require "doorkeeper"
|
15
|
+
|
4
16
|
module BulletTrain
|
5
17
|
module Api
|
6
18
|
mattr_accessor :endpoints, default: []
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.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: 2022-
|
11
|
+
date: 2022-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: standard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,6 +68,20 @@ dependencies:
|
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: grape-jsonapi
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: grape-swagger
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - ">="
|
@@ -67,7 +95,7 @@ dependencies:
|
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: grape_on_rails_routes
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -81,7 +109,7 @@ dependencies:
|
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: pagy
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -95,7 +123,7 @@ dependencies:
|
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: api-pagination
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - ">="
|
@@ -109,7 +137,7 @@ dependencies:
|
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
140
|
+
name: rack-cors
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - ">="
|
@@ -123,7 +151,7 @@ dependencies:
|
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
154
|
+
name: jsonapi-serializer
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
157
|
- - ">="
|
@@ -137,7 +165,7 @@ dependencies:
|
|
137
165
|
- !ruby/object:Gem::Version
|
138
166
|
version: '0'
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
168
|
+
name: doorkeeper
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
142
170
|
requirements:
|
143
171
|
- - ">="
|
@@ -151,7 +179,7 @@ dependencies:
|
|
151
179
|
- !ruby/object:Gem::Version
|
152
180
|
version: '0'
|
153
181
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
182
|
+
name: bullet_train
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
156
184
|
requirements:
|
157
185
|
- - ">="
|
@@ -178,6 +206,7 @@ files:
|
|
178
206
|
- app/controllers/account/platform/applications_controller.rb
|
179
207
|
- app/controllers/api.rb
|
180
208
|
- app/controllers/api/base.rb
|
209
|
+
- app/controllers/api/model_parser.rb
|
181
210
|
- app/controllers/api/v1.rb
|
182
211
|
- app/controllers/api/v1/defaults.rb
|
183
212
|
- app/controllers/api/v1/exceptions_handler.rb
|
@@ -207,6 +236,7 @@ files:
|
|
207
236
|
- app/views/account/platform/applications/show.html.erb
|
208
237
|
- app/views/account/platform/applications/show.json.jbuilder
|
209
238
|
- config/locales/en/api.en.yml
|
239
|
+
- config/locales/en/me.en.yml
|
210
240
|
- config/locales/en/platform/applications.en.yml
|
211
241
|
- config/routes.rb
|
212
242
|
- lib/bullet_train/api.rb
|
@@ -234,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
264
|
- !ruby/object:Gem::Version
|
235
265
|
version: '0'
|
236
266
|
requirements: []
|
237
|
-
rubygems_version: 3.
|
267
|
+
rubygems_version: 3.3.7
|
238
268
|
signing_key:
|
239
269
|
specification_version: 4
|
240
270
|
summary: Bullet Train API
|