json_schema_helper 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: 1fdc09fb1ad0a5dc4da0d733aafee82e09bfd08c5357f7ab30f42568e2498921
4
+ data.tar.gz: 0cefa93036d94aa306e96ce48e327a806e3b85e8b6715d62cf44be1fa311a9f9
5
+ SHA512:
6
+ metadata.gz: 5a1f34c20b2a031e4dd49394b47bb6e8e77d6ab98b9af4c0879ff0b5cb41bb8fdc98bdc6103949bb944ce62155baa0659568db75c079d4e9da449b29d01b6575
7
+ data.tar.gz: 618e2d19e0564cd71dc2992bf57943cb166c33530bb2d81b85c0b9fd1af49a6fe9fc2c8693628c2b5441d26e8e84a2122887508c4910f2321729102e5b551f2c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
+ AllCops:
12
+ TargetRubyVersion: 2.6
13
+
14
+ Metrics:
15
+ Enabled: false
16
+
17
+ Naming/FileName:
18
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in json_schema_helper.gemspec
6
+ gemspec
7
+
8
+ gem 'rubocop'
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json_schema_helper (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.3)
12
+ parallel (1.17.0)
13
+ parser (2.6.3.0)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.2)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.4)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.2)
30
+ rubocop (0.74.0)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.6)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (>= 1.4.0, < 1.7)
37
+ ruby-progressbar (1.10.1)
38
+ unicode-display_width (1.6.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 2.0)
45
+ json_schema_helper!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+ rubocop
49
+
50
+ BUNDLED WITH
51
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yoshiyuki Hirano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # JsonSchemaHelper
2
+
3
+ JsonSchemaHelper is rake tasks for openapi3.
4
+
5
+ ## Usage
6
+
7
+ See at `rake -T`
8
+
9
+ ## License
10
+
11
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
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 'json_schema_helper'
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('./lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'json_schema_helper/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'json_schema_helper'
9
+ s.version = JsonSchemaHelper::VERSION
10
+ s.authors = ['Yoshiyuki Hirano']
11
+ s.email = ['yhirano@me.com']
12
+ s.homepage = 'https://github.com/yhirano55/json_schema_helper'
13
+ s.summary = %(json schema helper)
14
+ s.description = s.summary
15
+ s.license = 'MIT'
16
+ s.files = Dir.chdir(File.expand_path('.', __dir__)) do
17
+ `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ end
21
+
22
+ s.bindir = 'exe'
23
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ s.require_paths = ['lib']
25
+
26
+ s.required_rubygems_version = '>= 1.8.11'
27
+
28
+ s.add_development_dependency 'bundler', '~> 2.0'
29
+ s.add_development_dependency 'rake', '~> 10.0'
30
+ s.add_development_dependency 'rspec', '~> 3.0'
31
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json_schema_helper/version'
4
+
5
+ begin
6
+ require 'rails'
7
+ require 'json_schema_helper/railtie'
8
+ rescue LoadError
9
+ nil
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonSchemaHelper
4
+ class Railtie < ::Rails::Railtie # :nodoc:
5
+ rake_tasks do
6
+ load 'json_schema_helper/tasks/init.rake'
7
+ load 'json_schema_helper/tasks/update.rake'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ namespace :openapi3 do
6
+ desc 'init'
7
+ task init: :environment do
8
+ FileUtils.mkdir_p Rails.root.join('docs', 'openapi3', 'paths')
9
+ FileUtils.mkdir_p Rails.root.join('docs', 'openapi3', 'components', 'parameters')
10
+ FileUtils.mkdir_p Rails.root.join('docs', 'openapi3', 'components', 'schemas')
11
+
12
+ unless File.exist?('docs/openapi3/meta.yaml')
13
+ File.open('docs/openapi3/meta.yaml', 'wb+') do |io|
14
+ io.write <<~YAML
15
+ openapi: 3.0.0
16
+
17
+ info:
18
+ version: 1.0.0
19
+ title: #{Rails.application.class.to_s.deconstantize.titleize}
20
+
21
+ servers:
22
+ - url: http://localhost:3000
23
+ YAML
24
+ end
25
+ end
26
+
27
+ if Dir['./docs/openapi3/paths/**/*.yaml'].empty?
28
+ File.open('docs/openapi3/paths/v1.yaml', 'wb+') do |io|
29
+ io.write <<~YAML
30
+ # "/v1/admin_users":
31
+ # get:
32
+ # responses:
33
+ # '200':
34
+ # content:
35
+ # application/json:
36
+ # schema:
37
+ # type: array
38
+ # items:
39
+ # "$ref": "#/components/schemas/admin_user/properties/admin_user"
40
+ # parameters:
41
+ # - name: access_token
42
+ # in: query
43
+ # schema:
44
+ # "$ref": "#/components/schemas/access_token"
45
+ YAML
46
+ end
47
+ end
48
+
49
+ if Dir['./docs/openapi3/components/parameters/**/*.yaml'].empty?
50
+ File.open('docs/openapi3/components/parameters/v1.yaml', 'wb+') do |io|
51
+ io.write <<~YAML
52
+ # v1_something__cursor:
53
+ # name: cursor
54
+ # in: query
55
+ # schema:
56
+ # nullable: true
57
+ # type: string
58
+ # format: date-time
59
+ YAML
60
+ end
61
+ end
62
+
63
+ if Dir['./docs/openapi3/components/schemas/**/*.yaml'].empty?
64
+ File.open('docs/openapi3/components/schemas/v1.yaml', 'wb+') do |io|
65
+ io.write <<~YAML
66
+ # access_token:
67
+ # type: string
68
+ #
69
+ # user_id:
70
+ # type: integer
71
+ #
72
+ # datetime:
73
+ # description: datetime
74
+ # type: string
75
+ # format: date-time
76
+ #
77
+ # nullable_datetime:
78
+ # description: datetime
79
+ # type: string
80
+ # format: date-time
81
+ # nullable: true
82
+ YAML
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :openapi3 do
4
+ desc 'combine YAML files'
5
+ task combine: :environment do
6
+ schema = {}
7
+ schema.merge! YAML.load_file(Rails.root.join('docs', 'openapi3', 'meta.yaml'))
8
+
9
+ schema['paths'] = {}
10
+
11
+ Dir[Rails.root.join('docs', 'openapi3', 'paths', '**', '*.yaml')].sort.each do |path|
12
+ $stdout.puts "merge #{path}"
13
+ schema['paths'].merge!(YAML.load_file(path) || {})
14
+ rescue StandardError => e
15
+ $stdout.puts "error #{path}: #{e.message}"
16
+ exit
17
+ end
18
+
19
+ schema['components'] = {}
20
+
21
+ schema['components']['parameters'] = {}
22
+ Dir[Rails.root.join('docs', 'openapi3', 'components', 'parameters', '**', '*.yaml')].sort.each do |path|
23
+ $stdout.puts "merge #{path}"
24
+ schema['components']['parameters'].merge!(YAML.load_file(path) || {})
25
+ rescue StandardError => e
26
+ $stdout.puts "error #{path}: #{e.message}"
27
+ exit
28
+ end
29
+
30
+ schema['components']['schemas'] = {}
31
+ Dir[Rails.root.join('docs', 'openapi3', 'components', 'schemas', '**', '*.yaml')].sort.each do |path|
32
+ $stdout.puts "merge #{path}"
33
+ schema['components']['schemas'].merge!(YAML.load_file(path) || {})
34
+ rescue StandardError => e
35
+ $stdout.puts "error #{path}: #{e.message}"
36
+ exit
37
+ end
38
+
39
+ schema['paths'] = Hash[schema['paths'].sort_by { |k, _| k }]
40
+ schema['components']['parameters'] = Hash[schema['components']['parameters'].sort_by { |k, _| k }]
41
+ schema['components']['schemas'] = Hash[schema['components']['schemas'].sort_by { |k, _| k }]
42
+
43
+ dest = Rails.root.join('docs', 'schema.yaml')
44
+
45
+ File.open(dest, 'wb+') do |io|
46
+ io.write YAML.dump(schema)
47
+ end
48
+
49
+ $stdout.puts "Update file: #{dest}"
50
+ end
51
+
52
+ desc 'verify YAML files'
53
+ task verify: :environment do
54
+ # implement later
55
+ end
56
+
57
+ desc 'update schema'
58
+ task update: %w[openapi3:verify openapi3:combine]
59
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonSchemaHelper
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_schema_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiyuki Hirano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-06 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: json schema helper
56
+ email:
57
+ - yhirano@me.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - json_schema_helper.gemspec
74
+ - lib/json_schema_helper.rb
75
+ - lib/json_schema_helper/railtie.rb
76
+ - lib/json_schema_helper/tasks/init.rake
77
+ - lib/json_schema_helper/tasks/update.rake
78
+ - lib/json_schema_helper/version.rb
79
+ homepage: https://github.com/yhirano55/json_schema_helper
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.11
97
+ requirements: []
98
+ rubygems_version: 3.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: json schema helper
102
+ test_files: []