oas_contrib 0.1.0 → 0.1.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 +4 -4
- data/README.md +2 -0
- data/lib/oas_contrib/command.rb +19 -4
- data/lib/oas_contrib/command_util.rb +49 -16
- data/lib/oas_contrib/version.rb +1 -1
- data/sample_petstore_2.yml +103 -0
- data/sample_petstore_3.yml +110 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c8a1b78e6c65c71f5d0053bd8b1a268213a8cb0e1eecfe423f2321c27aea23e
|
4
|
+
data.tar.gz: 8d705ccbd6fbabb6e11e418c08423707cbd14ae47f67bf3eaa8b689d52484f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587adc04a079ca0030fd341df911947edbb4722ee583df1bd6487e78a8d7be29221833855d0665fa17424b729516422aa13630da48776a89a342f1844a278d1b
|
7
|
+
data.tar.gz: 4b6876e829bd6f7a1e1bebd662c7533a01b1b6e6796d6467f5a9eb8ccd8d9b4b9a6ba9fcaaf1f3c82f036cf9e1f02f86bae850da8aa89eae19de2359be20e626
|
data/README.md
CHANGED
data/lib/oas_contrib/command.rb
CHANGED
@@ -19,13 +19,19 @@ module OasContrib
|
|
19
19
|
raise ArgumentError, "in_file:[#{in_file}] is not exists." unless File.exist?(in_file)
|
20
20
|
in_type = options['in_type']
|
21
21
|
out_type = options['out_type']
|
22
|
-
meta_file, path_dir, schema_dir = env_paths(out_dir, out_type)
|
23
22
|
hash = input_solo(in_file, in_type)
|
23
|
+
version = definition_version(hash)
|
24
|
+
|
25
|
+
meta_file = get_meta_file_path(out_dir, out_type)
|
26
|
+
path_dir = get_path_dir_path(out_dir)
|
27
|
+
schema_dir = get_schema_dir_path(out_dir, version)
|
28
|
+
|
24
29
|
FileUtils.mkdir_p(path_dir)
|
25
30
|
FileUtils.mkdir_p(schema_dir)
|
31
|
+
|
26
32
|
output_solo(meta_filter(hash), meta_file, out_type)
|
27
33
|
output_multi(hash['paths'], path_dir, out_type)
|
28
|
-
output_multi(hash
|
34
|
+
output_multi(schema_filter(hash, version), schema_dir, out_type)
|
29
35
|
end
|
30
36
|
|
31
37
|
option :in_type, :type => :string, :aliases => '-it', :default => 'yaml', :desc => 'input file type (yaml or json)'
|
@@ -40,11 +46,20 @@ module OasContrib
|
|
40
46
|
raise ArgumentError, "in_dir:[#{in_dir}] is not exists." unless File.exist?(in_dir)
|
41
47
|
in_type = options['in_type']
|
42
48
|
out_type = options['out_type']
|
43
|
-
|
49
|
+
|
50
|
+
meta_file = get_meta_file_path(in_dir, in_type)
|
44
51
|
hash = input_solo(meta_file, in_type)
|
52
|
+
version = definition_version(hash)
|
53
|
+
|
54
|
+
path_dir = get_path_dir_path(in_dir)
|
55
|
+
schema_dir = get_schema_dir_path(in_dir, version)
|
56
|
+
|
45
57
|
hash['components'] = {}
|
46
58
|
hash['paths'] = input_multi(path_dir, in_type)
|
47
|
-
|
59
|
+
case version
|
60
|
+
when 'v2' then hash['definitions'] = input_multi(schema_dir, in_type)
|
61
|
+
when 'v3' then hash['components']['schemas'] = input_multi(schema_dir, in_type)
|
62
|
+
end
|
48
63
|
output_solo(hash, out_file, out_type)
|
49
64
|
end
|
50
65
|
|
@@ -9,16 +9,42 @@ module OasContrib
|
|
9
9
|
# @return [String]
|
10
10
|
FILE_TYPE_JSON = 'json'.freeze
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
def definition_version(hash)
|
13
|
+
if hash['swagger']
|
14
|
+
puts 'OK. input file is swagger 2.0 format.'
|
15
|
+
return 'v2'
|
16
|
+
end
|
17
|
+
|
18
|
+
if hash['openapi']
|
19
|
+
puts 'OK. input file is openapi 3.0 format.'
|
20
|
+
return 'v3'
|
21
|
+
end
|
22
|
+
|
23
|
+
raise 'input file must be swagger 2.0, or openapi 3.0 format.'
|
24
|
+
end
|
25
|
+
|
26
|
+
def schema_filter(hash, version)
|
27
|
+
case version
|
28
|
+
when 'v2' then hash['definitions']
|
29
|
+
when 'v3' then hash['components']['schemas']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_meta_file_path(root, file_type)
|
34
|
+
"#{root}/meta#{file_type_ext(file_type)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_path_dir_path(root)
|
38
|
+
"#{root}/paths"
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_schema_dir_path(root, version)
|
42
|
+
schema_path = case version
|
43
|
+
when 'v2' then '/definitions'
|
44
|
+
when 'v3' then '/components/schemas'
|
45
|
+
end
|
46
|
+
|
47
|
+
"#{root}#{schema_path}"
|
22
48
|
end
|
23
49
|
|
24
50
|
# Get file extension
|
@@ -36,10 +62,13 @@ module OasContrib
|
|
36
62
|
# @param [String] file_type <description>
|
37
63
|
# @return [Hash]
|
38
64
|
def input_solo(path, file_type)
|
39
|
-
case file_type
|
40
|
-
|
41
|
-
|
42
|
-
|
65
|
+
hash = case file_type
|
66
|
+
when FILE_TYPE_YAML then YAML.load_file(path)
|
67
|
+
when FILE_TYPE_JSON then JSON.parse(File.read(path))
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Load #{file_type} complete: #{path}"
|
71
|
+
hash
|
43
72
|
end
|
44
73
|
|
45
74
|
# Load path files and get hash
|
@@ -65,7 +94,11 @@ module OasContrib
|
|
65
94
|
when FILE_TYPE_YAML then ->(file) { YAML.dump(hash, file) }
|
66
95
|
when FILE_TYPE_JSON then ->(file) { JSON.dump(hash, file) }
|
67
96
|
end
|
68
|
-
|
97
|
+
|
98
|
+
File.open(path, 'w') do |f|
|
99
|
+
output_lambda.call(f)
|
100
|
+
puts "Generate #{file_type} complete: #{path}"
|
101
|
+
end
|
69
102
|
end
|
70
103
|
|
71
104
|
# Output path definition files
|
@@ -86,7 +119,7 @@ module OasContrib
|
|
86
119
|
# @param [Hash] hash data source hash
|
87
120
|
# @return [Hash] filtered hash
|
88
121
|
def meta_filter(hash)
|
89
|
-
hash.select { |k, _| k != 'paths' && k != 'components' }
|
122
|
+
hash.select { |k, _| k != 'paths' && k != 'components' && k != 'definitions' }
|
90
123
|
end
|
91
124
|
end
|
92
125
|
end
|
data/lib/oas_contrib/version.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
---
|
2
|
+
swagger: '2.0'
|
3
|
+
info:
|
4
|
+
version: 1.0.0
|
5
|
+
title: Swagger Petstore
|
6
|
+
license:
|
7
|
+
name: MIT
|
8
|
+
host: petstore.swagger.io
|
9
|
+
basePath: "/v1"
|
10
|
+
schemes:
|
11
|
+
- http
|
12
|
+
consumes:
|
13
|
+
- application/json
|
14
|
+
produces:
|
15
|
+
- application/json
|
16
|
+
components: {}
|
17
|
+
paths:
|
18
|
+
"/pets":
|
19
|
+
get:
|
20
|
+
summary: List all pets
|
21
|
+
operationId: listPets
|
22
|
+
tags:
|
23
|
+
- pets
|
24
|
+
parameters:
|
25
|
+
- name: limit
|
26
|
+
in: query
|
27
|
+
description: How many items to return at one time (max 100)
|
28
|
+
required: false
|
29
|
+
type: integer
|
30
|
+
format: int32
|
31
|
+
responses:
|
32
|
+
'200':
|
33
|
+
description: A paged array of pets
|
34
|
+
headers:
|
35
|
+
x-next:
|
36
|
+
type: string
|
37
|
+
description: A link to the next page of responses
|
38
|
+
schema:
|
39
|
+
"$ref": "#/definitions/Pets"
|
40
|
+
default:
|
41
|
+
description: unexpected error
|
42
|
+
schema:
|
43
|
+
"$ref": "#/definitions/Error"
|
44
|
+
post:
|
45
|
+
summary: Create a pet
|
46
|
+
operationId: createPets
|
47
|
+
tags:
|
48
|
+
- pets
|
49
|
+
responses:
|
50
|
+
'201':
|
51
|
+
description: Null response
|
52
|
+
default:
|
53
|
+
description: unexpected error
|
54
|
+
schema:
|
55
|
+
"$ref": "#/definitions/Error"
|
56
|
+
"/pets/{petId}":
|
57
|
+
get:
|
58
|
+
summary: Info for a specific pet
|
59
|
+
operationId: showPetById
|
60
|
+
tags:
|
61
|
+
- pets
|
62
|
+
parameters:
|
63
|
+
- name: petId
|
64
|
+
in: path
|
65
|
+
required: true
|
66
|
+
description: The id of the pet to retrieve
|
67
|
+
type: string
|
68
|
+
responses:
|
69
|
+
'200':
|
70
|
+
description: Expected response to a valid request
|
71
|
+
schema:
|
72
|
+
"$ref": "#/definitions/Pets"
|
73
|
+
default:
|
74
|
+
description: unexpected error
|
75
|
+
schema:
|
76
|
+
"$ref": "#/definitions/Error"
|
77
|
+
definitions:
|
78
|
+
Pet:
|
79
|
+
required:
|
80
|
+
- id
|
81
|
+
- name
|
82
|
+
properties:
|
83
|
+
id:
|
84
|
+
type: integer
|
85
|
+
format: int64
|
86
|
+
name:
|
87
|
+
type: string
|
88
|
+
tag:
|
89
|
+
type: string
|
90
|
+
Error:
|
91
|
+
required:
|
92
|
+
- code
|
93
|
+
- message
|
94
|
+
properties:
|
95
|
+
code:
|
96
|
+
type: integer
|
97
|
+
format: int32
|
98
|
+
message:
|
99
|
+
type: string
|
100
|
+
Pets:
|
101
|
+
type: array
|
102
|
+
items:
|
103
|
+
"$ref": "#/definitions/Pet"
|
@@ -0,0 +1,110 @@
|
|
1
|
+
---
|
2
|
+
openapi: 3.0.0
|
3
|
+
info:
|
4
|
+
version: 1.0.0
|
5
|
+
title: Swagger Petstore
|
6
|
+
license:
|
7
|
+
name: MIT
|
8
|
+
servers:
|
9
|
+
- url: http://petstore.swagger.io/v1
|
10
|
+
components:
|
11
|
+
schemas:
|
12
|
+
Pet:
|
13
|
+
required:
|
14
|
+
- id
|
15
|
+
- name
|
16
|
+
properties:
|
17
|
+
id:
|
18
|
+
type: integer
|
19
|
+
format: int64
|
20
|
+
name:
|
21
|
+
type: string
|
22
|
+
tag:
|
23
|
+
type: string
|
24
|
+
Error:
|
25
|
+
required:
|
26
|
+
- code
|
27
|
+
- message
|
28
|
+
properties:
|
29
|
+
code:
|
30
|
+
type: integer
|
31
|
+
format: int32
|
32
|
+
message:
|
33
|
+
type: string
|
34
|
+
Pets:
|
35
|
+
type: array
|
36
|
+
items:
|
37
|
+
"$ref": "#/components/schemas/Pet"
|
38
|
+
paths:
|
39
|
+
"/pets":
|
40
|
+
get:
|
41
|
+
summary: List all pets
|
42
|
+
operationId: listPets
|
43
|
+
tags:
|
44
|
+
- pets
|
45
|
+
parameters:
|
46
|
+
- name: limit
|
47
|
+
in: query
|
48
|
+
description: How many items to return at one time (max 100)
|
49
|
+
required: false
|
50
|
+
schema:
|
51
|
+
type: integer
|
52
|
+
format: int32
|
53
|
+
responses:
|
54
|
+
'200':
|
55
|
+
description: A paged array of pets
|
56
|
+
headers:
|
57
|
+
x-next:
|
58
|
+
description: A link to the next page of responses
|
59
|
+
schema:
|
60
|
+
type: string
|
61
|
+
content:
|
62
|
+
application/json:
|
63
|
+
schema:
|
64
|
+
"$ref": "#/components/schemas/Pets"
|
65
|
+
default:
|
66
|
+
description: unexpected error
|
67
|
+
content:
|
68
|
+
application/json:
|
69
|
+
schema:
|
70
|
+
"$ref": "#/components/schemas/Error"
|
71
|
+
post:
|
72
|
+
summary: Create a pet
|
73
|
+
operationId: createPets
|
74
|
+
tags:
|
75
|
+
- pets
|
76
|
+
responses:
|
77
|
+
'201':
|
78
|
+
description: Null response
|
79
|
+
default:
|
80
|
+
description: unexpected error
|
81
|
+
content:
|
82
|
+
application/json:
|
83
|
+
schema:
|
84
|
+
"$ref": "#/components/schemas/Error"
|
85
|
+
"/pets/{petId}":
|
86
|
+
get:
|
87
|
+
summary: Info for a specific pet
|
88
|
+
operationId: showPetById
|
89
|
+
tags:
|
90
|
+
- pets
|
91
|
+
parameters:
|
92
|
+
- name: petId
|
93
|
+
in: path
|
94
|
+
required: true
|
95
|
+
description: The id of the pet to retrieve
|
96
|
+
schema:
|
97
|
+
type: string
|
98
|
+
responses:
|
99
|
+
'200':
|
100
|
+
description: Expected response to a valid request
|
101
|
+
content:
|
102
|
+
application/json:
|
103
|
+
schema:
|
104
|
+
"$ref": "#/components/schemas/Pets"
|
105
|
+
default:
|
106
|
+
description: unexpected error
|
107
|
+
content:
|
108
|
+
application/json:
|
109
|
+
schema:
|
110
|
+
"$ref": "#/components/schemas/Error"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michinao Shimizu
|
@@ -88,6 +88,8 @@ files:
|
|
88
88
|
- lib/oas_contrib/command_util.rb
|
89
89
|
- lib/oas_contrib/version.rb
|
90
90
|
- oas_contrib.gemspec
|
91
|
+
- sample_petstore_2.yml
|
92
|
+
- sample_petstore_3.yml
|
91
93
|
homepage: https://github.com/MichinaoShimizu/oas_contrib
|
92
94
|
licenses:
|
93
95
|
- MIT
|