bump-cli 2.9.2 → 2.9.3
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.
- package/README.md +101 -88
- package/dist/core/overlay.d.ts +4 -0
- package/dist/core/overlay.js +90 -50
- package/oclif.manifest.json +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="https://
|
|
8
|
+
<a href="https://docs.bump.sh/help">Help</a> |
|
|
9
9
|
<a href="https://bump.sh/users/sign_up">Sign up</a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
|
-
The Bump.sh CLI is used to interact with
|
|
12
|
+
The Bump.sh CLI is used to interact with API documentation and hubs hosted on Bump.sh from your choice of popular API description formats: OpenAPI, Swagger, or AsyncAPI.
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
- Publish an API document to your Bump.sh documentation or hubs
|
|
16
|
-
- Compare two API documents to generate a human-readable diff from your API definitions
|
|
14
|
+
Using [OpenAPI](https://github.com/OAI/OpenAPI-Specification) (v3.x and v2.0) or [AsyncAPI](https://www.asyncapi.com/docs/reference/specification/latest) (2.x), you can do any of the following:
|
|
17
15
|
|
|
16
|
+
- Validate an API document before publishing to your documentation.
|
|
17
|
+
- Publish an API document to your Bump.sh documentation or hubs.
|
|
18
|
+
- Compare two API documents to generate a human-readable diff from your API definition.
|
|
18
19
|
Under the hood, it uses the API of [developers.bump.sh](https://developers.bump.sh). And is built with the [`oclif`](https://oclif.io) framework in Typescript.
|
|
19
20
|
|
|
20
21
|
[](https://npmjs.org/package/bump-cli)
|
|
@@ -34,43 +35,43 @@ Under the hood, it uses the API of [developers.bump.sh](https://developers.bump.
|
|
|
34
35
|
|
|
35
36
|
The Bump.sh CLI is a node package currently distributed via NPM. This means you must have the Node v20+ interpreter installed on your computer or CI servers.
|
|
36
37
|
|
|
37
|
-
_If you are looking to use Bump.sh in a continuous integration environment you might be interested by [our Github Action](https://github.com/marketplace/actions/api-documentation-
|
|
38
|
+
_If you are looking to use Bump.sh in a continuous integration environment you might be interested by [our Github Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog)._
|
|
38
39
|
|
|
39
40
|
> You can download a standalone package directly from the latest
|
|
40
|
-
>
|
|
41
|
+
> Github release assets if you don’t use Node.
|
|
41
42
|
{: .info}
|
|
42
43
|
|
|
43
44
|
### Global installation
|
|
44
45
|
|
|
45
|
-
To install it globally, run the following command with NPM
|
|
46
|
+
To install it globally, run the following command with NPM:
|
|
46
47
|
|
|
47
|
-
```
|
|
48
|
+
```shell
|
|
48
49
|
npm install -g bump-cli
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
Or, with Yarn via
|
|
52
|
+
Or, with Yarn via:
|
|
52
53
|
|
|
53
|
-
```
|
|
54
|
+
```shell
|
|
54
55
|
yarn global add bump-cli
|
|
55
56
|
```
|
|
56
57
|
|
|
57
58
|
### Add Bump.sh to your Node project
|
|
58
59
|
|
|
59
|
-
As our CLI is a node package, you can easily embed it
|
|
60
|
+
As our CLI is a node package, you can easily embed it to your project by adding the package to your `package.json` file, either with NPM:
|
|
60
61
|
|
|
61
|
-
```
|
|
62
|
+
```shell
|
|
62
63
|
npm install --save-dev bump-cli
|
|
63
64
|
```
|
|
64
65
|
|
|
65
|
-
Or with Yarn via
|
|
66
|
+
Or with Yarn via:
|
|
66
67
|
|
|
67
|
-
```
|
|
68
|
+
```shell
|
|
68
69
|
yarn add --dev bump-cli
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
You can then use any Bump.sh commands with `npx` (same as `npm exec`)
|
|
72
|
+
You can then use any Bump.sh commands with `npx` (same as `npm exec`):
|
|
72
73
|
|
|
73
|
-
```
|
|
74
|
+
```shell
|
|
74
75
|
npx bump --help
|
|
75
76
|
```
|
|
76
77
|
|
|
@@ -82,12 +83,12 @@ Unfortunately, at the moment we only support the Node environment. However, you
|
|
|
82
83
|
|
|
83
84
|
To list all the available commands, just type `bump` in your command line environment.
|
|
84
85
|
|
|
85
|
-
```
|
|
86
|
+
```shell
|
|
86
87
|
$ bump --help
|
|
87
88
|
The Bump.sh CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh
|
|
88
89
|
|
|
89
90
|
VERSION
|
|
90
|
-
bump-cli/2.9.
|
|
91
|
+
bump-cli/2.9.2 linux-x64 node-v20.18.1
|
|
91
92
|
|
|
92
93
|
USAGE
|
|
93
94
|
$ bump [COMMAND]
|
|
@@ -110,16 +111,16 @@ Head over to your Documentation settings in the “CI deployment” section or y
|
|
|
110
111
|
|
|
111
112
|
## Commands
|
|
112
113
|
|
|
113
|
-
* [`bump deploy [FILE]`](#
|
|
114
|
-
* [`bump diff [FILE]`](#
|
|
115
|
-
* [`bump preview [FILE]`](#
|
|
116
|
-
* [`bump overlay [DEFINITION_FILE] [OVERLAY_FILE]`](#
|
|
114
|
+
* [`bump deploy [FILE]`](#the-deploy-command)
|
|
115
|
+
* [`bump diff [FILE]`](#the-diff-command)
|
|
116
|
+
* [`bump preview [FILE]`](#the-preview-command)
|
|
117
|
+
* [`bump overlay [DEFINITION_FILE] [OVERLAY_FILE]`](#the-overlay-command)
|
|
117
118
|
|
|
118
|
-
### `
|
|
119
|
+
### The `deploy` command
|
|
119
120
|
|
|
120
|
-
When
|
|
121
|
+
When an API is updated, the documentation should be updated at the same time. This is what the deploy command is for.
|
|
121
122
|
|
|
122
|
-
```
|
|
123
|
+
```shell
|
|
123
124
|
bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN
|
|
124
125
|
```
|
|
125
126
|
|
|
@@ -128,7 +129,7 @@ bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN
|
|
|
128
129
|
|
|
129
130
|
You can also deploy a given API document to a different branch of your documentation with the `--branch <branch-name>` parameter. Please note the branch will be created if it doesn’t exist. More details about the branching feature are available on [this dedicated help page](https://docs.bump.sh/help/branching). E.g. deploy the API document to the `staging` branch of the documentation:
|
|
130
131
|
|
|
131
|
-
```
|
|
132
|
+
```shell
|
|
132
133
|
bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN --branch staging
|
|
133
134
|
```
|
|
134
135
|
|
|
@@ -136,7 +137,7 @@ bump deploy path/to/api-document.yml --doc my-documentation --token $DOC_TOKEN -
|
|
|
136
137
|
|
|
137
138
|
If you already have a hub in your [Bump.sh](https://bump.sh) account, you can automatically create documentation and deploy it into that hub by publishing a whole directory containing multiple API documents in a single command:
|
|
138
139
|
|
|
139
|
-
```
|
|
140
|
+
```shell
|
|
140
141
|
bump deploy dir/path/to/apis/ --auto-create --hub my-hub --token $HUB_TOKEN
|
|
141
142
|
```
|
|
142
143
|
|
|
@@ -168,69 +169,81 @@ bump deploy path/to/apis/ --hub my-hub --filename-pattern '*-api-{slug}-service'
|
|
|
168
169
|
|
|
169
170
|
Simulate your API document's deployment to ensure it is valid by adding the `--dry-run` flag to the `deploy` command. It is handy in a Continuous Integration environment running a test deployment outside your main branch:
|
|
170
171
|
|
|
171
|
-
```
|
|
172
|
+
```shell
|
|
172
173
|
bump deploy path/to/api-document.yml --dry-run --doc my-documentation --token $DOC_TOKEN
|
|
173
174
|
```
|
|
174
175
|
|
|
175
176
|
Please check `bump deploy --help` for more usage details.
|
|
176
177
|
|
|
177
|
-
### `
|
|
178
|
-
|
|
179
|
-
_If you want to receive automatic `bump diff` results on your Github Pull Requests you might be interested by [our Github Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog) which also has a diff command._
|
|
178
|
+
### The `diff` command
|
|
180
179
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
environment and want the command to fail **in case of a breaking
|
|
184
|
-
change**, you will need to add the `--fail-on-breaking` flag to your
|
|
185
|
-
diff command. By default if the environment variable `CI=1` is present
|
|
186
|
-
(in most continuous integration environment), the flag will be
|
|
187
|
-
enabled. In that case you can disable the failures with
|
|
188
|
-
`--no-fail-on-breaking` flag.
|
|
180
|
+
Using the `diff` command can help to spot differences between the local API
|
|
181
|
+
document and the latest deployed version.
|
|
189
182
|
|
|
190
183
|
#### Public API diffs
|
|
191
184
|
|
|
192
|
-
From any two API documents or URLs, you can retrieve a comprehensive changelog
|
|
185
|
+
From any two API documents or URLs, you can retrieve a comprehensive changelog
|
|
186
|
+
of what has changed between them.
|
|
193
187
|
|
|
194
|
-
```
|
|
188
|
+
```shell
|
|
195
189
|
$ bump diff path/to/your/file.yml path/to/your/second_file.yml
|
|
196
190
|
* Comparing the two given definition files... done
|
|
197
191
|
Modified: GET /consommations
|
|
198
192
|
Response modified: 200
|
|
199
193
|
[Breaking] Body attribute modified: energie
|
|
200
194
|
```
|
|
201
|
-
> You can create as many diffs as you like without being authenticated. This is a **free and unlimited service** provided as long as you use the service fairly.
|
|
202
|
-
{: .info}
|
|
203
195
|
|
|
204
|
-
|
|
196
|
+
By default the command will always exit with a successful return code. If you
|
|
197
|
+
want to use this command in a CI environment and want the command to fail **in
|
|
198
|
+
case of a breaking change**, you will need to add the `--fail-on-breaking` flag
|
|
199
|
+
to your diff command.
|
|
200
|
+
|
|
201
|
+
By default if the environment variable `CI=1` is present (in most continuous
|
|
202
|
+
integration environment), the flag will be enabled. In that case you can disable
|
|
203
|
+
the failures with `--no-fail-on-breaking` flag.
|
|
204
|
+
|
|
205
|
+
You can also test this feature in our dedicated web application at
|
|
206
|
+
<https://api-diff.io/>.
|
|
207
|
+
|
|
208
|
+
#### GitHub Integration
|
|
209
|
+
|
|
210
|
+
If you want to receive automatic `bump diff` results on Github Pull Requests you
|
|
211
|
+
might be interested by [our Github
|
|
212
|
+
Action](https://github.com/marketplace/actions/bump-sh-api-documentation-changelog#deploy-documentation--diff-on-pull-requests)
|
|
213
|
+
which has support for the diff command.
|
|
205
214
|
|
|
206
215
|
#### Authenticated diffs related to your Bump.sh documentation
|
|
207
216
|
|
|
208
|
-
From an existing Bump.sh documentation, the `diff` command will retrieve a
|
|
217
|
+
From an existing Bump.sh documentation, the `diff` command will retrieve a
|
|
218
|
+
comparison changelog between your latest published documentation and the given
|
|
219
|
+
file or URL:
|
|
209
220
|
|
|
210
|
-
```
|
|
221
|
+
```shell
|
|
211
222
|
bump diff path/to/your/file.yml --doc my-documentation --token $DOC_TOKEN
|
|
212
223
|
```
|
|
213
224
|
|
|
214
225
|
If you want to compare two unpublished versions of your API document, the `diff` command can retrieve a comparison changelog between two given file or URL, “as simple as `git diff`”:
|
|
215
226
|
|
|
216
|
-
```
|
|
227
|
+
```shell
|
|
217
228
|
bump diff path/to/your/file.yml path/to/your/next-file.yml --doc my-documentation --token $DOC_TOKEN
|
|
218
229
|
```
|
|
219
230
|
|
|
220
231
|
Please check `bump diff --help` for full usage details.
|
|
221
232
|
|
|
222
|
-
### `
|
|
233
|
+
### The `preview` command
|
|
223
234
|
|
|
235
|
+
When writing documentation, you might want to preview how it renders on Bump.sh.
|
|
236
|
+
This is precisely the goal of the `preview` command: it will create temporary
|
|
237
|
+
documentation with a unique URL, which will be available for a short period (30
|
|
238
|
+
minutes).
|
|
224
239
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
Usage from a local OpenAPI or AsyncAPI file
|
|
240
|
+
Usage from a local OpenAPI or AsyncAPI document:
|
|
228
241
|
|
|
229
242
|
```shell
|
|
230
243
|
bump preview path/to/file.json
|
|
231
244
|
```
|
|
232
245
|
|
|
233
|
-
You can also preview a
|
|
246
|
+
You can also preview a document available via a URL:
|
|
234
247
|
|
|
235
248
|
```shell
|
|
236
249
|
bump preview https://developers.bump.sh/source.yaml
|
|
@@ -243,37 +256,48 @@ By using the `--live` flag you can stay focused on API design (OpenAPI or AsyncA
|
|
|
243
256
|
- Launch the live preview command in your terminal
|
|
244
257
|
|
|
245
258
|
```shell
|
|
246
|
-
bump preview --live --open
|
|
259
|
+
bump preview --live --open api-document.yaml
|
|
247
260
|
```
|
|
248
261
|
|
|
249
|
-
- Edit your `
|
|
262
|
+
- Edit your `api-document.yaml` file in your favorite text editor.
|
|
250
263
|
- Watch the live preview being updated each time you save your file.
|
|
264
|
+
- The additional `--open` flag helps to automatically open the preview URL in your browser.
|
|
251
265
|
|
|
252
266
|
> You can create as many previews as you like without being authenticated. This is a **free and unlimited service**.
|
|
253
267
|
{: .info}
|
|
254
268
|
|
|
255
|
-
_**Note:** the additional `--open` flag helps to automatically open the preview URL in your browser._
|
|
256
|
-
|
|
257
269
|
Please check `bump preview --help` for more usage details
|
|
258
270
|
|
|
259
|
-
### `
|
|
271
|
+
### The `overlay` command
|
|
260
272
|
|
|
261
|
-
|
|
273
|
+
The [Overlay Specification](https://spec.openapis.org/overlay/v1.0.0.html) from the OpenAPI Initiative makes it possible to modify the content of an API definition by adding a layer on top of it. That layer helps adding, removing or changing some or all of the content of the original definition.
|
|
262
274
|
|
|
263
|
-
The
|
|
275
|
+
The `bump overlay` command takes an original API document, applies the changes from the overlay document, and outputs a modified version. No changes are made directly to the original document.
|
|
264
276
|
|
|
265
|
-
|
|
277
|
+
```shell
|
|
278
|
+
bump overlay api-document.yaml overlay.yaml
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
To redirect the output of the command to a new file you can run:
|
|
282
|
+
|
|
283
|
+
```shell
|
|
284
|
+
bump overlay api-document.yaml overlay.yaml > modified-api-document.yaml
|
|
285
|
+
```
|
|
266
286
|
|
|
267
|
-
|
|
287
|
+
You can also apply the overlay using the [`deploy` command](#the-deploy-command) with the `--overlay` flag:
|
|
268
288
|
|
|
269
289
|
```shell
|
|
270
|
-
bump
|
|
290
|
+
bump deploy api-document.yaml --doc my-doc --token my-token --overlay overlay.yaml
|
|
271
291
|
```
|
|
272
292
|
|
|
273
|
-
|
|
293
|
+
If there are multiple overlays which need to be applied, the `--overlay` can be passed multiple times.
|
|
274
294
|
|
|
275
295
|
```shell
|
|
276
|
-
bump deploy api-document.yaml
|
|
296
|
+
bump deploy api-document.yaml \
|
|
297
|
+
--doc my-doc \
|
|
298
|
+
--token my-token \
|
|
299
|
+
--overlay overlay1.yaml \
|
|
300
|
+
--overlay overlay2.yaml
|
|
277
301
|
```
|
|
278
302
|
|
|
279
303
|
## Development
|
|
@@ -282,55 +306,44 @@ Make sure to have Node.js (At least v20) installed on your machine.
|
|
|
282
306
|
|
|
283
307
|
- Install node dependencies with
|
|
284
308
|
|
|
285
|
-
```
|
|
309
|
+
```shell
|
|
286
310
|
npm install
|
|
287
311
|
```
|
|
288
312
|
|
|
289
313
|
- Compile the Typescript code
|
|
290
314
|
|
|
291
|
-
|
|
315
|
+
|
|
316
|
+
```shell
|
|
292
317
|
npm run build
|
|
293
|
-
npm run clean #
|
|
318
|
+
npm run clean # Remove build artifacts
|
|
294
319
|
```
|
|
295
320
|
|
|
296
321
|
- Format the codebase to comply with the linter rules
|
|
297
322
|
|
|
298
|
-
```
|
|
323
|
+
```shell
|
|
299
324
|
npm run fmt
|
|
300
325
|
```
|
|
301
326
|
|
|
302
327
|
- Run the test suites
|
|
303
|
-
|
|
304
|
-
```
|
|
328
|
+
|
|
329
|
+
```shell
|
|
305
330
|
npm run test
|
|
306
331
|
npm run test-coverage # Run tests with coverage
|
|
307
332
|
```
|
|
308
333
|
|
|
309
|
-
##
|
|
334
|
+
## License
|
|
310
335
|
|
|
311
|
-
|
|
336
|
+
The Bump CLI project is released under the [MIT License](http://opensource.org/licenses/MIT).
|
|
312
337
|
|
|
313
338
|
## Contributing
|
|
314
339
|
|
|
315
340
|
Bug reports and pull requests are welcome on GitHub at <https://github.com/bump-sh/cli>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
316
341
|
|
|
317
|
-
## Thanks
|
|
318
|
-
|
|
319
|
-
- [Lorna Mitchel](https://github.com/lornajane/) for [openapi-overlay-js](https://github.com/lornajane/openapi-overlays-js)
|
|
320
|
-
|
|
321
|
-
## License
|
|
322
|
-
|
|
323
|
-
The Bump CLI project is released under the [MIT License](http://opensource.org/licenses/MIT).
|
|
324
|
-
|
|
325
342
|
## Code of Conduct
|
|
326
343
|
|
|
327
344
|
Everyone interacting in the Bump-CLI project codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/bump-sh/.github/blob/main/CODE_OF_CONDUCT.md).
|
|
328
345
|
|
|
329
|
-
##
|
|
330
|
-
|
|
331
|
-
This npm package starts at v2.0.0 for two main reasons:
|
|
332
|
-
|
|
333
|
-
- Our [first version](https://github.com/bump-sh/bump-cli) of the Bump CLI was written in Ruby, starting at v2.0.0, which makes it clear we are working on our second version of the Bump CLI
|
|
346
|
+
## Thanks
|
|
334
347
|
|
|
335
|
-
-
|
|
336
|
-
|
|
348
|
+
- [Lorna Mitchel](https://github.com/lornajane/) for [openapi-overlay-js](https://github.com/lornajane/openapi-overlays-js).
|
|
349
|
+
- [Rico](https://github.com/rstacruz) for transferring the ownership of the `bump-cli` package name.
|
package/dist/core/overlay.d.ts
CHANGED
|
@@ -2,4 +2,8 @@ import { APIDefinition, OpenAPIOverlay } from '../definition.js';
|
|
|
2
2
|
export declare class Overlay {
|
|
3
3
|
d(formatter: any, ...args: any[]): void;
|
|
4
4
|
run(spec: APIDefinition, overlay: OpenAPIOverlay): APIDefinition;
|
|
5
|
+
private executeAction;
|
|
6
|
+
private humanName;
|
|
7
|
+
private remove;
|
|
8
|
+
private update;
|
|
5
9
|
}
|
package/dist/core/overlay.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
|
|
3
|
-
import jsonpath from 'jsonpath';
|
|
2
|
+
import * as jsonpath from 'jsonpathly';
|
|
4
3
|
import { mergician } from 'mergician';
|
|
5
4
|
export class Overlay {
|
|
6
5
|
// WIP @github.com/lornajane/openapi-overlays-js
|
|
@@ -19,63 +18,104 @@ export class Overlay {
|
|
|
19
18
|
// If you make any changes here, PLEASE ALSO MAKE THEM UPSTREAM.
|
|
20
19
|
run(spec, overlay) {
|
|
21
20
|
// Use jsonpath.apply to do the changes
|
|
22
|
-
if (overlay.actions && overlay.actions.length > 0)
|
|
21
|
+
if (overlay.actions && overlay.actions.length > 0) {
|
|
23
22
|
for (const a of overlay.actions) {
|
|
24
23
|
const action = a;
|
|
25
24
|
if (!action.target) {
|
|
26
|
-
process.stderr.write(
|
|
25
|
+
process.stderr.write(`WARNING: ${this.humanName(action)} has an empty target\n`);
|
|
27
26
|
continue;
|
|
28
27
|
}
|
|
29
28
|
const target = action.target;
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const thingToRemove = path[0].at(-1);
|
|
40
|
-
if (thingToRemove !== undefined) {
|
|
41
|
-
if (Array.isArray(parent)) {
|
|
42
|
-
parent.splice(thingToRemove, 1);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
delete parent[thingToRemove];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
29
|
+
// jsonpathly's paths are strings. They represent a “Path
|
|
30
|
+
// expression” which represents the absolute path in the objet
|
|
31
|
+
// tree reached by our `target`.
|
|
32
|
+
//
|
|
33
|
+
// E.g. '$["store"]["book"][0]["price"]'
|
|
34
|
+
const paths = jsonpath.paths(spec, target);
|
|
35
|
+
if (paths.length === 0) {
|
|
36
|
+
process.stderr.write(`WARNING: Action target '${target}' has no matching elements\n`);
|
|
37
|
+
continue;
|
|
49
38
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const merger = mergician({ appendArrays: true });
|
|
55
|
-
if (target === '$') {
|
|
56
|
-
// You can't actually merge an update on a root object
|
|
57
|
-
// target with the jsonpath lib, this is just us merging
|
|
58
|
-
// the given update with the whole spec.
|
|
59
|
-
spec = merger(spec, action.update);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
jsonpath.apply(spec, target, (chunk) => {
|
|
63
|
-
if (typeof chunk === 'object' && typeof action.update === 'object') {
|
|
64
|
-
if (Array.isArray(chunk) && Array.isArray(action.update)) {
|
|
65
|
-
return [...chunk, ...action.update];
|
|
66
|
-
}
|
|
67
|
-
return merger(chunk, action.update);
|
|
68
|
-
}
|
|
69
|
-
return action.update;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
process.stderr.write(`Error applying overlay: ${error.message}\n`);
|
|
75
|
-
// return chunk
|
|
76
|
-
}
|
|
39
|
+
for (const path of paths) {
|
|
40
|
+
// The 'executeAction' will mutate the passed spec object in
|
|
41
|
+
// place.
|
|
42
|
+
this.executeAction(spec, action, path);
|
|
77
43
|
}
|
|
78
44
|
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
process.stderr.write('WARNING: No actions found in your overlay\n');
|
|
48
|
+
}
|
|
79
49
|
return spec;
|
|
80
50
|
}
|
|
51
|
+
/* Mutates the given 'spec' object with the 'action' given and
|
|
52
|
+
* targeting a unique 'pat ' within the spec object. We don't check
|
|
53
|
+
* if the path is valid in the object as this is the role of the
|
|
54
|
+
* jsonpathly lib which we used previously to extract the target
|
|
55
|
+
* paths. */
|
|
56
|
+
executeAction(spec, action, path) {
|
|
57
|
+
const explodedPath = path.split(/(?:]\[|\$\[)+/);
|
|
58
|
+
// Remove root
|
|
59
|
+
explodedPath.shift();
|
|
60
|
+
// Take last element from path (which is the thing to act
|
|
61
|
+
// upon)
|
|
62
|
+
let thingToActUpon = explodedPath.pop();
|
|
63
|
+
// The last element (e.g. '"price"]' or '0]') contains a final ']'
|
|
64
|
+
// so we need to remove it AND we need to parse the element to
|
|
65
|
+
// transform the string in either a string or a number
|
|
66
|
+
thingToActUpon =
|
|
67
|
+
thingToActUpon === undefined ? '$' : (thingToActUpon = JSON.parse(thingToActUpon.slice(0, -1)));
|
|
68
|
+
// Reconstruct the stringified path expression targeting the parent
|
|
69
|
+
const parentPath = explodedPath.join('][');
|
|
70
|
+
const parent = parentPath.length > 0 ? jsonpath.query(spec, `$[${parentPath}]`) : spec;
|
|
71
|
+
// Do the overlay action
|
|
72
|
+
// Is it a remove?
|
|
73
|
+
if (Object.hasOwn(action, 'remove')) {
|
|
74
|
+
this.remove(parent, thingToActUpon);
|
|
75
|
+
}
|
|
76
|
+
else if (Object.hasOwn(action, 'update')) {
|
|
77
|
+
this.update(spec, parent, action.update, thingToActUpon);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
process.stderr.write(`WARNING: ${this.humanName(action)} needs either a 'remove' or an 'update' property\n`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
humanName(action) {
|
|
84
|
+
return action.description ? `Action '${action.description}'` : 'Action';
|
|
85
|
+
}
|
|
86
|
+
remove(parent, property_or_index) {
|
|
87
|
+
if (Array.isArray(parent)) {
|
|
88
|
+
parent.splice(property_or_index, 1);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
delete parent[property_or_index];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
update(spec, parent, update, property_or_index) {
|
|
95
|
+
try {
|
|
96
|
+
// Deep merge objects using a module (built-in spread operator is only shallow)
|
|
97
|
+
const merger = mergician({ appendArrays: true });
|
|
98
|
+
if (property_or_index === '$') {
|
|
99
|
+
// You can't actually merge an update on a root object
|
|
100
|
+
// target with the jsonpathly lib, this is just us merging
|
|
101
|
+
// the given update with the whole spec.
|
|
102
|
+
spec = merger(spec, update);
|
|
103
|
+
}
|
|
104
|
+
else if (property_or_index) {
|
|
105
|
+
const targetObject = parent[property_or_index];
|
|
106
|
+
if (typeof targetObject === 'object' && typeof update === 'object') {
|
|
107
|
+
parent[property_or_index] =
|
|
108
|
+
Array.isArray(targetObject) && Array.isArray(update)
|
|
109
|
+
? [...targetObject, ...update]
|
|
110
|
+
: merger(targetObject, update);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
parent[property_or_index] = update;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
process.stderr.write(`Error applying overlay: ${error.message}\n`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
81
121
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bump-cli",
|
|
3
3
|
"description": "The Bump CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.3",
|
|
5
5
|
"author": "Paul Bonaud <paulr@bump.sh>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"bump": "./bin/run.js"
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
},
|
|
74
74
|
"repository": "bump-sh/cli",
|
|
75
75
|
"scripts": {
|
|
76
|
-
"prepare": "npm run build",
|
|
77
76
|
"build": "shx rm -rf dist && tsc -b",
|
|
78
77
|
"clean": "rm -rf dist/ oclif.manifest.json",
|
|
79
78
|
"lint": "eslint . --ext .ts",
|
|
@@ -93,7 +92,7 @@
|
|
|
93
92
|
"dependencies": {
|
|
94
93
|
"@apidevtools/json-schema-ref-parser": "^11.7.2",
|
|
95
94
|
"@asyncapi/specs": "^6.8.0",
|
|
96
|
-
"@clack/prompts": "^0.
|
|
95
|
+
"@clack/prompts": "^0.10.0",
|
|
97
96
|
"@oclif/core": "^4",
|
|
98
97
|
"@oclif/plugin-help": "^6",
|
|
99
98
|
"@oclif/plugin-warn-if-update-available": "^3.1.20",
|
|
@@ -102,7 +101,7 @@
|
|
|
102
101
|
"axios": "^1.7.7",
|
|
103
102
|
"chalk": "^5.3.0",
|
|
104
103
|
"debug": "^4.3.7",
|
|
105
|
-
"
|
|
104
|
+
"jsonpathly": "^2.0.2",
|
|
106
105
|
"mergician": "^2.0.2",
|
|
107
106
|
"oas-schemas": "git+https://git@github.com/OAI/OpenAPI-Specification.git#882d1caedb0bff825a1fd10728e7e3dc43912d37",
|
|
108
107
|
"open": "^10.1.0"
|