yori 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +14 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +15 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +7 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +35 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +44 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/yori.rb +16 -0
  17. data/lib/yori/errors/field_must_not_be_specified_error.rb +5 -0
  18. data/lib/yori/errors/invalid_schema_error.rb +5 -0
  19. data/lib/yori/errors/missing_required_field_error.rb +5 -0
  20. data/lib/yori/errors/unknown_component_error.rb +7 -0
  21. data/lib/yori/schema/any.rb +22 -0
  22. data/lib/yori/schema/v3.rb +10 -0
  23. data/lib/yori/schema/v3/callback.rb +15 -0
  24. data/lib/yori/schema/v3/components.rb +70 -0
  25. data/lib/yori/schema/v3/composer.rb +36 -0
  26. data/lib/yori/schema/v3/contact.rb +15 -0
  27. data/lib/yori/schema/v3/discriminator.rb +25 -0
  28. data/lib/yori/schema/v3/encoding.rb +33 -0
  29. data/lib/yori/schema/v3/example.rb +20 -0
  30. data/lib/yori/schema/v3/external_documentation.rb +18 -0
  31. data/lib/yori/schema/v3/header.rb +32 -0
  32. data/lib/yori/schema/v3/info.rb +27 -0
  33. data/lib/yori/schema/v3/license.rb +18 -0
  34. data/lib/yori/schema/v3/link.rb +46 -0
  35. data/lib/yori/schema/v3/media_type.rb +35 -0
  36. data/lib/yori/schema/v3/oauth_flow.rb +35 -0
  37. data/lib/yori/schema/v3/oauth_flows.rb +51 -0
  38. data/lib/yori/schema/v3/openapi.rb +61 -0
  39. data/lib/yori/schema/v3/operation.rb +72 -0
  40. data/lib/yori/schema/v3/parameter.rb +63 -0
  41. data/lib/yori/schema/v3/path_item.rb +47 -0
  42. data/lib/yori/schema/v3/paths.rb +44 -0
  43. data/lib/yori/schema/v3/request_body.rb +27 -0
  44. data/lib/yori/schema/v3/response.rb +34 -0
  45. data/lib/yori/schema/v3/responses.rb +42 -0
  46. data/lib/yori/schema/v3/root.rb +40 -0
  47. data/lib/yori/schema/v3/schema.rb +35 -0
  48. data/lib/yori/schema/v3/security_requirement.rb +23 -0
  49. data/lib/yori/schema/v3/security_scheme.rb +93 -0
  50. data/lib/yori/schema/v3/server.rb +24 -0
  51. data/lib/yori/schema/v3/server_variable.rb +25 -0
  52. data/lib/yori/schema/v3/tag.rb +28 -0
  53. data/lib/yori/schema/v3/xml.rb +28 -0
  54. data/lib/yori/schema_base.rb +110 -0
  55. data/lib/yori/schema_validator.rb +40 -0
  56. data/lib/yori/version.rb +3 -0
  57. data/yori.gemspec +44 -0
  58. metadata +142 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f29b178020df0e824044f5e9eda902f67379c843
