interpol_to_open_api 0.2.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 +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/interpol_to_open_api +6 -0
- data/interpol_to_open_api.gemspec +27 -0
- data/lib/interpol_to_open_api.rb +7 -0
- data/lib/interpol_to_open_api/cli.rb +36 -0
- data/lib/interpol_to_open_api/converter.rb +95 -0
- data/lib/interpol_to_open_api/ext/string.rb +5 -0
- data/lib/interpol_to_open_api/interpol/property.rb +42 -0
- data/lib/interpol_to_open_api/interpol/schema.rb +18 -0
- data/lib/interpol_to_open_api/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b700570441ee836e99a610386695ba4863e37a0
|
4
|
+
data.tar.gz: 6c5688b27258dc36774e95b620ee96b108d8caa4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 687a06d8a163025c9fe03ee79c91c0db8e81ac3ccc5fb0274ad6041fd07aa2ba7d870912609e0727378e180b9d427f1dc03464d442b66b23b81f98be3c85b47f
|
7
|
+
data.tar.gz: 5917ee6f527ef6910309e72f89c54556007efe2103618cc65f308358221cbff29f0cc85c81282b5fe857e78e9c092d7cdf94538074ad54a07cb4025d73fecc1d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# InterpolToOpenAPI
|
2
|
+
|
3
|
+
This tool is made to be used in a process of work to convert Interpol definitions into Open API Specification v2.0.
|
4
|
+
|
5
|
+
Note that this does not aim complete conversion. Manual modification is premised and developed for only my use-case.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Clone this repository and build. Publishing on Rubygem is not planned for now.
|
10
|
+
|
11
|
+
```
|
12
|
+
git clone https://github.com/Joe-noh/interpol_to_open_api
|
13
|
+
|
14
|
+
cd ./interpol_to_open_api
|
15
|
+
|
16
|
+
gem build interpol_to_open_api.gemspec
|
17
|
+
gem install interpol_to_open_api-0.x.x,gem
|
18
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "interpol_to_open_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'interpol_to_open_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "interpol_to_open_api"
|
8
|
+
spec.version = InterpolToOpenAPI::VERSION
|
9
|
+
spec.authors = ["Joe-noh"]
|
10
|
+
spec.email = ["goflb.jh@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Converts interpol endpoint definition into Open API spec."
|
13
|
+
spec.homepage = "https://github.com/Joe-noh/interpol_to_open_api"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.2.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module InterpolToOpenAPI
|
5
|
+
class CLI
|
6
|
+
def initialize(argv)
|
7
|
+
@src = nil
|
8
|
+
|
9
|
+
define_cli_options(argv)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
raise 'Give input yaml path with -i option.' if @src.nil?
|
14
|
+
|
15
|
+
converter = InterpolToOpenAPI::Converter.new
|
16
|
+
puts converter.convert(@src).to_yaml
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def define_cli_options(argv)
|
22
|
+
@opt = OptionParser.new
|
23
|
+
|
24
|
+
@opt.on('-v', '--version', 'print the version') do
|
25
|
+
puts InterpolToOpenAPI::VERSION
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
@opt.on('-i path', '--input', 'path to input endpoint definition yaml') do |path|
|
30
|
+
@src = path
|
31
|
+
end
|
32
|
+
|
33
|
+
@opt.parse!(argv)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require_relative 'interpol/schema'
|
3
|
+
|
4
|
+
module InterpolToOpenAPI
|
5
|
+
class Converter
|
6
|
+
def convert(path)
|
7
|
+
interpol = YAML.load_file(path)
|
8
|
+
|
9
|
+
req, res = interpol['definitions'].partition {|definition| definition['message_type'] == 'request' }
|
10
|
+
|
11
|
+
{
|
12
|
+
camelize_path_parameters(interpol['route']) => {
|
13
|
+
interpol['method'].downcase => {
|
14
|
+
'summary' => '',
|
15
|
+
'description' => req.first['schema']['description'] || '',
|
16
|
+
'operationId' => interpol['name'].camelize,
|
17
|
+
'tags' => [],
|
18
|
+
'parameters' => build_parameters(req.first),
|
19
|
+
'responses' => build_responses(res.first)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_parameters(request)
|
28
|
+
[
|
29
|
+
parameters_in_path(request['path_params']['properties']),
|
30
|
+
parameters_in_query(request['query_params']['properties']),
|
31
|
+
parameters_in_body(request['schema'])
|
32
|
+
].flatten
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_responses(response)
|
36
|
+
status_code = response['status_codes'].first
|
37
|
+
schema = Interpol::Schema.new response['schema'].merge({
|
38
|
+
'example' => response['examples'].first
|
39
|
+
})
|
40
|
+
|
41
|
+
{
|
42
|
+
status_code => {
|
43
|
+
'description' => '',
|
44
|
+
'schema' => schema.to_openapi
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def parameters_in_path(properties)
|
50
|
+
return [] unless properties.is_a? Hash
|
51
|
+
|
52
|
+
properties.map do |name, schema|
|
53
|
+
{
|
54
|
+
'in' => 'path',
|
55
|
+
'name' => name.camelize,
|
56
|
+
'description' => '',
|
57
|
+
'required' => true,
|
58
|
+
'type' => schema['type']
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def parameters_in_query(properties)
|
64
|
+
return [] unless properties.is_a? Hash
|
65
|
+
|
66
|
+
properties.map do |name, schema|
|
67
|
+
{
|
68
|
+
'in' => 'query',
|
69
|
+
'name' => name,
|
70
|
+
'description' => '',
|
71
|
+
'type' => schema['type']
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def parameters_in_body(schema)
|
77
|
+
return [] unless schema['properties'].is_a? Hash
|
78
|
+
|
79
|
+
schema['properties'].map do |name, schema|
|
80
|
+
{
|
81
|
+
'in' => 'body',
|
82
|
+
'name' => name,
|
83
|
+
'description' => '',
|
84
|
+
'schema' => Interpol::Schema.new(schema).to_openapi
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def camelize_path_parameters(path)
|
90
|
+
path.gsub(/:([\w]+)/) do |_matched|
|
91
|
+
"{" + $1.camelize + "}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module InterpolToOpenAPI
|
2
|
+
module Interpol
|
3
|
+
class Property
|
4
|
+
def self.array_to_openapi(properties)
|
5
|
+
properties.map {|name, attrs|
|
6
|
+
Property.new(name, attrs).to_openapi
|
7
|
+
}.inject {|acc, hash|
|
8
|
+
acc.merge(hash)
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(name, attrs)
|
13
|
+
@name = name
|
14
|
+
@attrs = attrs
|
15
|
+
|
16
|
+
@attrs["properties"] = Property.array_to_openapi(@attrs["properties"]) if @attrs.has_key?("properties")
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_openapi
|
20
|
+
if nullable?
|
21
|
+
attrs = @attrs.merge({
|
22
|
+
"type" => type_without_null,
|
23
|
+
"x-nullable" => true
|
24
|
+
})
|
25
|
+
else
|
26
|
+
attrs = @attrs
|
27
|
+
end
|
28
|
+
|
29
|
+
{@name => attrs}
|
30
|
+
end
|
31
|
+
|
32
|
+
def nullable?
|
33
|
+
@attrs["type"].is_a?(Array) && @attrs["type"].member?("null")
|
34
|
+
end
|
35
|
+
|
36
|
+
def type_without_null
|
37
|
+
type = @attrs["type"].select {|t| t != "null"}
|
38
|
+
type.size == 1 ? type.first : type
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "property"
|
2
|
+
|
3
|
+
module InterpolToOpenAPI
|
4
|
+
module Interpol
|
5
|
+
class Schema
|
6
|
+
def initialize(schema)
|
7
|
+
@schema = schema
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_openapi
|
11
|
+
update = {}
|
12
|
+
update["properties"] = Property.array_to_openapi(@schema["properties"]) if @schema.has_key?("properties")
|
13
|
+
|
14
|
+
@schema.merge(update)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interpol_to_open_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe-noh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- goflb.jh@gmail.com
|
58
|
+
executables:
|
59
|
+
- interpol_to_open_api
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- exe/interpol_to_open_api
|
71
|
+
- interpol_to_open_api.gemspec
|
72
|
+
- lib/interpol_to_open_api.rb
|
73
|
+
- lib/interpol_to_open_api/cli.rb
|
74
|
+
- lib/interpol_to_open_api/converter.rb
|
75
|
+
- lib/interpol_to_open_api/ext/string.rb
|
76
|
+
- lib/interpol_to_open_api/interpol/property.rb
|
77
|
+
- lib/interpol_to_open_api/interpol/schema.rb
|
78
|
+
- lib/interpol_to_open_api/version.rb
|
79
|
+
homepage: https://github.com/Joe-noh/interpol_to_open_api
|
80
|
+
licenses: []
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.2.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Converts interpol endpoint definition into Open API spec.
|
102
|
+
test_files: []
|