oas_contrib 0.2.5 → 0.2.6
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/.rspec_status +10 -10
- data/README.md +5 -5
- data/lib/oas_contrib/command.rb +15 -0
- data/lib/oas_contrib/interface/resolver.rb +9 -0
- data/lib/oas_contrib/interface/spec.rb +3 -0
- data/lib/oas_contrib/openapi/base.rb +5 -0
- data/lib/oas_contrib/openapi/v2/spec.rb +17 -1
- data/lib/oas_contrib/openapi/v3/spec.rb +17 -1
- data/lib/oas_contrib/resolver/base.rb +50 -5
- data/lib/oas_contrib/resolver/divide.rb +31 -4
- data/lib/oas_contrib/resolver/merge.rb +17 -3
- data/lib/oas_contrib/resolver/preview.rb +10 -0
- data/lib/oas_contrib/version.rb +2 -1
- data/lib/oas_contrib.rb +1 -0
- 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: 0435eddeadb5b43491f1df9287f23fa12049571c24e710031046f9536b5d9450
|
4
|
+
data.tar.gz: aca0d184bd5c17d8b34d11078e78cd8cd60f62e5403985eb864d38300092eb67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8067d5c55797756b8f4978306b907b7fa24e9960a8f05d2e6e140affaa41fa006eac5996d2084d0885acf737de2392db297ff134063ed8d28e7e727ffd2c0fdb
|
7
|
+
data.tar.gz: 6e39a195a3f0ef8e4eab7bf1ab11051c61e9d4150af76a9c2a2ad0dc7713a87747c5e54786c7cd4b8a7eb13a578fc5e97f06198c4b26c180e257157346425309
|
data/.rspec_status
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
------------------------------------ | ------ | --------------- |
|
3
|
-
./spec/divide_command_spec.rb[1:1:1] | passed | 0.
|
4
|
-
./spec/divide_command_spec.rb[1:2:1] | passed | 0.
|
5
|
-
./spec/divide_command_spec.rb[1:3:1] | passed | 0.
|
6
|
-
./spec/divide_command_spec.rb[1:4:1] | passed | 0.
|
7
|
-
./spec/divide_command_spec.rb[1:5:1] | passed | 0.
|
8
|
-
./spec/merge_command_spec.rb[1:1:1] | passed | 0.
|
9
|
-
./spec/merge_command_spec.rb[1:2:1] | passed | 0.
|
10
|
-
./spec/merge_command_spec.rb[1:3:1] | passed | 0.
|
11
|
-
./spec/merge_command_spec.rb[1:4:1] | passed | 0.
|
12
|
-
./spec/merge_command_spec.rb[1:5:1] | passed | 0.
|
3
|
+
./spec/divide_command_spec.rb[1:1:1] | passed | 0.37097 seconds |
|
4
|
+
./spec/divide_command_spec.rb[1:2:1] | passed | 0.34114 seconds |
|
5
|
+
./spec/divide_command_spec.rb[1:3:1] | passed | 0.33399 seconds |
|
6
|
+
./spec/divide_command_spec.rb[1:4:1] | passed | 0.33446 seconds |
|
7
|
+
./spec/divide_command_spec.rb[1:5:1] | passed | 0.39866 seconds |
|
8
|
+
./spec/merge_command_spec.rb[1:1:1] | passed | 0.34996 seconds |
|
9
|
+
./spec/merge_command_spec.rb[1:2:1] | passed | 0.33477 seconds |
|
10
|
+
./spec/merge_command_spec.rb[1:3:1] | passed | 0.39575 seconds |
|
11
|
+
./spec/merge_command_spec.rb[1:4:1] | passed | 0.46906 seconds |
|
12
|
+
./spec/merge_command_spec.rb[1:5:1] | passed | 0.42331 seconds |
|
data/README.md
CHANGED
@@ -14,11 +14,11 @@ gem 'oas_contrib'
|
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
bundle
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
|
21
|
+
gem install oas_contrib
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
@@ -30,7 +30,7 @@ Or install it yourself as:
|
|
30
30
|
### Divide the OpenAPI Specification file
|
31
31
|
|
32
32
|
```bash
|
33
|
-
|
33
|
+
oas_contrib divide <OpenAPI Specification file> <output_dir> (<options>...)
|
34
34
|
```
|
35
35
|
|
36
36
|
| option | description | value type | default |
|
@@ -40,7 +40,7 @@ $ oas_contrib divide <OpenAPI Specification file> <output_dir> (<options>...)
|
|
40
40
|
### Merge from divided files to an OpenAPI Specification file
|
41
41
|
|
42
42
|
```bash
|
43
|
-
|
43
|
+
oas_contrib merge <input_dir> <OpenAPI Specification file> (<options>...)
|
44
44
|
```
|
45
45
|
|
46
46
|
| option | description | value type | default |
|
@@ -50,7 +50,7 @@ $ oas_contrib merge <input_dir> <OpenAPI Specification file> (<options>...)
|
|
50
50
|
### Preview the OpenAPI Specification file using Swagger-UI docker image
|
51
51
|
|
52
52
|
```bash
|
53
|
-
|
53
|
+
oas_contrib preview <OpenAPI Specification file> (<options>...)
|
54
54
|
```
|
55
55
|
|
56
56
|
| option | description | value type | default |
|
data/lib/oas_contrib/command.rb
CHANGED
@@ -4,12 +4,17 @@ require 'oas_contrib/resolver/merge'
|
|
4
4
|
require 'oas_contrib/resolver/preview'
|
5
5
|
|
6
6
|
module OasContrib
|
7
|
+
# Command class
|
7
8
|
class Command < Thor
|
8
9
|
include Thor::Actions
|
9
10
|
|
10
11
|
desc 'divide <spec_file> <output_dir> (<options>)', 'Divide the spec_file into path units and schema units.'
|
11
12
|
option :out_ext, type: :string, default: '.yml', desc: 'output file ext (.yml or .json)'
|
12
13
|
|
14
|
+
# Divide the spec file command
|
15
|
+
# @param [String] spec_file spec file path
|
16
|
+
# @param [String] outdir output directory path
|
17
|
+
# @return [Integer] return code
|
13
18
|
def divide(spec_file, outdir)
|
14
19
|
resolver = OasContrib::Resolver::Divide.new(spec_file, outdir, options)
|
15
20
|
resolver.setup
|
@@ -17,11 +22,16 @@ module OasContrib
|
|
17
22
|
resolver.resolve
|
18
23
|
resolver.distribute
|
19
24
|
say 'complete!', :green
|
25
|
+
exit(0)
|
20
26
|
end
|
21
27
|
|
22
28
|
desc 'merge <input_dir> <spec_file> (<options>)', 'Merge multiple divided files into an spec_file.'
|
23
29
|
option :in_ext, type: :string, default: '.yml', desc: 'input file ext (.yml or .json)'
|
24
30
|
|
31
|
+
# Merge divided files to spec file command
|
32
|
+
# @param [String] indir input directory path
|
33
|
+
# @param [String] spec_file spec file path
|
34
|
+
# @return [Integer] return code
|
25
35
|
def merge(indir, spec_file)
|
26
36
|
resolver = OasContrib::Resolver::Merge.new(indir, spec_file, options)
|
27
37
|
resolver.setup
|
@@ -29,16 +39,21 @@ module OasContrib
|
|
29
39
|
resolver.resolve
|
30
40
|
resolver.distribute
|
31
41
|
say 'complete!', :green
|
42
|
+
exit(0)
|
32
43
|
end
|
33
44
|
|
34
45
|
desc 'preview <spec_file> (<options>)', 'Preview the spec_file using Swagger-UI official Docker image.'
|
35
46
|
option :port, type: :numeric, default: 50_010, desc: 'Swagger UI listen port'
|
36
47
|
|
48
|
+
# Preview the spec file with Swagger UI
|
49
|
+
# @param [String] spec_file spec file path
|
50
|
+
# @return [Integer] return code
|
37
51
|
def preview(spec_file)
|
38
52
|
resolver = OasContrib::Resolver::Preview.new(spec_file, options)
|
39
53
|
resolver.setup
|
40
54
|
resolver.distribute
|
41
55
|
say 'complete!', :green
|
56
|
+
exit(0)
|
42
57
|
end
|
43
58
|
end
|
44
59
|
end
|
@@ -1,18 +1,27 @@
|
|
1
1
|
module OasContrib
|
2
2
|
module Interface
|
3
|
+
# Interface of Resolver class
|
3
4
|
module Resolver
|
5
|
+
# Setup the resolver object.
|
6
|
+
# @return [nil]
|
4
7
|
def setup
|
5
8
|
raise NotImplementedError, 'You must be implement "setup" method.'
|
6
9
|
end
|
7
10
|
|
11
|
+
# Load and parse the input file.
|
12
|
+
# @return [nil]
|
8
13
|
def load
|
9
14
|
raise NotImplementedError, 'You must be implement "load" method.'
|
10
15
|
end
|
11
16
|
|
17
|
+
# Judge and generate OpenAPI specification object.
|
18
|
+
# @return [nil]
|
12
19
|
def resolve
|
13
20
|
raise NotImplementedError, 'You must be implement "resolve" method.'
|
14
21
|
end
|
15
22
|
|
23
|
+
# Distribute the command artifacts.
|
24
|
+
# @return [nil]
|
16
25
|
def distribute
|
17
26
|
raise NotImplementedError, 'You must be implement"dist" method.'
|
18
27
|
end
|
@@ -2,11 +2,16 @@ require 'oas_contrib/interface/spec'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module OpenAPI
|
5
|
+
# Basical spec class
|
5
6
|
class Base
|
7
|
+
# @!attribute [r] data
|
8
|
+
# @return [Hash] mapped spec data hash
|
6
9
|
attr_reader :data
|
7
10
|
|
8
11
|
include OasContrib::Interface::Spec
|
9
12
|
|
13
|
+
# Initialize
|
14
|
+
# @param [Hash] data spec data hash
|
10
15
|
def initialize(data)
|
11
16
|
@data = data
|
12
17
|
end
|
@@ -2,14 +2,30 @@ require 'oas_contrib/openapi/base'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module OpenAPI
|
5
|
+
# OpenAPI V2 module
|
5
6
|
module V2
|
7
|
+
# Spec class
|
6
8
|
class Spec < OasContrib::OpenAPI::Base
|
7
|
-
|
9
|
+
# @!attribute [r] meta
|
10
|
+
# @return [Hash] meta part
|
11
|
+
attr_reader :meta
|
8
12
|
|
13
|
+
# @!attribute [r] path
|
14
|
+
# @return [Hash] path part
|
15
|
+
attr_reader :path
|
16
|
+
|
17
|
+
# @!attribute [r] model
|
18
|
+
# @return [Hash] model part
|
19
|
+
attr_reader :model
|
20
|
+
|
21
|
+
# Initialize
|
22
|
+
# @param [Hash] data spec data hash
|
9
23
|
def initialize(data)
|
10
24
|
super
|
11
25
|
end
|
12
26
|
|
27
|
+
# Mapping the hash to the spec object.
|
28
|
+
# @return [OpenAPI::V2::Spec] mapped spec data object
|
13
29
|
def mapping
|
14
30
|
@meta = data.select { |v| v != 'paths' && v != 'definitions' } || nil
|
15
31
|
@path = data['paths'] || nil
|
@@ -2,14 +2,30 @@ require 'oas_contrib/openapi/base'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module OpenAPI
|
5
|
+
# OpenAPI V3 module
|
5
6
|
module V3
|
7
|
+
# Spec class
|
6
8
|
class Spec < OasContrib::OpenAPI::Base
|
7
|
-
|
9
|
+
# @!attribute [r] meta
|
10
|
+
# @return [Hash] meta part
|
11
|
+
attr_reader :meta
|
8
12
|
|
13
|
+
# @!attribute [r] path
|
14
|
+
# @return [Hash] path part
|
15
|
+
attr_reader :path
|
16
|
+
|
17
|
+
# @!attribute [r] model
|
18
|
+
# @return [Hash] model part
|
19
|
+
attr_reader :model
|
20
|
+
|
21
|
+
# Initialize
|
22
|
+
# @param [Hash] data spec data hash
|
9
23
|
def initialize(data)
|
10
24
|
super
|
11
25
|
end
|
12
26
|
|
27
|
+
# Mapping the hash to the spec object.
|
28
|
+
# @return [OpenAPI::V3::Spec] mapped spec data object
|
13
29
|
def mapping
|
14
30
|
@meta = data.select { |v| v != 'paths' && v != 'components' } || nil
|
15
31
|
@path = data['paths'] || nil
|
@@ -6,13 +6,32 @@ require 'json'
|
|
6
6
|
|
7
7
|
module OasContrib
|
8
8
|
module Resolver
|
9
|
+
# Basical command resolver class
|
9
10
|
class Base
|
10
|
-
|
11
|
+
# @!attribute [r] data
|
12
|
+
# @return [Hash] parsed input data hash
|
13
|
+
attr_reader :data
|
14
|
+
|
15
|
+
# @!attribute [r] spec
|
16
|
+
# @return [OpenAPI::V3::Spec|OpenAPI::V2::Spec] mapped spec data object
|
17
|
+
attr_reader :spec
|
11
18
|
|
12
19
|
include OasContrib::Interface::Resolver
|
13
20
|
|
21
|
+
# @return [Array] approval file extensions
|
14
22
|
DEFINED_FILE_EXT = ['.json', '.yml'].freeze
|
15
23
|
|
24
|
+
# @return [String] the directory name of meta part files
|
25
|
+
DIR_NAME_META = 'meta'.freeze
|
26
|
+
|
27
|
+
# @return [String] the directory name of path part files
|
28
|
+
DIR_NAME_PATH = 'path'.freeze
|
29
|
+
|
30
|
+
# @return [String] the directory name of model part files
|
31
|
+
DIR_NAME_MODEL = 'model'.freeze
|
32
|
+
|
33
|
+
# Check the file extensions is approved or not.
|
34
|
+
# @return [Boolean]
|
16
35
|
def file_ext_check
|
17
36
|
if @infile_ext && !DEFINED_FILE_EXT.include?(@infile_ext)
|
18
37
|
raise "Undefined input file extension. #{@infile_ext}"
|
@@ -21,16 +40,23 @@ module OasContrib
|
|
21
40
|
if @outfile_ext && !DEFINED_FILE_EXT.include?(@outfile_ext)
|
22
41
|
raise "Undefined output file extension. #{@outfile_ext}"
|
23
42
|
end
|
43
|
+
true
|
24
44
|
end
|
25
45
|
|
46
|
+
# Check the format of input file is OpenAPI v3 specificaion or not.
|
47
|
+
# @return [Boolean]
|
26
48
|
def v3?
|
27
49
|
@data['openapi'] =~ /^3/
|
28
50
|
end
|
29
51
|
|
52
|
+
# Check the format of input file is OpenAPI v2 specificaion or not.
|
53
|
+
# @return [Boolean]
|
30
54
|
def v2?
|
31
55
|
@data['swagger'] =~ /^2/
|
32
56
|
end
|
33
57
|
|
58
|
+
# Judge and generate OpenAPI specification object.
|
59
|
+
# @return [OpenAPI::V3::Spec|OpenAPI::V2::Spec] mapped spec data object
|
34
60
|
def resolve
|
35
61
|
@spec = OasContrib::OpenAPI::V2::Spec.new(@data) if v2?
|
36
62
|
@spec = OasContrib::OpenAPI::V3::Spec.new(@data) if v3?
|
@@ -38,19 +64,31 @@ module OasContrib
|
|
38
64
|
@spec.mapping
|
39
65
|
end
|
40
66
|
|
67
|
+
# Load and parse the input file.
|
68
|
+
# @param [String] path input file path
|
69
|
+
# @return [Hash] parsed input data hash
|
41
70
|
def input(path)
|
42
71
|
@data = _input(path)
|
43
72
|
end
|
44
73
|
|
74
|
+
# Output a new file with mapped spec data hash.
|
75
|
+
# @param [Hash] hash mapped spec data hash
|
76
|
+
# @param [String] path output file path
|
77
|
+
# @return [IO]
|
45
78
|
def output(hash, path)
|
46
79
|
File.open(path, 'w') { |f| _output(hash, f) }
|
47
80
|
end
|
48
81
|
|
82
|
+
# Load and parse the files in target directory recursive.
|
83
|
+
# @param [String] dir input directory path
|
84
|
+
# @return [Hash] parsed input data hash
|
49
85
|
def input_dir(dir)
|
50
86
|
path = dir + '/**/*' + @infile_ext
|
51
87
|
Dir.glob(path).sort.each_with_object({}, &input_lambda)
|
52
88
|
end
|
53
89
|
|
90
|
+
# Load and parse the file proc.
|
91
|
+
# @return [Proc]
|
54
92
|
def input_lambda
|
55
93
|
lambda do |file, result|
|
56
94
|
hash = _input(file)
|
@@ -61,20 +99,27 @@ module OasContrib
|
|
61
99
|
|
62
100
|
private
|
63
101
|
|
102
|
+
# Load and prase the file depending on the file extension.
|
103
|
+
# @param [String] path input file path
|
104
|
+
# @return [Hash] parsed input data hash
|
64
105
|
def _input(path)
|
65
106
|
puts "Load: #{path}"
|
66
107
|
case @infile_ext
|
67
|
-
when
|
68
|
-
when
|
108
|
+
when DEFINED_FILE_EXT[0] then JSON.parse(File.read(path))
|
109
|
+
when DEFINED_FILE_EXT[1] then YAML.load_file(path)
|
69
110
|
else raise ArgumentError, 'Undefined input file type'
|
70
111
|
end
|
71
112
|
end
|
72
113
|
|
114
|
+
# Write the spec data hash depending on the file extension.
|
115
|
+
# @param [Hash] hash mapped spec data hash
|
116
|
+
# @param [String] file output file path
|
117
|
+
# @return [IO]
|
73
118
|
def _output(hash, file)
|
74
119
|
puts "Dist: #{file.path}"
|
75
120
|
case @outfile_ext
|
76
|
-
when
|
77
|
-
when
|
121
|
+
when DEFINED_FILE_EXT[0] then JSON.dump(hash, file)
|
122
|
+
when DEFINED_FILE_EXT[1] then YAML.dump(hash, file)
|
78
123
|
else raise ArgumentError, 'Undefined output file type'
|
79
124
|
end
|
80
125
|
end
|
@@ -2,32 +2,50 @@ require 'oas_contrib/resolver/base'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module Resolver
|
5
|
+
# Divide command resolver class
|
5
6
|
class Divide < OasContrib::Resolver::Base
|
7
|
+
# Initialize
|
8
|
+
# @param [String] infile spec file path
|
9
|
+
# @param [String] outdir output directory path
|
10
|
+
# @param [Array] options command options
|
6
11
|
def initialize(infile, outdir, options)
|
7
|
-
@meta_dir = outdir + '/
|
8
|
-
@path_dir = outdir + '/
|
9
|
-
@model_dir = outdir + '/
|
12
|
+
@meta_dir = outdir + '/' + DIR_NAME_META
|
13
|
+
@path_dir = outdir + '/' + DIR_NAME_PATH
|
14
|
+
@model_dir = outdir + '/' + DIR_NAME_MODEL
|
10
15
|
@infile = infile
|
11
16
|
@outfile_ext = options['out_ext']
|
12
17
|
end
|
13
18
|
|
19
|
+
# Setup the resolver object.
|
20
|
+
# @return [Boolean]
|
14
21
|
def setup
|
15
22
|
@infile_ext = File.extname(@infile)
|
16
23
|
file_ext_check
|
24
|
+
true
|
17
25
|
end
|
18
26
|
|
27
|
+
# Load and parse the input file.
|
28
|
+
# @return [Boolean]
|
19
29
|
def load
|
20
30
|
input(@infile)
|
31
|
+
true
|
21
32
|
end
|
22
33
|
|
34
|
+
# Distribute the command artifacts.
|
35
|
+
# @return [Boolean]
|
23
36
|
def distribute
|
24
37
|
output_dir(@spec.meta, @meta_dir)
|
25
38
|
output_dir(@spec.path, @path_dir)
|
26
39
|
output_dir(@spec.model, @model_dir)
|
40
|
+
true
|
27
41
|
end
|
28
42
|
|
29
43
|
private
|
30
44
|
|
45
|
+
# Generate directory and output files.
|
46
|
+
# @param [Hash] hash mapped spec data hash
|
47
|
+
# @param [String] path output directory path
|
48
|
+
# @return [Boolean]
|
31
49
|
def output_dir(hash, path)
|
32
50
|
puts "Dist: #{path}"
|
33
51
|
FileUtils.mkdir_p(path)
|
@@ -36,15 +54,24 @@ module OasContrib
|
|
36
54
|
outfile_data = _output_dir_file_data_filter(hash, k)
|
37
55
|
output(outfile_data, outfile_path)
|
38
56
|
end
|
39
|
-
|
57
|
+
true
|
40
58
|
end
|
41
59
|
|
60
|
+
# Modify the output file path.
|
61
|
+
# @param [String] dir output directory path
|
62
|
+
# @param [String] hash_key hash key
|
63
|
+
# @param [Integer] num count of file
|
64
|
+
# @return [String] modified file path
|
42
65
|
def _output_dir_file_path_modify(dir, hash_key, num)
|
43
66
|
prefix = num.to_s.rjust(3, '0')
|
44
67
|
file_name = hash_key.tr('/', '_').gsub(/^_/, '')
|
45
68
|
dir + '/' + prefix + '_' + file_name + @outfile_ext
|
46
69
|
end
|
47
70
|
|
71
|
+
# Filter the output file data.
|
72
|
+
# @param [Hash] hash mapped spec data hash
|
73
|
+
# @param [String] filter_key filtering hash key
|
74
|
+
# @return [Hash] filterd hash
|
48
75
|
def _output_dir_file_data_filter(hash, filter_key)
|
49
76
|
hash.select { |key, _| key == filter_key }
|
50
77
|
end
|
@@ -2,30 +2,44 @@ require 'oas_contrib/resolver/base'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module Resolver
|
5
|
+
# Merge command resolver class
|
5
6
|
class Merge < OasContrib::Resolver::Base
|
7
|
+
# Initialize
|
8
|
+
# @param [String] indir input directory path
|
9
|
+
# @param [String] outfile output spec file path
|
10
|
+
# @param [Array] options command options
|
6
11
|
def initialize(indir, outfile, options)
|
7
|
-
@meta_dir = indir + '/
|
8
|
-
@path_dir = indir + '/
|
9
|
-
@model_dir = indir + '/
|
12
|
+
@meta_dir = indir + '/' + DIR_NAME_META
|
13
|
+
@path_dir = indir + '/' + DIR_NAME_PATH
|
14
|
+
@model_dir = indir + '/' + DIR_NAME_MODEL
|
10
15
|
@outfile = outfile
|
11
16
|
@infile_ext = options['in_ext']
|
12
17
|
end
|
13
18
|
|
19
|
+
# Setup the resolver object.
|
20
|
+
# @return [Boolean]
|
14
21
|
def setup
|
15
22
|
@outfile_ext = File.extname(@outfile)
|
16
23
|
file_ext_check
|
24
|
+
true
|
17
25
|
end
|
18
26
|
|
27
|
+
# Load and parse the input files.
|
28
|
+
# @return [Boolean]
|
19
29
|
def load
|
20
30
|
@data = input_dir(@meta_dir)
|
21
31
|
resolve
|
22
32
|
@data['paths'] = input_dir(@path_dir)
|
23
33
|
@data['definitions'] = input_dir(@model_dir) if v2?
|
24
34
|
@data['components'] = { 'schemas' => input_dir(@model_dir) } if v3?
|
35
|
+
true
|
25
36
|
end
|
26
37
|
|
38
|
+
# Distribute the command artifacts.
|
39
|
+
# @return [Boolean]
|
27
40
|
def distribute
|
28
41
|
output(@data, @outfile)
|
42
|
+
true
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
@@ -2,25 +2,35 @@ require 'oas_contrib/resolver/base'
|
|
2
2
|
|
3
3
|
module OasContrib
|
4
4
|
module Resolver
|
5
|
+
# Preview command resolver class
|
5
6
|
class Preview < OasContrib::Resolver::Base
|
7
|
+
# Initialize
|
8
|
+
# @param [String] infile spec file path
|
9
|
+
# @param [Array] options command options
|
6
10
|
def initialize(infile, options)
|
7
11
|
@infile = infile
|
8
12
|
@port = options['port']
|
9
13
|
end
|
10
14
|
|
15
|
+
# Setup the resolver object.
|
16
|
+
# @return [Boolean]
|
11
17
|
def setup
|
12
18
|
@expand_path = File.expand_path(@infile)
|
13
19
|
@basename = File.basename(@expand_path)
|
14
20
|
@infile_ext = File.extname(@infile)
|
15
21
|
file_ext_check
|
22
|
+
true
|
16
23
|
end
|
17
24
|
|
25
|
+
# Distribute the command artifacts.
|
26
|
+
# @return [Boolean]
|
18
27
|
def distribute
|
19
28
|
puts "SwaggerUI listen: http://localhost:#{@port} with: #{@expand_path}"
|
20
29
|
`docker run --rm --name oas_contrib_preview_swagger_ui \
|
21
30
|
-p #{@port}:8080 -e API_URL=#{@basename} \
|
22
31
|
-v #{@expand_path}:/usr/share/nginx/html/#{@basename} swaggerapi/swagger-ui`
|
23
32
|
raise 'Preview command needs docker.' unless $?.exitstatus.zero?
|
33
|
+
true
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
data/lib/oas_contrib/version.rb
CHANGED
data/lib/oas_contrib.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michinao Shimizu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.7.
|
143
|
+
rubygems_version: 2.7.7
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Libraries and Commands for Open API (2.0, 3.0) Specification.
|