openapi3_definition_generator-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01ef57221283427bc3b5d85dbf6b79bfc199ff04546e2853928dd0831c3f4186
4
+ data.tar.gz: 629ea8f06cdf55a397f4a0a189cb0e425d91501967f24e3e7c1f4a0f93279ed9
5
+ SHA512:
6
+ metadata.gz: 4931b18f71044b964d1cbdaeb675f05393e5189944670c37da922fdeec95a26ec1a934da84537f241edf076d5d101c746d323a0a85b35b6b2a21b23f3ecd0ed8
7
+ data.tar.gz: a0bf0ce7b226cb3cc33423b83e050d0f8e6a3c3aa5cb31065c9e7da10e425673c611d19519f3e542f614026ded6a39bf84c41a2ebb1f01c8b2b1af95c29a4537
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Yusuke Nakamura
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Openapi3DefinitionGenerator::Rails
2
+ [![CircleCI](https://circleci.com/gh/unasuke/openapi3_definition_generator-rails.svg?style=svg)](https://circleci.com/gh/unasuke/openapi3_definition_generator-rails)
3
+
4
+ Generate minimum OpenAPI 3 definition YAML from `config/routes.rb` in your Rails application.
5
+
6
+ :warning: This gem uses Rails private API so may be broken in future.
7
+
8
+ ## Usage
9
+ How to use my plugin.
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'openapi3_definition_generator-rails'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```bash
21
+ $ bin/rails openapi3_definition:generate_yaml
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Openapi3DefinitionGenerator::Rails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,7 @@
1
+ require "openapi3_definition_generator/rails/railtie"
2
+
3
+ module Openapi3DefinitionGenerator
4
+ module Rails
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ require 'action_dispatch/routing/inspector'
2
+ require 'yaml'
3
+
4
+ module ActionDispatch
5
+ module Routing
6
+ class OpenAPI3Formatter
7
+ def initialize()
8
+ @view = nil
9
+ @buffer = []
10
+ @openapi_structute = {
11
+ 'openapi' => '3.0.0',
12
+ 'info' => {
13
+ 'title' => '',
14
+ 'description' => '',
15
+ 'version' => '0.1.0'
16
+ },
17
+ 'paths' => {}
18
+ }
19
+ end
20
+
21
+ def section_title(title)
22
+ end
23
+
24
+ def section(routes)
25
+ routes.filter do |r|
26
+ !r[:verb].empty?
27
+ end.each do |r|
28
+ @openapi_structute['paths'][r[:path]] ||= {}
29
+ @openapi_structute['paths'][r[:path]][r[:verb].downcase] = {}
30
+ @openapi_structute['paths'][r[:path]][r[:verb].downcase] = {
31
+ 'summary' => r[:name],
32
+ 'description' => r[:reqs],
33
+ 'responses' => nil
34
+ }
35
+ end
36
+ end
37
+
38
+ def header(routes)
39
+ end
40
+
41
+ def no_routes(*)
42
+ end
43
+
44
+ def result
45
+ YAML.dump @openapi_structute
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ module Openapi3DefinitionGenerator
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ rake_tasks do
5
+ load 'tasks/openapi3_definition_generator/rails_tasks.rake'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Openapi3DefinitionGenerator
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :openapi3_definition do
4
+ desc 'Generate OpenAPI3 definition YAML from condig/routes.rb'
5
+ task generate_yaml: :environment do
6
+ require 'action_dispatch/routing/inspector'
7
+ require 'openapi3_definition_generator/rails/openapi3_formatter'
8
+
9
+ inspector = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
10
+
11
+ puts inspector.format(ActionDispatch::Routing::OpenAPI3Formatter.new, nil)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openapi3_definition_generator-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.3
27
+ description: Generate minimum OpenAPI 3 definition YAML from config/routes.rb in your
28
+ Rails application.
29
+ email:
30
+ - yusuke1994525@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/openapi3_definition_generator/rails.rb
39
+ - lib/openapi3_definition_generator/rails/openapi3_formatter.rb
40
+ - lib/openapi3_definition_generator/rails/railtie.rb
41
+ - lib/openapi3_definition_generator/rails/version.rb
42
+ - lib/tasks/openapi3_definition_generator/rails_tasks.rake
43
+ homepage: https://github.com/unasuke/openapi3_definition_generator-rails
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Generate minimum OpenAPI 3 definition YAML from config/routes.rb in your
66
+ Rails application.
67
+ test_files: []