bump-cli 0.2.1 → 0.4.1

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: d5169670a252b09da084e26e8d2b8278edd15d9e904f123983f68649c5ead88f
4
- data.tar.gz: 186066a217405dbdef02f5f95c05954925220b400aaa1b2ba8320366b5d807d3
3
+ metadata.gz: 037f50e1dc85f791e29b7d04610c536d5c5de55465129218036508f7dc9b4f23
4
+ data.tar.gz: a88fcc165c82445b31447194f4156479793294519327b7a37e0f253a532043d3
5
5
  SHA512:
6
- metadata.gz: 358db0967d78738d45711ad7628c2b407f565b3032e526704e7919c47916774686c02dd093d857a6d3ffc8ed2829905fdb739b7a50627f0f04f37a95fe5446ec
7
- data.tar.gz: aedba4f9f17a31bdbf2cfb85a6d297fe7b4ecb9924559c815e74262fb08aea0a07766d869b9ab3d54a0eec6b2f85f431aeec58822c20ce89ffad52c3e40abc0d
6
+ metadata.gz: 62985d280a33db74d42a6afafde570231aca07a18fbae7a492756352f9315ea38b7fc7fa97b188d0dd2823d65a82e6cc8b639449b1064746f831d7c3de1a5e2f
7
+ data.tar.gz: 6179fc9f2b65c33c4416f869a1c7c1e41b825d81a1e77533bb3d84e6a319f870c79ffbd45b5ac53b4d4a9f54fd23d841959fd40f83cac77457124dd82defa438
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
 
@@ -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,12 +4,21 @@ 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
 
9
- def body(file, specification)
11
+ def post(url:, body:, token: nil)
12
+ HTTP
13
+ .headers(headers(token: token))
14
+ .post(url, body: body)
15
+ end
16
+
17
+ def body(file, specification, validation)
10
18
  {
11
19
  definition: open(file).read,
12
- specification: specification
20
+ specification: specification,
21
+ validation: validation
13
22
  }
14
23
  end
15
24
 
@@ -20,22 +29,22 @@ module Bump
20
29
  end
21
30
 
22
31
  def headers(token: '')
32
+ headers = {
33
+ 'Content-Type' => 'application/json',
34
+ 'User-Agent' => USER_AGENT
35
+ }
36
+
23
37
  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
- }
38
+ headers['Authorization'] = "Basic #{Base64.strict_encode64(token + ':')}"
32
39
  end
40
+
41
+ headers
33
42
  end
34
43
 
35
44
  def display_error(response)
36
45
  if response.code == 422
37
46
  body = JSON.parse(response.body)
38
- display_invalid_definition(body)
47
+ display_validation_errors(body)
39
48
  elsif response.code == 401
40
49
  abort "Invalid credentials (status: 401)"
41
50
  else
@@ -46,13 +55,30 @@ module Bump
46
55
  abort "Unknown error (status: #{response.code})"
47
56
  end
48
57
 
49
- def display_invalid_definition(body)
50
- puts "Definition is not valid:"
51
- body["errors"]["raw_definition"].each do |error|
52
- puts "> #{error}"
58
+ def display_validation_errors(body)
59
+ errors = body.dig('errors') || []
60
+
61
+ $stderr.puts "Invalid request:"
62
+ errors.each do |attribute, messages|
63
+ display_attribute_errors(attribute, messages)
53
64
  end
65
+
54
66
  abort
55
67
  end
68
+
69
+ def display_attribute_errors(attribute, messages)
70
+ case
71
+ when messages.is_a?(String)
72
+ $stderr.puts "- #{attribute}: #{messages}"
73
+ when messages.is_a?(Array) && messages.count == 1
74
+ $stderr.puts "- #{attribute}: #{messages[0]}"
75
+ when messages.is_a?(Array)
76
+ $stderr.puts "- #{attribute}:"
77
+ messages.each do |message|
78
+ $stderr.puts " #{message}"
79
+ end
80
+ end
81
+ end
56
82
  end
57
83
  end
58
84
  end
@@ -5,16 +5,19 @@ 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', desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
12
13
 
13
- def call(file:, specification:, id:, token:)
14
+ def call(file:, id:, token:, validation:, specification: nil)
14
15
  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)
16
+ response = post(
17
+ url: API_URL + "/docs/#{id}/versions",
18
+ body: body(file, specification, validation).to_json,
19
+ token: token
20
+ )
18
21
 
19
22
  if response.code == 201
20
23
  puts "New version has been successfully deployed."
@@ -3,14 +3,16 @@ 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', 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
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
8
9
 
9
- def call(file:, specification:)
10
+ def call(file:, validation:, specification: nil)
10
11
  with_errors_rescued do
11
- response = HTTP
12
- .headers(headers)
13
- .post(API_URL + "/previews", body: body(file, specification).to_json)
12
+ response = post(
13
+ url: API_URL + "/previews",
14
+ body: body(file, specification, validation).to_json
15
+ )
14
16
 
15
17
  if response.code == 201
16
18
  body = JSON.parse(response.body)
@@ -5,16 +5,19 @@ 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', desc: "Specification of the definition"
11
+ option :specification, desc: "Specification of the definition"
12
+ option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
12
13
 
13
- def call(file:, specification:, id:, token:)
14
+ def call(file:, id:, token:, validation:, specification: nil)
14
15
  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)
16
+ response = post(
17
+ url: API_URL + "/docs/#{id}/validations",
18
+ body: body(file, specification, validation).to_json,
19
+ token: token
20
+ )
18
21
 
19
22
  if response.code == 200
20
23
  puts "Definition is valid."
@@ -1,5 +1,5 @@
1
1
  module Bump
2
2
  class CLI
3
- VERSION = "0.2.1"
3
+ VERSION = "0.4.1"
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.1
4
+ version: 0.4.1
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-08-16 00:00:00.000000000 Z
12
+ date: 2020-02-11 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