bump-cli 0.2.0 → 0.4.0

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: eae58f754a98f3e2e633376bee6bd7dd3be44fc00e4f8c5d0a7d1b9f88e19236
4
- data.tar.gz: bde4b9c983ef8dbccca2432526c86ab4417b1deef95994d2aff0412f009ee08f
3
+ metadata.gz: 00a05336bed7f3a4f81e5b59a102950d067acb25cfe6d4bbdb057c0bf83f2265
4
+ data.tar.gz: 2f08c89b6ec3fbad5a85e1325309cf85da94cd7ded892ae06615c440c4623df5
5
5
  SHA512:
6
- metadata.gz: e0f74113804392d5f473e882b091567ce84cd2d09a9f980b35e2e9770170475d8856c667ec52926d2ff787e469f51fcb362dc1dd9414cee5e4ad14f49d916315
7
- data.tar.gz: f241dfd78599b68123d1146546cc338f73c447db28aeb2247701bde03fe87bc7216af00b0ba5101ec021fd192e1dd1166b0cb597c3fef51bf8c72a54aa8d3ff7
6
+ metadata.gz: c4686dc55a271061d849af7a4aa778c7e6f4a93a3c7bfd38667f0f72dab7dc137e050aa73fe3ba1062c838193accc0613bbc5452ab55e949bf85a99aa8258b60
7
+ data.tar.gz: 34c42d4756f1dc1199af1a16d706298f07f8dc01723988322f58131d4312b8ffd624b25464152e294a999f870f9bea7499aa19f494b72f957fde9c098f41f857
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .byebug_history
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
data/README.md CHANGED
@@ -20,27 +20,34 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- By default, `bump-cli` considers files as `yaml` ones. If you work with JSON definitions, you need to specify the format for all the commands using `--format json`.
23
+ Bump tries to identify your file specification and format automatically. You can force it by using the `--specification` option. Here are the supported values:
24
24
 
25
- The doc `id` and `token` used below can be found in your documentation settings page on https://bump.sh. Note that you can replace the options by environments variables: `--id` can be replaced by `BUMP_ID`, and `--token` can by replaced by `BUMP_TOKEN`. This is useful to keep your private token secret.
25
+ * `openapi/v2/json`
26
+ * `openapi/v2/yaml`
27
+ * `openapi/v3/json`
28
+ * `openapi/v3/yaml`
29
+ * `asyncapi/v2/json`
30
+ * `asyncapi/v2/yaml`
31
+
32
+ The doc `id` and `token` options used below can be found in your documentation settings page on https://bump.sh. Note that you can replace these options by environments variables: `--id` can be replaced by `BUMP_ID`, and `--token` can by replaced by `BUMP_TOKEN`. This is useful to keep your private token secret.
26
33
 
27
34
  ### Preview
28
35
 
29
36
  You can preview your documentation by calling the `preview` command. A temporary preview will be created, with a unique URL. This preview will be available for 30 minutes. You don't need any credentials to use this command.
30
37
 
31
- $ bundle exec bump preview path/to/your/openapi.yml
38
+ $ bundle exec bump preview path/to/your/file.yml
32
39
 
33
40
  ### Validate
34
41
 
35
- Validate your file against the OpenApi specification.
42
+ Validate your file against its specification.
36
43
 
37
- $ bundle exec bump validate path/to/your/openapi.yml --id DOC_ID --token DOC_TOKEN
44
+ $ bundle exec bump validate path/to/your/file.yml --id DOC_ID --token DOC_TOKEN
38
45
 
39
46
  ### Deploy
40
47
 
41
48
  Deploy the file as the current version of the documentation.
42
49
 
43
- $ bundle exec bump deploy path/to/your/openapi.yml --id DOC_ID --token DOC_TOKEN
50
+ $ bundle exec bump deploy path/to/your/file.yml --id DOC_ID --token DOC_TOKEN
44
51
 
45
52
  ## Development
46
53
 
data/bump-cli.gemspec CHANGED
@@ -27,11 +27,12 @@ Gem::Specification.new do |spec|
27
27
  spec.required_ruby_version = '>= 2.3'
28
28
 
29
29
  spec.add_dependency "hanami-cli", '~> 0'
30
- spec.add_dependency "http", '~> 3'
30
+ spec.add_dependency "http", '>= 3'
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1.15"
32
+ spec.add_development_dependency "bundler", "~> 1"
33
+ spec.add_development_dependency "byebug", "~> 11"
33
34
  spec.add_development_dependency "climate_control", '~> 0'
34
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rake", "~> 13"
35
36
  spec.add_development_dependency "rspec", "~> 3"
36
37
  spec.add_development_dependency "webmock", "~> 3"
37
38
  end
@@ -4,8 +4,16 @@ module Bump
4
4
  class CLI
5
5
  module Commands
6
6
  class Base < Hanami::CLI::Command
7
+ USER_AGENT = "bump-cli/#{VERSION}".freeze
8
+
7
9
  private
8
10
 
11
+ def post(url:, body:, token: nil)
12
+ HTTP
13
+ .headers(headers(token: token))
14
+ .post(url, body: body)
15
+ end
16
+
9
17
  def body(file, specification)
