swagger2hyperschema 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +36 -0
- data/Rakefile +11 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/example/simple.yml +17 -0
- data/exe/swagger2hyperschema +10 -0
- data/lib/swagger2hyperschema/cli.rb +20 -0
- data/lib/swagger2hyperschema/converter.rb +51 -0
- data/lib/swagger2hyperschema/version.rb +4 -0
- data/lib/swagger2hyperschema.rb +3 -0
- data/swagger2hyperschema.gemspec +26 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85b66a40ba49a3827e9f3558abb6a3f53ab66752
|
4
|
+
data.tar.gz: a6c2d46c264ca00e7a7e836846f7753721fc999a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e09b140f80350a973d7cdd11e9f825a4bc03fc209ca603bbe8ccba1c03425136b1eba40af57300d4d57fe0b064a7b8be5df0a1ec08d6cdf1469100e64775a0e7
|
7
|
+
data.tar.gz: 1ef084c1a8d1403752f58b7047705f073d59fb736e46a8a764858f7a55a220d558814a6f57122731af6d17c42f49e78a4d5a7eb9cee83c2cd0d1d8b850fadc81
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Swagger2hyperschema
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/swagger2hyperschema`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'swagger2hyperschema'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install swagger2hyperschema
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/swagger2hyperschema.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'swagger2hyperschema'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/example/simple.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
git_path = File.expand_path('../../.git', __FILE__)
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) if File.exist?(git_path)
|
7
|
+
|
8
|
+
require 'swagger2hyperschema/cli'
|
9
|
+
|
10
|
+
Swagger2hyperschema::CLI.new(ARGV).call
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'optparse'
|
3
|
+
require 'stringio'
|
4
|
+
require 'swagger2hyperschema/converter'
|
5
|
+
|
6
|
+
module Swagger2hyperschema
|
7
|
+
class CLI
|
8
|
+
def initialize(argv)
|
9
|
+
@argv = argv
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
file = (File.open(@argv[0]) if File.exist?(@argv[0].to_s))
|
14
|
+
|
15
|
+
return puts 'Usage: swagger2hyperschema FILE' unless file
|
16
|
+
|
17
|
+
puts JSON.pretty_generate(Converter.new(file).call)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Swagger2hyperschema
|
6
|
+
class Converter
|
7
|
+
def initialize(swagger_file)
|
8
|
+
@swagger_file = swagger_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
json_schema = {
|
13
|
+
'$schema' => 'http://json-schema.org/draft-04/hyper-schema',
|
14
|
+
'type' => 'object',
|
15
|
+
'links' => []
|
16
|
+
}
|
17
|
+
|
18
|
+
json_schema['links'] = swagger['paths'].flat_map {|endpoint, methods|
|
19
|
+
methods.map {|method, link| convert_path_to_link(endpoint, method, link) }
|
20
|
+
}
|
21
|
+
|
22
|
+
json_schema['definitions'] = swagger['definitions']
|
23
|
+
|
24
|
+
json_schema
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def convert_path_to_link(endpoint, method, link)
|
30
|
+
{
|
31
|
+
'description' => link['description'] || "#{method} #{endpoint}",
|
32
|
+
'href' => swagger['basePath'].to_s + endpoint,
|
33
|
+
'method' => method.upcase,
|
34
|
+
'rel' => link['description'] || "#{method} #{endpoint}",
|
35
|
+
'targetSchema' => link['responses'][200]['schema']
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def swagger
|
40
|
+
return @swagger if defined? @swagger
|
41
|
+
|
42
|
+
contents = @swagger_file.read
|
43
|
+
|
44
|
+
@swagger = begin
|
45
|
+
YAML.load(contents)
|
46
|
+
rescue
|
47
|
+
JSON.parse(contents)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'swagger2hyperschema/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'swagger2hyperschema'
|
9
|
+
spec.version = Swagger2hyperschema::VERSION
|
10
|
+
spec.authors = ['Fumiaki MATSUSHIMA']
|
11
|
+
spec.email = ['mtsmfm@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Convert swagger spec to json hyper schema'
|
14
|
+
spec.description = 'Convert swagger spec to json hyper schema'
|
15
|
+
spec.homepage = 'https://github.com/mtsmfm/swagger2hyperschema'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
25
|
+
spec.add_development_dependency 'deka_eiwakun'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swagger2hyperschema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fumiaki MATSUSHIMA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-13 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: deka_eiwakun
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Convert swagger spec to json hyper schema
|
70
|
+
email:
|
71
|
+
- mtsmfm@gmail.com
|
72
|
+
executables:
|
73
|
+
- swagger2hyperschema
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- example/simple.yml
|
86
|
+
- exe/swagger2hyperschema
|
87
|
+
- lib/swagger2hyperschema.rb
|
88
|
+
- lib/swagger2hyperschema/cli.rb
|
89
|
+
- lib/swagger2hyperschema/converter.rb
|
90
|
+
- lib/swagger2hyperschema/version.rb
|
91
|
+
- swagger2hyperschema.gemspec
|
92
|
+
homepage: https://github.com/mtsmfm/swagger2hyperschema
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Convert swagger spec to json hyper schema
|
115
|
+
test_files: []
|