oas_contrib 0.2.4 → 0.2.5
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 +16 -111
- data/lib/oas_contrib/command.rb +3 -3
- data/lib/oas_contrib/interface/spec.rb +1 -1
- data/lib/oas_contrib/resolver/base.rb +12 -8
- data/lib/oas_contrib/resolver/divide.rb +3 -3
- data/lib/oas_contrib/resolver/merge.rb +6 -6
- data/lib/oas_contrib/resolver/preview.rb +3 -1
- data/lib/oas_contrib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0a7cb442ad80a5069290a8ee4452c08aa454b9db4fe0e4c6a4a9e759754269f
|
4
|
+
data.tar.gz: 41ee8a0a9d722e5ec0e14cc2db1eb177d646538b4e1c4bd52a12816d8325c089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30b549fe4d53f3281f3b498d898251a131fd20fd4d8f5e6b70fed504bcb6935a29de10237952895287cbf5d1f7f4fce294233541cb48ce798f4caa75ceec8a92
|
7
|
+
data.tar.gz: 92fbd5c8820a6b30dde1e7b7ff431d7fac8b56cc14c1392ea36cfb836b364e1f6e7fb6919ff14022ffa6639a22a16680e7164b9005c4f250fced5a165955c706
|
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.51656 seconds |
|
4
|
+
./spec/divide_command_spec.rb[1:2:1] | passed | 0.42067 seconds |
|
5
|
+
./spec/divide_command_spec.rb[1:3:1] | passed | 0.45216 seconds |
|
6
|
+
./spec/divide_command_spec.rb[1:4:1] | passed | 0.35493 seconds |
|
7
|
+
./spec/divide_command_spec.rb[1:5:1] | passed | 0.31474 seconds |
|
8
|
+
./spec/merge_command_spec.rb[1:1:1] | passed | 0.34898 seconds |
|
9
|
+
./spec/merge_command_spec.rb[1:2:1] | passed | 0.3249 seconds |
|
10
|
+
./spec/merge_command_spec.rb[1:3:1] | passed | 0.3212 seconds |
|
11
|
+
./spec/merge_command_spec.rb[1:4:1] | passed | 0.41895 seconds |
|
12
|
+
./spec/merge_command_spec.rb[1:5:1] | passed | 0.75778 seconds |
|
data/README.md
CHANGED
@@ -22,132 +22,37 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
###
|
25
|
+
### Common rule
|
26
26
|
|
27
|
-
|
27
|
+
* The file extension of `<OpenAPI Specification file>` must be `.json` or `.yml`.
|
28
|
+
* `<OpenAPI Specification file>` must be has the section of `swagger: 2.0.X` or `openapi: 3.0.X`.
|
28
29
|
|
29
|
-
|
30
|
-
$ oas_contrib divide <OAS file> <output_dir> (<options>...)
|
31
|
-
```
|
32
|
-
|
33
|
-
`<OAS file>` must be `.json` or `.yml`
|
34
|
-
|
35
|
-
#### Options
|
36
|
-
|
37
|
-
| option | description | value type | default |
|
38
|
-
|------------|------------------|---------------------------|----------|
|
39
|
-
|`--out_type`| output file type | String (`yaml` or `json`) | `yaml` |
|
40
|
-
|
41
|
-
#### Example
|
42
|
-
|
43
|
-
##### Open API 3.0
|
44
|
-
|
45
|
-
[BEFORE](https://github.com/MichinaoShimizu/oas_contrib/blob/master/example/v3.yml) -> [AFTER](https://github.com/MichinaoShimizu/oas_contrib/tree/master/example/dist/v3)
|
46
|
-
|
47
|
-
```
|
48
|
-
$ oas_contrib divide example/v3.yml example/dist/v3
|
49
|
-
Load: example/v3.yml
|
50
|
-
Dist: example/dist/v3/meta
|
51
|
-
Dist: example/dist/v3/meta/001_openapi.yml
|
52
|
-
Dist: example/dist/v3/meta/002_info.yml
|
53
|
-
Dist: example/dist/v3/meta/003_servers.yml
|
54
|
-
Dist: example/dist/v3/path
|
55
|
-
Dist: example/dist/v3/path/001_pets.yml
|
56
|
-
Dist: example/dist/v3/path/002_pets_{petId}.yml
|
57
|
-
Dist: example/dist/v3/model
|
58
|
-
Dist: example/dist/v3/model/001_Pet.yml
|
59
|
-
Dist: example/dist/v3/model/002_Error.yml
|
60
|
-
|
61
|
-
$ tree example/dist/v3/
|
62
|
-
example/dist/v3/
|
63
|
-
├── meta
|
64
|
-
│ ├── 001_openapi.yml
|
65
|
-
│ ├── 002_info.yml
|
66
|
-
│ └── 003_servers.yml
|
67
|
-
├── model
|
68
|
-
│ ├── 001_Pet.yml
|
69
|
-
│ ├── 002_Error.yml
|
70
|
-
│ └── 003_Pets.yml
|
71
|
-
└── path
|
72
|
-
├── 001_pets.yml
|
73
|
-
└── 002_pets_{petId}.yml
|
74
|
-
```
|
30
|
+
### Divide the OpenAPI Specification file
|
75
31
|
|
76
|
-
|
77
|
-
|
78
|
-
[BEFORE](https://github.com/MichinaoShimizu/oas_contrib/blob/master/example/v2.yml) -> [AFTER](https://github.com/MichinaoShimizu/oas_contrib/tree/master/example/dist/v2)
|
79
|
-
|
80
|
-
```
|
81
|
-
$ oas_contrib divide example/v2.yml example/dist/v2
|
82
|
-
Load: example/v2.yml
|
83
|
-
Dist: example/dist/v2/meta
|
84
|
-
Dist: example/dist/v2/meta/001_swagger.yml
|
85
|
-
Dist: example/dist/v2/meta/002_info.yml
|
86
|
-
Dist: example/dist/v2/meta/003_host.yml
|
87
|
-
Dist: example/dist/v2/meta/004_basePath.yml
|
88
|
-
Dist: example/dist/v2/meta/005_schemes.yml
|
89
|
-
Dist: example/dist/v2/meta/006_consumes.yml
|
90
|
-
Dist: example/dist/v2/meta/007_produces.yml
|
91
|
-
Dist: example/dist/v2/meta/008_components.yml
|
92
|
-
Dist: example/dist/v2/path
|
93
|
-
Dist: example/dist/v2/path/001_pets.yml
|
94
|
-
Dist: example/dist/v2/path/002_pets_{petId}.yml
|
95
|
-
Dist: example/dist/v2/model
|
96
|
-
Dist: example/dist/v2/model/001_Pet.yml
|
97
|
-
Dist: example/dist/v2/model/002_Error.yml
|
98
|
-
Dist: example/dist/v2/model/003_Pets.yml
|
99
|
-
|
100
|
-
$ tree example/dist/
|
101
|
-
example/dist/
|
102
|
-
└── v2
|
103
|
-
├── meta
|
104
|
-
│ ├── 001_swagger.yml
|
105
|
-
│ ├── 002_info.yml
|
106
|
-
│ ├── 003_host.yml
|
107
|
-
│ ├── 004_basePath.yml
|
108
|
-
│ ├── 005_schemes.yml
|
109
|
-
│ ├── 006_consumes.yml
|
110
|
-
│ ├── 007_produces.yml
|
111
|
-
│ └── 008_components.yml
|
112
|
-
├── model
|
113
|
-
│ ├── 001_Pet.yml
|
114
|
-
│ ├── 002_Error.yml
|
115
|
-
│ └── 003_Pets.yml
|
116
|
-
└── path
|
117
|
-
├── 001_pets.yml
|
118
|
-
└── 002_pets_{petId}.yml
|
32
|
+
```bash
|
33
|
+
$ oas_contrib divide <OpenAPI Specification file> <output_dir> (<options>...)
|
119
34
|
```
|
120
35
|
|
121
|
-
|
36
|
+
| option | description | value type | default |
|
37
|
+
|------------|------------------------------|----------------------------|----------|
|
38
|
+
|`--out_ext` | the extension of output file | String (`.json` or `.yml`) | `.yml` |
|
122
39
|
|
123
|
-
Merge
|
40
|
+
### Merge from divided files to an OpenAPI Specification file
|
124
41
|
|
125
42
|
```bash
|
126
|
-
$ oas_contrib merge <input_dir> <
|
43
|
+
$ oas_contrib merge <input_dir> <OpenAPI Specification file> (<options>...)
|
127
44
|
```
|
128
45
|
|
129
|
-
|
130
|
-
|
131
|
-
|
46
|
+
| option | description | value type | default |
|
47
|
+
|------------|------------------------------|----------------------------|----------|
|
48
|
+
|`--in_ext` | the extension of input file | String (`.json` or `.yml`) | `.yml` |
|
132
49
|
|
133
|
-
|
134
|
-
|------------|------------------|------------------------- |----------|
|
135
|
-
|`--in_type` | input file type | String (`yaml` or `json`)| `yaml` |
|
136
|
-
|
137
|
-
### Preview command
|
138
|
-
|
139
|
-
Preview OAS file using Swagger-UI official Docker image.
|
140
|
-
|
141
|
-
The preview command needs docker.
|
50
|
+
### Preview the OpenAPI Specification file using Swagger-UI docker image
|
142
51
|
|
143
52
|
```bash
|
144
|
-
$ oas_contrib preview <
|
53
|
+
$ oas_contrib preview <OpenAPI Specification file> (<options>...)
|
145
54
|
```
|
146
55
|
|
147
|
-
`<input_file>` must be `.json` or `.yml`
|
148
|
-
|
149
|
-
#### Options
|
150
|
-
|
151
56
|
| option | description | value type | default |
|
152
57
|
|------------|-------------------------|-----------------|----------|
|
153
58
|
|`--port` | Swagger UI listen port | Integer | `50010` |
|
data/lib/oas_contrib/command.rb
CHANGED
@@ -7,8 +7,8 @@ module OasContrib
|
|
7
7
|
class Command < Thor
|
8
8
|
include Thor::Actions
|
9
9
|
|
10
|
-
option :out_type, type: :string, default: 'yaml', desc: 'output file type (yaml or json)'
|
11
10
|
desc 'divide <spec_file> <output_dir> (<options>)', 'Divide the spec_file into path units and schema units.'
|
11
|
+
option :out_ext, type: :string, default: '.yml', desc: 'output file ext (.yml or .json)'
|
12
12
|
|
13
13
|
def divide(spec_file, outdir)
|
14
14
|
resolver = OasContrib::Resolver::Divide.new(spec_file, outdir, options)
|
@@ -19,8 +19,8 @@ module OasContrib
|
|
19
19
|
say 'complete!', :green
|
20
20
|
end
|
21
21
|
|
22
|
-
option :in_type, type: :string, default: 'yaml', desc: 'input file type (yaml or json)'
|
23
22
|
desc 'merge <input_dir> <spec_file> (<options>)', 'Merge multiple divided files into an spec_file.'
|
23
|
+
option :in_ext, type: :string, default: '.yml', desc: 'input file ext (.yml or .json)'
|
24
24
|
|
25
25
|
def merge(indir, spec_file)
|
26
26
|
resolver = OasContrib::Resolver::Merge.new(indir, spec_file, options)
|
@@ -31,8 +31,8 @@ module OasContrib
|
|
31
31
|
say 'complete!', :green
|
32
32
|
end
|
33
33
|
|
34
|
-
option :port, type: :numeric, default: 50010, desc: 'Swagger UI listen port'
|
35
34
|
desc 'preview <spec_file> (<options>)', 'Preview the spec_file using Swagger-UI official Docker image.'
|
35
|
+
option :port, type: :numeric, default: 50_010, desc: 'Swagger UI listen port'
|
36
36
|
|
37
37
|
def preview(spec_file)
|
38
38
|
resolver = OasContrib::Resolver::Preview.new(spec_file, options)
|
@@ -11,6 +11,18 @@ module OasContrib
|
|
11
11
|
|
12
12
|
include OasContrib::Interface::Resolver
|
13
13
|
|
14
|
+
DEFINED_FILE_EXT = ['.json', '.yml'].freeze
|
15
|
+
|
16
|
+
def file_ext_check
|
17
|
+
if @infile_ext && !DEFINED_FILE_EXT.include?(@infile_ext)
|
18
|
+
raise "Undefined input file extension. #{@infile_ext}"
|
19
|
+
end
|
20
|
+
|
21
|
+
if @outfile_ext && !DEFINED_FILE_EXT.include?(@outfile_ext)
|
22
|
+
raise "Undefined output file extension. #{@outfile_ext}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
14
26
|
def v3?
|
15
27
|
@data['openapi'] =~ /^3/
|
16
28
|
end
|
@@ -34,14 +46,6 @@ module OasContrib
|
|
34
46
|
File.open(path, 'w') { |f| _output(hash, f) }
|
35
47
|
end
|
36
48
|
|
37
|
-
def str2ext(type)
|
38
|
-
case type
|
39
|
-
when 'yaml' then '.yml'
|
40
|
-
when 'json' then '.json'
|
41
|
-
else raise ArgumentError, 'Undefined file type'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
49
|
def input_dir(dir)
|
46
50
|
path = dir + '/**/*' + @infile_ext
|
47
51
|
Dir.glob(path).sort.each_with_object({}, &input_lambda)
|
@@ -8,12 +8,12 @@ module OasContrib
|
|
8
8
|
@path_dir = outdir + '/path'
|
9
9
|
@model_dir = outdir + '/model'
|
10
10
|
@infile = infile
|
11
|
-
@
|
11
|
+
@outfile_ext = options['out_ext']
|
12
12
|
end
|
13
13
|
|
14
14
|
def setup
|
15
|
-
@infile_ext
|
16
|
-
|
15
|
+
@infile_ext = File.extname(@infile)
|
16
|
+
file_ext_check
|
17
17
|
end
|
18
18
|
|
19
19
|
def load
|
@@ -4,16 +4,16 @@ module OasContrib
|
|
4
4
|
module Resolver
|
5
5
|
class Merge < OasContrib::Resolver::Base
|
6
6
|
def initialize(indir, outfile, options)
|
7
|
-
@meta_dir
|
8
|
-
@path_dir
|
9
|
-
@model_dir
|
10
|
-
@outfile
|
11
|
-
@
|
7
|
+
@meta_dir = indir + '/meta'
|
8
|
+
@path_dir = indir + '/path'
|
9
|
+
@model_dir = indir + '/model'
|
10
|
+
@outfile = outfile
|
11
|
+
@infile_ext = options['in_ext']
|
12
12
|
end
|
13
13
|
|
14
14
|
def setup
|
15
|
-
@infile_ext = str2ext(@infile_type)
|
16
15
|
@outfile_ext = File.extname(@outfile)
|
16
|
+
file_ext_check
|
17
17
|
end
|
18
18
|
|
19
19
|
def load
|
data/lib/oas_contrib/version.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.5
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|