bullet_train-api 1.0.7 → 1.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 892999078661fe5c970b56d9718403df7fe909748b0764b31f8da8ff5f3ae166
4
- data.tar.gz: 8cd26976c5abdbb57a838503f11b046364eae8d5165c1c94ff4bae231886230f
3
+ metadata.gz: 766d45178150439d1076f0330084c75f25f6349943a6cd90ae55061a9900cd08
4
+ data.tar.gz: 578914d5271157d1a3709174464e7fcd15441c6391a3fcc5ee9c9dd997decb06
5
5
  SHA512:
6
- metadata.gz: 3a8290f40a81d4dd0ca8dded910b8a2907a96bd0e6c9ca03f339b310ac2d95ce62af5fc468a13266daffdcf84c06a5f3afcd97e3e2959aff340b43d6875c7307
7
- data.tar.gz: 4029a5b7cc6d41141d280e2b55be9e638b45bac86cc3f8360c6a9eeba404d92df17aab8d89da4119768263f4006b1fe052d6534c853146f200a45e6cd82d5c72
6
+ metadata.gz: 9f56d8880d393c5d9eb568b345328cca556fb5d6592187833395959fbf8b2cfd8a78cb9f9cf6a53b695b1c5491279ba69eb72d168ff7c6611437d4db96e868e5
7
+ data.tar.gz: 5e199bab324f5f1d6f6d28b0ffee43d5c0f649b46b019257760a5b05a2de0e325d1e8c387385bcb6402e21bb2f50bbdc69a54640ab96d97750fed5b17cef88dd
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 Andrew Culver
1
+ Copyright 2022 Bullet Train, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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/swagger_doc.json`.
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
- endpoint_auth_wrapper: WineBouncer::OAuth2
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
@@ -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
- use ::WineBouncer::OAuth2
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 &@api.to_s.constantize::PARAMS
19
+ instance_eval(&@api.to_s.constantize::PARAMS)
20
20
  end
21
21
  end
22
22
  end
@@ -3,7 +3,7 @@ require "grape-cancan"
3
3
  require "grape_jsonapi"
4
4
  require "grape-swagger"
5
5
  require "grape_on_rails_routes"
6
- require "wine_bouncer"
6
+ # require "wine_bouncer"
7
7
  require "kaminari"
8
8
  require "api-pagination"
9
9
  require "rack/cors"
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.0.7"
3
+ VERSION = "1.0.13"
4
4
  end
5
5
  end
@@ -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 "kaminari"
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.7
4
+ version: 1.0.13
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-02-16 00:00:00.000000000 Z
11
+ date: 2022-04-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
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: wine_bouncer
112
+ name: kaminari
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: kaminari
126
+ name: api-pagination
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -123,7 +137,7 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
- name: api-pagination
140
+ name: rack-cors
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ">="
@@ -137,7 +151,35 @@ dependencies:
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: rack-cors
154
+ name: jsonapi-serializer
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: doorkeeper
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: bullet_train
141
183
  requirement: !ruby/object:Gem::Requirement
142
184
  requirements:
143
185
  - - ">="
@@ -164,6 +206,7 @@ files:
164
206
  - app/controllers/account/platform/applications_controller.rb
165
207
  - app/controllers/api.rb
166
208
  - app/controllers/api/base.rb
209
+ - app/controllers/api/model_parser.rb
167
210
  - app/controllers/api/v1.rb
168
211
  - app/controllers/api/v1/defaults.rb
169
212
  - app/controllers/api/v1/exceptions_handler.rb