bump-cli 0.5.1 → 0.6.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 +4 -4
- data/lib/bump/cli/commands/base.rb +9 -5
- data/lib/bump/cli/commands/deploy.rb +1 -0
- data/lib/bump/cli/commands/preview.rb +1 -0
- data/lib/bump/cli/commands/validate.rb +1 -0
- data/lib/bump/cli/definition.rb +43 -0
- data/lib/bump/cli/parser.rb +24 -0
- data/lib/bump/cli/references.rb +88 -0
- data/lib/bump/cli/uuid.rb +11 -0
- data/lib/bump/cli/version.rb +1 -1
- metadata +6 -3
- data/lib/bump/cli/tools/uuid.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a76424c2ad6eed8a8b65caa28e57e26c7efb892b8909a9e6aed60871b9964105
|
4
|
+
data.tar.gz: 4f597a0961e36cfb2108409198a11abae798333b49fadf298fbd0f7b332c529a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda499aed9b3edfb4600ccd8ede77a65dd6bd98403937f29b714c557e8fb5457f8258d49d55ab5968499c5e10ff67b6a0cd446d3304a5b0ea69afeab20f0e47d
|
7
|
+
data.tar.gz: 2fa948728d09d134b552954d12d2f64d3141bf5c0422ffdd95ec853afed861aed0440c4c6a3ff5378025f5788d1ceb535e04c37a12e8b4180441d35b850b499c
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'bump/cli/
|
1
|
+
require 'bump/cli/definition'
|
2
|
+
require 'bump/cli/uuid'
|
3
3
|
|
4
4
|
module Bump
|
5
5
|
class CLI
|
@@ -20,7 +20,7 @@ module Bump
|
|
20
20
|
|
21
21
|
compact(
|
22
22
|
{
|
23
|
-
definition:
|
23
|
+
definition: prepare_file(file, options),
|
24
24
|
specification: options[:specification],
|
25
25
|
validation: options[:validation],
|
26
26
|
auto_create_documentation: options[:'auto-create']
|
@@ -28,6 +28,10 @@ module Bump
|
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
|
+
def prepare_file(file, options)
|
32
|
+
Definition.new(file, import_external_references: options[:'import-external-references']).prepare
|
33
|
+
end
|
34
|
+
|
31
35
|
def deprecation_warning(options)
|
32
36
|
if present?(options[:id])
|
33
37
|
puts "[DEPRECATION WARNING] --id option is deprecated. Please use --doc instead."
|
@@ -56,7 +60,7 @@ module Bump
|
|
56
60
|
end
|
57
61
|
|
58
62
|
def documentation_uuid?(options)
|
59
|
-
Bump::CLI::
|
63
|
+
Bump::CLI::UUID.valid?(options[:doc])
|
60
64
|
end
|
61
65
|
|
62
66
|
def documentation_slug?(options)
|
@@ -64,7 +68,7 @@ module Bump
|
|
64
68
|
end
|
65
69
|
|
66
70
|
def hub_uuid?(options)
|
67
|
-
Bump::CLI::
|
71
|
+
Bump::CLI::UUID.valid?(options[:hub])
|
68
72
|
end
|
69
73
|
|
70
74
|
def hub_slug?(options)
|
@@ -14,6 +14,7 @@ module Bump
|
|
14
14
|
option :specification, desc: "Specification of the definition"
|
15
15
|
option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
|
16
16
|
option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
|
17
|
+
option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
|
17
18
|
|
18
19
|
def call(file:, **options)
|
19
20
|
with_errors_rescued do
|
@@ -6,6 +6,7 @@ module Bump
|
|
6
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
7
|
option :specification, desc: "Specification of the definition"
|
8
8
|
option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
|
9
|
+
option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
|
9
10
|
|
10
11
|
def call(file:, **options)
|
11
12
|
with_errors_rescued do
|
@@ -14,6 +14,7 @@ module Bump
|
|
14
14
|
option :specification, desc: "Specification of the definition"
|
15
15
|
option :validation, desc: "Validation mode", values: %w(basic strict), default: 'basic'
|
16
16
|
option :'auto-create', type: :boolean, default: false, desc: 'Automatically create the documentation if needed (only available with a hub and when specifying a slug for documentation)'
|
17
|
+
option :'import-external-references', type: :boolean, default: false, desc: 'Import external $refs (URI or file system) into the specification before sending it to Bump servers'
|
17
18
|
|
18
19
|
def call(file:, **options)
|
19
20
|
with_errors_rescued do
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'bump/cli/parser'
|
3
|
+
require 'bump/cli/references'
|
4
|
+
|
5
|
+
module Bump
|
6
|
+
class CLI
|
7
|
+
class Definition
|
8
|
+
def initialize(path, import_external_references: false)
|
9
|
+
@path = path
|
10
|
+
@import_external_references = import_external_references
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
if !import_external_references
|
15
|
+
read_file
|
16
|
+
else
|
17
|
+
parse_file_and_import_external_references
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :path, :import_external_references
|
24
|
+
|
25
|
+
def read_file
|
26
|
+
open(path).read
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_file_and_import_external_references
|
30
|
+
original_format, definition = parser.load(read_file)
|
31
|
+
|
32
|
+
references = References.new(definition, base_path: path)
|
33
|
+
references.import!
|
34
|
+
|
35
|
+
parser.dump(references.definition, original_format)
|
36
|
+
end
|
37
|
+
|
38
|
+
def parser
|
39
|
+
@parser ||= Parser.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Bump
|
5
|
+
class CLI
|
6
|
+
class Parser
|
7
|
+
def load(content)
|
8
|
+
[:json, ::JSON.parse(content)]
|
9
|
+
rescue ::JSON::ParserError => e
|
10
|
+
[:yaml, ::YAML.safe_load(content, [Date, Time])]
|
11
|
+
rescue ::Psych::SyntaxError
|
12
|
+
raise 'Invalid format: definition file should be valid YAML or JSON'
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump(definition, format)
|
16
|
+
if format == :yaml
|
17
|
+
::YAML.dump(definition)
|
18
|
+
else
|
19
|
+
::JSON.dump(definition)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Bump
|
5
|
+
class CLI
|
6
|
+
class References
|
7
|
+
attr_reader :definition
|
8
|
+
|
9
|
+
def initialize(definition, base_path: '')
|
10
|
+
@definition = definition
|
11
|
+
@base_path = cleanup(base_path)
|
12
|
+
@processed = false
|
13
|
+
@external_references = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def import!
|
17
|
+
if !processed
|
18
|
+
@definition = traverse_and_replace_external_references(definition)
|
19
|
+
import_references
|
20
|
+
@processed = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :base_path, :processed, :external_references
|
27
|
+
|
28
|
+
def traverse_and_replace_external_references(current, parent = nil)
|
29
|
+
current.each do |key, value|
|
30
|
+
if key == '$ref'
|
31
|
+
current[key] = replace_external_reference(value)
|
32
|
+
elsif value.is_a?(Hash)
|
33
|
+
traverse_and_replace_external_references(value, key)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def replace_external_reference(reference)
|
39
|
+
if external?(reference)
|
40
|
+
if external_references[reference].nil?
|
41
|
+
@external_references[reference] = "#{external_references.count + 1}"
|
42
|
+
end
|
43
|
+
|
44
|
+
subpath = reference[/#(.*)$/, 1]
|
45
|
+
"#/components/x-imported/#{external_references[reference]}#{ '/' + subpath if !subpath.nil? }"
|
46
|
+
else
|
47
|
+
reference
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def import_references
|
52
|
+
if external_references.count > 0
|
53
|
+
@definition['components'] = {} if @definition['components'].nil?
|
54
|
+
@definition['components']['x-imported'] = {} if @definition['components']['x-imported'].nil?
|
55
|
+
|
56
|
+
external_references.each do |key, value|
|
57
|
+
_, @definition['components']['x-imported'][value.to_s] = Parser.new.load(open(prepare_path(key)).read)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def prepare_path(key)
|
63
|
+
key = key.sub(/#.*/, '')
|
64
|
+
if url?(key) || absolute_path?(key)
|
65
|
+
key
|
66
|
+
else
|
67
|
+
base_path + key
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def external?(reference)
|
72
|
+
!reference.start_with?('#')
|
73
|
+
end
|
74
|
+
|
75
|
+
def url?(path)
|
76
|
+
path.start_with?('http')
|
77
|
+
end
|
78
|
+
|
79
|
+
def absolute_path?(path)
|
80
|
+
path.start_with?('/')
|
81
|
+
end
|
82
|
+
|
83
|
+
def cleanup(path)
|
84
|
+
Pathname.new(path).dirname.to_s + Pathname::SEPARATOR_LIST
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/bump/cli/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.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: 2020-
|
12
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-cli
|
@@ -155,7 +155,10 @@ files:
|
|
155
155
|
- lib/bump/cli/commands/deploy.rb
|
156
156
|
- lib/bump/cli/commands/preview.rb
|
157
157
|
- lib/bump/cli/commands/validate.rb
|
158
|
-
- lib/bump/cli/
|
158
|
+
- lib/bump/cli/definition.rb
|
159
|
+
- lib/bump/cli/parser.rb
|
160
|
+
- lib/bump/cli/references.rb
|
161
|
+
- lib/bump/cli/uuid.rb
|
159
162
|
- lib/bump/cli/version.rb
|
160
163
|
homepage: https://bump.sh
|
161
164
|
licenses:
|