4
+ data.tar.gz: 18987a92df28fd7d5d95e1b95f91d31f6d97ac06
5
+ SHA512:
6
+ metadata.gz: 94547a7548d63686ed2ab5121fab368b9deaae1839b0315d0879753e5114bd37b2d33999229e866fdbbdfcd937a486978c4332ced506df734f43a82317c4fad5
7
+ data.tar.gz: e14a4fb524e4745b39b35d747f9a7f5a4a794601e214483efa533c23bc580ec5c669cdd9c874dc5f92a7bbdff726f66747695ecd6e46847a4a82bc78e361d186
data/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # EditorConfig
2
+ root = true
3
+
4
+ [{*.rb,*.ru,*.erb,*.slim,*.rake}]
5
+ indent_size = 2
6
+ indent_style = space
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+
10
+ [{*.js,*.jsx,*.ts,*.tsx,*.css,*.scss}]
11
+ indent_size = 4
12
+ indent_style = space
13
+ trim_trailing_whitespace = true
14
+ insert_final_newline = true
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,15 @@
1
+ Metrics/LineLength:
2
+ Max: 200
3
+
4
+ Style/StringLiterals:
5
+ Enabled: false
6
+
7
+ Metrics/AbcSize:
8
+ Max: 20
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - spec/**/*.rb
13
+
14
+ Metrics/MethodLength:
15
+ Max: 20
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nakakuki.shingo@vareal.co.jp. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in yori.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yori (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ yori!
33
+
34
+ BUNDLED WITH
35
+ 1.16.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 nakakuki-shingo
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,44 @@
1
+ # Yori
2
+
3
+ **Y**et another **O**penAPI **R**uby **I**mplementation.
4
+
5
+ Inspired by [Swagger::Blocks](https://github.com/fotinakis/swagger-blocks). Supports only OpenAPI V3 or newer.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yori'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yori
22
+
23
+ ## Usage
24
+
25
+ See also [Wiki](https://github.com/yiyenene/yori/wiki).
26
+ Sorry, now under construction...
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yiyenene/yori. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Yori project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yiyenene/yori/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yori"
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,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
data/lib/yori.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "yori/version"
2
+ require 'yori/schema_validator'
3
+ require "yori/schema_base"
4
+ require "yori/schema/any"
5
+
6
+ Dir[File.dirname(__FILE__) + '/yori/errors/*.rb'].each { |f| require f }
7
+
8
+ # Yori: Yet another Openapi Ruby Implementation
9
+ module Yori
10
+ class << self
11
+ def v3
12
+ require 'yori/schema/v3'
13
+ Yori::Schema::V3
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Yori
2
+ module Errors
3
+ class FieldMustNotBeSpecifiedError < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Yori
2
+ module Errors
3
+ class InvalidSchemaError < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Yori
2
+ module Errors
3
+ class MissingRequiredFieldError < InvalidSchemaError; end
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yori
4
+ module Errors
5
+ class UnknownComponentError < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yori
4
+ module Schema
5
+ # Any: supports any keyword as dsl.
6
+ class Any < Yori::SchemaBase
7
+ def respond_to_missing?(*)
8
+ true
9
+ end
10
+
11
+ def method_missing(name, *args, &block)
12
+ arg = args.first
13
+ if arg || block_given?
14
+ c = self.class.eval_input!(self.class, id, arg, &block)
15
+ self[name.to_s] = c
16
+ return self
17
+ end
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yori
4
+ module Schema
5
+ # OpenApi version 3.0.0
6
+ module V3
7
+ Dir[File.dirname(__FILE__) + '/v3/*.rb'].each { |f| require f }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yori
4
+ module Schema
5
+ module V3
6
+ # Callback
7
+ # A map of possible out-of band callbacks related to the parent operation.
8
+ # Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses.
9
+ # The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
10
+ class Callback < Yori::SchemaBase
11
+ # defined at PathItem to avoid circular reference.
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yori/schema/v3/schema'
4
+ require 'yori/schema/v3/response'
5
+ require 'yori/schema/v3/parameter'
6
+ require 'yori/schema/v3/example'
7
+ require 'yori/schema/v3/request_body'
8
+ require 'yori/schema/v3/header'
9
+ require 'yori/schema/v3/security_scheme'
10
+ require 'yori/schema/v3/link'
11
+ require 'yori/schema/v3/callback'
12
+
13
+ module Yori
14
+ module Schema
15
+ module V3
16
+ # Components
17
+ # Holds a set of reusable objects for different aspects of the OAS.
18
+ # All objects defined within the components object will have no effect on the API
19
+ # unless they are explicitly referenced from properties outside the components object.
20
+ class Components < Yori::SchemaBase
21
+ # @!method schemas An object to hold reusable Schema Objects.
22
+ hash_field_block :schemas, :schema, Yori::Schema::V3::Schema
23
+ # @!method responses An object to hold reusable Response Objects.
24
+ hash_field_block :responses, :response, Yori::Schema::V3::Response
25
+ # @!method parameters An object to hold reusable Parameter Objects.
26
+ hash_field_block :parameters, :parameter, Yori::Schema::V3::Parameter
27
+ # @!method examples An object to hold reusable Example Objects.
28
+ hash_field_block :examples, :example, Yori::Schema::V3::Example
29
+ # @!method requestBodies An object to hold reusable Request Body Objects.
30
+ hash_field_block :requestBodies, :requestBody, Yori::Schema::V3::RequestBody
31
+ # @!method headers An object to hold reusable Header Objects.
32
+ hash_field_block :headers, :header, Yori::Schema::V3::Header
33
+ # @!method securitySchemes An object to hold reusable Security Scheme Objects.
34
+ hash_field_block :securitySchemes, :securityScheme, Yori::Schema::V3::SecurityScheme
35
+ # @!method links An object to hold reusable Link Objects.
36
+ hash_field_block :links, :link, Yori::Schema::V3::Link
37
+ # @!method callbacks An object to hold reusable Callback Objects.
38
+ hash_field_block :callbacks, :callback, Yori::Schema::V3::Callback
39
+
40
+ def merge_registered!
41
+ components ||= self.class.registered_components[id]
42
+ components.flat_map { |_component, procs| procs.values }
43
+ .each do |block|
44
+ instance_eval(&block)
45
+ end
46
+ end
47
+
48
+ VALID_COMPONENTS = %w[schema response parameter example requestBody header securityScheme link callback].freeze
49
+
50
+ def check_and_send!(component, key, value, &block)
51
+ raise Yori::Errors::UnknownComponentError, "Unknown component: #{component}" unless VALID_COMPONENTS.include?(component.to_s)
52
+ send(component, key, value, &block)
53
+ end
54
+
55
+ class << self
56
+ def registered_components
57
+ @registered_components ||= {}
58
+ end
59
+
60
+ def register_component(id, component, key, value = nil, &block)
61
+ @registered_components ||= {}
62
+ @registered_components[id] ||= {}
63
+ @registered_components[id][component.to_s] ||= {}
64
+ @registered_components[id][component.to_s][key.to_s] = proc { check_and_send!(component, key, value, &block) }
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end