10
18
  {
11
19
  definition: open(file).read,
@@ -20,22 +28,22 @@ module Bump
20
28
  end
21
29
 
22
30
  def headers(token: '')
31
+ headers = {
32
+ 'Content-Type' => 'application/json',
33
+ 'User-Agent' => USER_AGENT
34
+ }
35
+
23
36
  if token
24
- {
25
- "Content-Type" => "application/json",
26
- "Authorization" => "Basic #{Base64.strict_encode64(token + ':')}"
27
- }
28
- else
29
- {
30
- "Content-Type" => "application/json"
31
- }
37
+ headers['Authorization'] = "Basic #{Base64.strict_encode64(token + ':')}"
32
38
  end
39
+
40
+ headers
33
41
  end
34
42
 
35
43
  def display_error(response)
36
44
  if response.code == 422
37
45
  body = JSON.parse(response.body)
38
- display_invalid_definition(body)
46
+ display_validation_errors(body)
39
47
  elsif response.code == 401
40
48
  abort "Invalid credentials (status: 401)"
41
49
  else
@@ -46,13 +54,30 @@ module Bump
46
54
  abort "Unknown error (status: #{response.code})"
47
55
  end
48
56
 
49
- def display_invalid_definition(body)
50
- puts "Definition is not valid:"
51
- body["errors"]["raw_definition"].each do |error|
52
- puts "> #{error}"
57
+ def display_validation_errors(body)
58
+ errors = body.dig('errors') || []
59
+
60
+ $stderr.puts "Invalid request:"
61
+ errors.each do |attribute, messages|
62
+ display_attribute_errors(attribute, messages)
53
63
  end
64
+
54
65
  abort
55
66
  end
67
+
68
+ def display_attribute_errors(attribute, messages)
69
+ case
70
+ when messages.is_a?(String)
71
+ $stderr.puts "- #{attribute}: #{messages}"
72
+ when messages.is_a?(Array) && messages.count == 1
73
+ $stderr.puts "- #{attribute}: #{messages[0]}"
74
+ when messages.is_a?(Array)
75
+ $stderr.puts "- #{attribute}:"
76
+ messages.each do |message|
77
+ $stderr.puts " #{message}"
78
+ end
79
+ end
80
+ end
56
81
  end
57
82
  end
58
83
  end
@@ -5,16 +5,18 @@ module Bump
5
5
  module Commands
6
6
  class Deploy < Base
7
7
  desc "Create a new version"
8
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
8
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
9
  option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
10
  option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
11
- option :specification, default: 'openapi/v2/yaml', values: %w[openapi/v2/json openapi/v2/yaml], desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
12
 
13
- def call(file:, specification:, id:, token:)
13
+ def call(file:, id:, token:, specification: nil)
14
14
  with_errors_rescued do
15
- response = HTTP
16
- .headers(headers(token: token))
17
- .post(API_URL + "/docs/#{id}/versions", body: body(file, specification).to_json)
15
+ response = post(
16
+ url: API_URL + "/docs/#{id}/versions",
17
+ body: body(file, specification).to_json,
18
+ token: token
19
+ )
18
20
 
19
21
  if response.code == 201
20
22
  puts "New version has been successfully deployed."
@@ -3,14 +3,15 @@ module Bump
3
3
  module Commands
4
4
  class Preview < Base
5
5
  desc "Create a documentation preview for the given file"
6
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
7
- option :specification, default: 'openapi/v2/yaml', values: %w[openapi/v2/json openapi/v2/yaml], desc: "Specification of the definition"
6
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
7
+ option :specification, desc: "Specification of the definition"
8
8
 
9
- def call(file:, specification:)
9
+ def call(file:, specification: nil)
10
10
  with_errors_rescued do
11
- response = HTTP
12
- .headers(headers)
13
- .post(API_URL + "/previews", body: body(file, specification).to_json)
11
+ response = post(
12
+ url: API_URL + "/previews",
13
+ body: body(file, specification).to_json
14
+ )
14
15
 
15
16
  if response.code == 201
16
17
  body = JSON.parse(response.body)
@@ -5,16 +5,18 @@ module Bump
5
5
  module Commands
6
6
  class Validate < Base
7
7
  desc "Validate a given file against its schema definition"
8
- argument :file, required: true, desc: "Path or URL to your API documentation file. Only OpenApi 2.0 (Swagger) specification is currently supported."
8
+ argument :file, required: true, desc: "Path or URL to your API documentation file. OpenAPI (2.0 to 3.0.2) and AsyncAPI (2.0) specifications are currently supported."
9
9
  option :id, default: ENV.fetch("BUMP_ID", ""), desc: "Documentation public id"
10
10
  option :token, default: ENV.fetch("BUMP_TOKEN", ""), desc: "Documentation private token"
11
- option :specification, default: 'openapi/v2/yaml', values: %w[openapi/v2/json openapi/v2/yaml], desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
12
 
13
- def call(file:, specification:, id:, token:)
13
+ def call(file:, id:, token:, specification: nil)
14
14
  with_errors_rescued do
15
- response = HTTP
16
- .headers(headers(token: token))
17
- .post(API_URL + "/docs/#{id}/validations", body: body(file, specification).to_json)
15
+ response = post(
16
+ url: API_URL + "/docs/#{id}/validations",
17
+ body: body(file, specification).to_json,
18
+ token: token
19
+ )
18
20
 
19
21
  if response.code == 200
20
22
  puts "Definition is valid."
@@ -1,5 +1,5 @@
1
1
  module Bump
2
2
  class CLI
3
- VERSION = "0.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bump-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehdi Lahmam
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-03-27 00:00:00.000000000 Z
12
+ date: 2019-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hanami-cli
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: http
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '3'
42
42
  - !ruby/object:Gem::Dependency
@@ -45,14 +45,28 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.15'
48
+ version: '1'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: byebug
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '11'
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - "~>"
54
68
  - !ruby/object:Gem::Version
55
- version: '1.15'
69
+ version: '11'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: climate_control
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +87,14 @@ dependencies:
73
87
  requirements:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '10.0'
90
+ version: '13'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '10.0'
97
+ version: '13'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: rspec
86
100
  requirement: !ruby/object:Gem::Requirement