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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b1a48c2b71fbc69225a8d565450bd2478ce8e5f2710196a06c05a3d60c93e68
4
- data.tar.gz: 4bb4aea54a90ebdd8edc03252da09122625e411c17a31076fdd93c8457df76ba
3
+ metadata.gz: b0a7cb442ad80a5069290a8ee4452c08aa454b9db4fe0e4c6a4a9e759754269f
4
+ data.tar.gz: 41ee8a0a9d722e5ec0e14cc2db1eb177d646538b4e1c4bd52a12816d8325c089
5
5
  SHA512:
6
- metadata.gz: 723585fa66b02f6ff7201026234ea318f9f26e798a2ddf6fdc232c6b32505a7a3d9a6653c07820cd12f32fb38f74009727a34a8425073b9692e9ba14ed13d03a
7
- data.tar.gz: a7d852a298beafaf2fbefec3c84278610d680f438ca3d21d9a02d36fd005e73e707709e165593fea66920696be8ccbbd5132512edaa4a1a3ec4313adf2bc561b
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.34731 seconds |
4
- ./spec/divide_command_spec.rb[1:2:1] | passed | 0.35834 seconds |
5
- ./spec/divide_command_spec.rb[1:3:1] | passed | 0.50581 seconds |
6
- ./spec/divide_command_spec.rb[1:4:1] | passed | 0.41085 seconds |
7
- ./spec/divide_command_spec.rb[1:5:1] | passed | 0.52116 seconds |
8
- ./spec/merge_command_spec.rb[1:1:1] | passed | 0.80512 seconds |
9
- ./spec/merge_command_spec.rb[1:2:1] | passed | 0.54957 seconds |
10
- ./spec/merge_command_spec.rb[1:3:1] | passed | 0.45048 seconds |
11
- ./spec/merge_command_spec.rb[1:4:1] | passed | 0.53336 seconds |
12
- ./spec/merge_command_spec.rb[1:5:1] | passed | 0.60615 seconds |
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
- ### Divide command
25
+ ### Common rule
26
26
 
27
- Divide the OAS file into path units and schema units.
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
- ```bash
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
- ##### Open API 2.0
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
- ### Merge command
36
+ | option | description | value type | default |
37
+ |------------|------------------------------|----------------------------|----------|
38
+ |`--out_ext` | the extension of output file | String (`.json` or `.yml`) | `.yml` |
122
39
 
123
- Merge multiple divided files into an OAS file.
40
+ ### Merge from divided files to an OpenAPI Specification file
124
41
 
125
42
  ```bash
126
- $ oas_contrib merge <input_dir> <OAS file> (<options>...)
43
+ $ oas_contrib merge <input_dir> <OpenAPI Specification file> (<options>...)
127
44
  ```
128
45
 
129
- `<OAS file>` must be `.json` or `.yml`
130
-
131
- #### Options
46
+ | option | description | value type | default |
47
+ |------------|------------------------------|----------------------------|----------|
48
+ |`--in_ext` | the extension of input file | String (`.json` or `.yml`) | `.yml` |
132
49
 
133
- | option | description | value type | default |
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 <input_file> (<options>...)
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` |
@@ -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)
@@ -2,7 +2,7 @@ module OasContrib
2
2
  module Interface
3
3
  module Spec
4
4
  def mapping
5
- raise NotImplementedError, 'You must be implement "mangppi" method.'
5
+ raise NotImplementedError, 'You must be implement "mapping" method.'
6
6
  end
7
7
  end
8
8
  end
@@ -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
- @outfile_type = options['out_type']
11
+ @outfile_ext = options['out_ext']
12
12
  end
13
13
 
14
14
  def setup
15
- @infile_ext = File.extname(@infile)
16
- @outfile_ext = str2ext(@outfile_type)
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 = indir + '/meta'
8
- @path_dir = indir + '/path'
9
- @model_dir = indir + '/model'
10
- @outfile = outfile
11
- @infile_type = options['in_type']
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
@@ -10,7 +10,9 @@ module OasContrib
10
10
 
11
11
  def setup
12
12
  @expand_path = File.expand_path(@infile)
13
- @basename = File.basename(@expand_path)
13
+ @basename = File.basename(@expand_path)
14
+ @infile_ext = File.extname(@infile)
15
+ file_ext_check
14
16
  end
15
17
 
16
18
  def distribute
@@ -1,3 +1,3 @@
1
1
  module OasContrib
2
- VERSION = '0.2.4'.freeze
2
+ VERSION = '0.2.5'.freeze
3
3
  end
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
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-07 00:00:00.000000000 Z
11
+ date: 2018-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor