bullet_train-api 1.6.37 → 1.6.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +257 -18
- data/lib/bullet_train/api/version.rb +1 -1
- data/lib/tasks/bullet_train/api_tasks.rake +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032efe953b88f9db79bee4f1e1b53f9a25b168a3579620d3c5e4ffe213734984
|
4
|
+
data.tar.gz: 3c15eabd737d77781282cef0be064121d35f1dffe4b012818fca5ac5c971ba85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40fb6d61b1968e0e584512bf33797432712665629bc16991b930a5a0934dde01c87512f213bc1db0b3145fee6e558abd1520814564ad1f682257dffe8eeda3b4
|
7
|
+
data.tar.gz: 1465a7fa12bd8be5d1ca2daaeb08c456acd7416b26dd880a8fac3ac31f63774227e675d4bc9066658e72c7d288fcc33a1940dbf2fdc64bee0ba4b3970306a6c3
|
data/README.md
CHANGED
@@ -1,28 +1,267 @@
|
|
1
1
|
# BulletTrain::Api
|
2
|
-
|
2
|
+
API capabilities for apps built with Bullet Train framework.
|
3
3
|
|
4
|
-
##
|
5
|
-
How to use my plugin.
|
4
|
+
## Quick Start
|
6
5
|
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
6
|
+
### Installation
|
9
7
|
|
10
|
-
|
11
|
-
gem "bullet_train-api"
|
12
|
-
```
|
8
|
+
Add this to your Gemfile:
|
13
9
|
|
14
|
-
|
15
|
-
```bash
|
16
|
-
$ bundle
|
17
|
-
```
|
10
|
+
gem "bullet_train-api"
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
Then, run `bundle` or install it manually using `gem install bullet_train-api`.
|
13
|
+
|
14
|
+
## Contents
|
15
|
+
|
16
|
+
- [API](#api)
|
17
|
+
- [Accessing](#accessing)
|
18
|
+
- [Versioning](#versioning)
|
19
|
+
- [Views](#views)
|
20
|
+
- [Documentation](#documentation)
|
21
|
+
- [Index file](#index-file)
|
22
|
+
- [Automatic Components](#automatic-components)
|
23
|
+
- [Automatic Paths](#automatic-paths)
|
24
|
+
- [External Markdown files](#external-markdown-files)
|
25
|
+
- [Examples](#examples)
|
26
|
+
- [Example IDs](#example-ids)
|
27
|
+
- [Associations](#associations)
|
28
|
+
- [Localization](#localization)
|
29
|
+
- [Rake Tasks](#rake-tasks)
|
30
|
+
- [Bump version](#bump-version)
|
31
|
+
- [Export OpenAPI document in file](#export-openapi-document-in-file)
|
32
|
+
- [Push OpenAPI document to Redocly](#push-openapi-document-to-redocly)
|
33
|
+
- [Create separate translations for API](#create-separate-translations-for-api)
|
34
|
+
- [Contributing](#contributing)
|
35
|
+
- [License](#license)
|
36
|
+
- [Sponsor](#open-source-development-sponsored-by)
|
37
|
+
|
38
|
+
### API
|
39
|
+
|
40
|
+
BulletTrain::Api defines basic REST actions for every model generated with super-scaffolding.
|
41
|
+
|
42
|
+
#### Accessing
|
43
|
+
|
44
|
+
BulletTrain::Api uses Bearer token as a default authentication method with the help of [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) gem.
|
45
|
+
It uses the idea that in order to access the API, there should be a Platform Application object, which can have access to different parts of the application.
|
46
|
+
In Bullet Train, each Team may have several Platform Applications (created in Developers > API menu). When a Platform Application is created,
|
47
|
+
it automatically generates an Bearer Token needed to access the API, controlled by this Platform Application.
|
48
|
+
|
49
|
+
#### Versioning
|
50
|
+
|
51
|
+
Versions are being set automatically based on the location of the controller.
|
52
|
+
|
53
|
+
Current version can also be checked with
|
54
|
+
````ruby
|
55
|
+
BulletTrain::Api.current_version
|
56
|
+
````
|
57
|
+
|
58
|
+
#### Views
|
59
|
+
All API response templates are located in `app/views/api/<version>/` and are written using standard jbuilder syntax.
|
60
|
+
|
61
|
+
### Documentation
|
62
|
+
|
63
|
+
This gem automatically generates OpenAPI 3.1 compatible documentation at:
|
64
|
+
|
65
|
+
/api/v1/openapi.yaml
|
66
|
+
|
67
|
+
|
68
|
+
#### Index File
|
69
|
+
|
70
|
+
app/views/api/v1/open_api/index.yaml.erb
|
71
|
+
|
72
|
+
The index file is the central point for the API documentation. This consists of a number of sections,
|
73
|
+
some that get pulled in and bundled at build time.
|
74
|
+
|
75
|
+
The file is in YAML format, but includes erb code which generates additional YAML with the help of [`jbuilder-schema`](https://github.com/bullet-train-co/jbuilder-schema) gem.
|
76
|
+
|
77
|
+
#### Automatic Components
|
78
|
+
|
79
|
+
There are several helper methods available in Index file.
|
80
|
+
One of them is `automatic_components_for`, which generates two schemas of a model, Attributes and Parameters, based on it's Jbuilder show file.
|
81
|
+
Parameters are used in requests and Attributes are used in responses.
|
82
|
+
|
83
|
+
For example this code:
|
84
|
+
````yaml
|
85
|
+
components:
|
86
|
+
schemas:
|
87
|
+
<%= automatic_components_for User %>
|
88
|
+
````
|
89
|
+
looks for the file `app/views/api/v1/users/_user.json.jbuilder`.
|
90
|
+
Let's say it has this contents:
|
91
|
+
````ruby
|
92
|
+
json.extract! user,
|
93
|
+
:id,
|
94
|
+
:email,
|
95
|
+
:name
|
96
|
+
````
|
97
|
+
then the produced component will be:
|
98
|
+
````yaml
|
99
|
+
components:
|
100
|
+
schemas:
|
101
|
+
UserAttributes:
|
102
|
+
type: object
|
103
|
+
title: Users
|
104
|
+
description: Users
|
105
|
+
required:
|
106
|
+
- id
|
107
|
+
- email
|
108
|
+
properties:
|
109
|
+
id:
|
110
|
+
type: integer
|
111
|
+
description: Team ID
|
112
|
+
email:
|
113
|
+
type: string
|
114
|
+
description: Email Address
|
115
|
+
name:
|
116
|
+
type:
|
117
|
+
- string
|
118
|
+
- 'null'
|
119
|
+
description: Name
|
120
|
+
example:
|
121
|
+
id: 42
|
122
|
+
email: generic-user-1@example.com
|
123
|
+
name: Example Name
|
124
|
+
UserParameters:
|
125
|
+
type: object
|
126
|
+
title: Users
|
127
|
+
description: Users
|
128
|
+
required:
|
129
|
+
- email
|
130
|
+
properties:
|
131
|
+
email:
|
132
|
+
type: string
|
133
|
+
description: Email Address
|
134
|
+
name:
|
135
|
+
type:
|
136
|
+
- string
|
137
|
+
- 'null'
|
138
|
+
description: Name
|
139
|
+
example:
|
140
|
+
email: generic-user-1@example.com
|
141
|
+
name: Example First Name
|
142
|
+
````
|
143
|
+
As you can see, it automatically sets required fields based on presence validators of the model,
|
144
|
+
field types based on the value found in Jbuilder file, descriptions and examples.
|
145
|
+
More on how it works and how you can customize the output in [`jbuilder-schema`](https://github.com/bullet-train-co/jbuilder-schema) documentation.
|
146
|
+
|
147
|
+
#### Automatic Paths
|
148
|
+
|
149
|
+
Method `automatic_paths_for` generates basic REST paths. It accepts model as it's argument.
|
150
|
+
To generate paths for nested models, pass parent model as a second argument. It also accepts `except` as a third argument,
|
151
|
+
where you can list actions which paths you don't want to be generated.
|
152
|
+
|
153
|
+
If the methods defined in the `automatic_paths_for` for the endpoints support
|
154
|
+
a write action (i.e. create or update), then doc generation uses the `strong_parameters`
|
155
|
+
defined in the corresponding controller to generate the Parameters section in the schema.
|
156
|
+
|
157
|
+
Automatic paths are generated for basic REST actions. You can customize those paths or add your own by creating a
|
158
|
+
file at `app/views/api/<version>/open_api/<Model.underscore.plural>/_paths.yaml.erb`. For REST paths there's no need to
|
159
|
+
duplicate all the schema, you can specify only what differs from auto-generated code.
|
160
|
+
|
161
|
+
#### External Markdown files
|
162
|
+
|
163
|
+
External text files with Markdown markup can be added with `external_doc` method.
|
164
|
+
It assumes that the file with `.md` extension can be found in `app/views/api/<version>/open_api/docs`.
|
165
|
+
You can also use `description_for` method with a model, then there should be file `app/views/api/<version>/open_api/docs/<Model.name.underscore>_description.md`
|
166
|
+
|
167
|
+
This allows including external markdown files in OpenAPI schema like in this example:
|
168
|
+
|
169
|
+
````yaml
|
170
|
+
openapi: 3.1.0
|
171
|
+
info:
|
172
|
+
...
|
173
|
+
description: <%= external_doc "info_description" %>
|
174
|
+
...
|
175
|
+
tags:
|
176
|
+
- name: Team
|
177
|
+
description: <%= description_for Team %>
|
178
|
+
- name: Addresses::Country
|
179
|
+
description: <%= description_for Addresses::Country %>
|
180
|
+
...
|
181
|
+
````
|
182
|
+
supposing the following files exist:
|
183
|
+
````
|
184
|
+
app/views/api/v1/open_api/docs/info_description.md
|
185
|
+
app/views/api/v1/open_api/docs/team_description.md
|
186
|
+
app/views/api/v1/open_api/docs/addresses/country_description.md
|
187
|
+
````
|
188
|
+
|
189
|
+
#### Examples
|
190
|
+
|
191
|
+
In order to generate example requests and responses for the documentation in the
|
192
|
+
`automatic_components_for` calls, the bullet_train-api gem contains `ExampleBot`
|
193
|
+
which uses FactoryBot to build an in-memory representation of the model,
|
194
|
+
then generates the relevant OpenAPI schema for that model.
|
195
|
+
|
196
|
+
ExampleBot will attempt to create an instance of the given model called `<model>_example`.
|
197
|
+
For namespaced models, `<plural_namespaces>_<model>_example`
|
198
|
+
|
199
|
+
For example, for the Order model, use `order_example` factory.
|
200
|
+
|
201
|
+
For Orders::Invoices::LineItem, use `orders_invoices_line_item_example` factory.
|
202
|
+
|
203
|
+
When writing the factory, the example factory should usually inherit from the existing factory,
|
204
|
+
but in some cases (usually if the existing factory uses callbacks or creates associations
|
205
|
+
that you may not want), you may wish to not inherit from the existing one.
|
206
|
+
|
207
|
+
##### Example IDs
|
208
|
+
|
209
|
+
Since we only want to use in-memory instances, we need to ensure that all examples
|
210
|
+
have an `id` specified, along with `created_at` and `updated_at`, otherwise they
|
211
|
+
will show as `null` in the examples.
|
212
|
+
|
213
|
+
You may wish to use `sequence` for the id in the examples, but you need to be careful
|
214
|
+
not to create circular references (see Associations section below)
|
215
|
+
|
216
|
+
##### Associations
|
217
|
+
|
218
|
+
You need to be careful when specifying associated examples since it is easy to get
|
219
|
+
into a recursive loop (see Example IDs section above). Also, ensure that you only
|
220
|
+
create associations using `FactoryBot.example()` and not `create`, otherwise it will
|
221
|
+
create records in your database.
|
222
|
+
|
223
|
+
#### Localization
|
224
|
+
|
225
|
+
The documentation requires that `"#{model.name.underscore.pluralize}.label"` localisation value is defined,
|
226
|
+
which will be used to set model title and description.
|
227
|
+
|
228
|
+
### Rake Tasks
|
229
|
+
|
230
|
+
#### Bump version
|
231
|
+
|
232
|
+
Bump the current version of application's API:
|
233
|
+
|
234
|
+
rake bullet_train:api:bump_version
|
235
|
+
|
236
|
+
#### Export OpenAPI document in file
|
237
|
+
|
238
|
+
Export the OpenAPI schema for the application to `tmp/openapi` directory:
|
239
|
+
|
240
|
+
rake bullet_train:api:export_openapi_schema
|
241
|
+
|
242
|
+
#### Push OpenAPI document to Redocly
|
243
|
+
|
244
|
+
Needs `REDOCLY_ORGANIZATION_ID` and `REDOCLY_API_KEY` to be set:
|
245
|
+
|
246
|
+
rake bullet_train:api:push_to_redocly
|
247
|
+
|
248
|
+
#### Create separate translations for API
|
249
|
+
|
250
|
+
Starting in 1.6.28, Bullet Train Scaffolding generates separate translations for API documentation: `api_title` and `api_description`.
|
251
|
+
This rake task will add those translations for the existing fields, based on their `heading` value:
|
252
|
+
|
253
|
+
rake bullet_train:api:create_translations
|
254
|
+
|
255
|
+
It only needs to be run once after upgrade.
|
23
256
|
|
24
257
|
## Contributing
|
25
|
-
|
258
|
+
|
259
|
+
Contributions are welcome! Report bugs and submit pull requests on [GitHub](https://github.com/bullet-train-co/bullet_train-core/tree/main/bullet_train-api).
|
26
260
|
|
27
261
|
## License
|
28
|
-
|
262
|
+
|
263
|
+
This gem is open source under the [MIT License](https://opensource.org/licenses/MIT).
|
264
|
+
|
265
|
+
## Open-source development sponsored by:
|
266
|
+
|
267
|
+
<a href="https://www.clickfunnels.com"><img src="https://images.clickfunnel.com/uploads/digital_asset/file/176632/clickfunnels-dark-logo.svg" width="575" /></a>
|
@@ -92,7 +92,7 @@ namespace :bullet_train do
|
|
92
92
|
puts "Finished bumping to #{new_version}"
|
93
93
|
end
|
94
94
|
|
95
|
-
desc "
|
95
|
+
desc "Push OpenAPI yaml file to Redocly"
|
96
96
|
task push_to_redocly: :environment do
|
97
97
|
include Rails.application.routes.url_helpers
|
98
98
|
|
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.6.
|
4
|
+
version: 1.6.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
description: Bullet Train
|
167
|
+
description: API capabilities for apps built with Bullet Train framework
|
168
168
|
email:
|
169
169
|
- andrew.culver@gmail.com
|
170
170
|
executables: []
|