open_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +15 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +86 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/open_api/callback.rb +22 -0
  14. data/lib/open_api/components.rb +35 -0
  15. data/lib/open_api/contact.rb +23 -0
  16. data/lib/open_api/discriminator.rb +40 -0
  17. data/lib/open_api/encoding.rb +26 -0
  18. data/lib/open_api/equatable_as_content.rb +13 -0
  19. data/lib/open_api/example.rb +24 -0
  20. data/lib/open_api/external_documentation.rb +20 -0
  21. data/lib/open_api/header.rb +42 -0
  22. data/lib/open_api/info.rb +39 -0
  23. data/lib/open_api/license.rb +20 -0
  24. data/lib/open_api/link.rb +50 -0
  25. data/lib/open_api/media_type.rb +34 -0
  26. data/lib/open_api/o_auth_flow.rb +26 -0
  27. data/lib/open_api/o_auth_flows.rb +26 -0
  28. data/lib/open_api/operation.rb +58 -0
  29. data/lib/open_api/parameter.rb +52 -0
  30. data/lib/open_api/path_item.rb +42 -0
  31. data/lib/open_api/paths.rb +26 -0
  32. data/lib/open_api/reference.rb +25 -0
  33. data/lib/open_api/request_body.rb +23 -0
  34. data/lib/open_api/response.rb +34 -0
  35. data/lib/open_api/responses.rb +34 -0
  36. data/lib/open_api/security_requirement.rb +20 -0
  37. data/lib/open_api/security_schema.rb +34 -0
  38. data/lib/open_api/serializers/yaml_serializer.rb +17 -0
  39. data/lib/open_api/serializers.rb +6 -0
  40. data/lib/open_api/server.rb +22 -0
  41. data/lib/open_api/server_variable.rb +22 -0
  42. data/lib/open_api/specification.rb +44 -0
  43. data/lib/open_api/tag.rb +24 -0
  44. data/lib/open_api/version.rb +3 -0
  45. data/lib/open_api/xml.rb +26 -0
  46. data/lib/open_api.rb +47 -0
  47. data/open_api.gemspec +30 -0
  48. metadata +174 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4dcb8f55e33a66045af98794ffb7683361538f73cfb33f5602a9979541ee772d
4
+ data.tar.gz: 2d7be42cd44216f877d533404c79ce74e8294ef2622530d0ecbd3a2e1cf21a3e
5
+ SHA512:
6
+ metadata.gz: d140ad5540fadce4e2a212fec19b40b5b2cb82094566e0dc44c1eec1a1eaa306f2cf8fe1295f09e353811412389526c309cec052221dfe97625ee263d25ea9ca
7
+ data.tar.gz: d912b8d7a8db740c79ddb5239931ff376d5f94253a086b86b5f107ee5c1cb415338a84ba4fa1a1e81766e5ac0ba511b3e4cceffb2c95558f0a9efe358337398b
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.0
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=618e64226e212a5824797037cb1a71487cdbfb3aa664bddc42a7189fb027f73a
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.4.4
8
+ - 2.5.1
9
+ before_install: gem install bundler -v 1.16.1
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -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 ngtknt@me.com. 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 open_api.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kent Nagata
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,86 @@
1
+ # OpenApi [![Build Status](https://travis-ci.org/ngtk/open_api.svg?branch=master)](https://travis-ci.org/ngtk/open_api) [![Maintainability](https://api.codeclimate.com/v1/badges/dc4713a3cb67f6edce65/maintainability)](https://codeclimate.com/github/ngtk/open_api/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/dc4713a3cb67f6edce65/test_coverage)](https://codeclimate.com/github/ngtk/open_api/test_coverage)
2
+
3
+ `open_api` provides PORO and serializers for OpenAPI and it supports OpenAPI v3.0.1.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'open_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install open_api
20
+
21
+ ## Usage
22
+ It has two use case:
23
+
24
+ 1. Serializing from PORO to yaml
25
+ 2. Deserializing yaml to PORO
26
+
27
+ ### Serializing
28
+
29
+ ```rb
30
+ spec = OpenApi::Specification.new(
31
+ openapi: "3.0.1",
32
+ info: OpenApi::Info.new(
33
+ title: "Awesome API",
34
+ description: "It provides something awesome",
35
+ version: "1.0.0",
36
+ ),
37
+ paths: OpenApi::Paths.new(
38
+ "/pets": OpenApi::PathItem.new(
39
+ get: OpenApi::Operation.new(
40
+ description: "Returns all pets from the system that the user has access to",
41
+ responses: OpenApi::Responses.new(
42
+ "200": OpenApi::Response.new(
43
+ description: "A list of pets.",
44
+ content: {
45
+ "application/json": OpenApi::MediaType.new(
46
+ schema: OpenApi::Schema.new(
47
+ type: "array",
48
+ items: OpenApi::Reference.new(ref: "#/components/schemas/pet"),
49
+ )
50
+ )
51
+ }
52
+ )
53
+ )
54
+ )
55
+ )
56
+ )
57
+ )
58
+
59
+ yaml = OpenApi::Serializers::YamlSerializer.serialize(spec)
60
+ File.write("spec.yml", yaml)
61
+ ```
62
+
63
+ ### Deserializing
64
+
65
+ ```rb
66
+ yaml = File.read("spec.yml")
67
+ spec = OpenApi::Serializers::YamlSerializer.deserialize(yaml)
68
+ ```
69
+
70
+ ## Development
71
+
72
+ 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.
73
+
74
+ 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).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ngtk/open_api. 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.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the OpenApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ngtk/open_api/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 "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,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,22 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#callback-object
3
+ class Callback
4
+ extend Forwardable
5
+
6
+ def initialize(**hash)
7
+ self.hash = hash.with_indifferent_access
8
+ end
9
+
10
+ def_delegator :hash, :[]
11
+
12
+ def self.load(hash)
13
+ return unless hash
14
+
15
+ new(**hash.symbolize_keys)
16
+ end
17
+
18
+ private
19
+
20
+ attr_accessor :hash
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module OpenApi
2
+ class Components
3
+ prepend EquatableAsContent
4
+
5
+ attr_accessor :schemas, :responses, :parameters, :examples, :request_bodies, :headers, :security_schemes, :links, :callbacks
6
+
7
+ def initialize(schemas: nil, responses: nil, parameters: nil, examples: nil, request_bodies: nil, headers: nil, security_schemes: nil, links: nil, callbacks: nil)
8
+ self.schemas = schemas
9
+ self.responses = responses
10
+ self.parameters = parameters
11
+ self.examples = examples
12
+ self.request_bodies = request_bodies
13
+ self.headers = headers
14
+ self.security_schemes = security_schemes
15
+ self.links = links
16
+ self.callbacks = callbacks
17
+ end
18
+
19
+ def self.load(hash)
20
+ return unless hash
21
+
22
+ new(
23
+ schemas: hash["schemas"]&.map { |k, v| [k, Reference.load(v) || Schema.load(v)] }.to_h,
24
+ responses: hash["responses"]&.map { |k, v| [k, Reference.load(v) || Response.load(v)] }.to_h,
25
+ parameters: hash["parameters"]&.map { |k, v| [k, Reference.load(v) || Parameter.load(v)] }.to_h,
26
+ examples: hash["examples"]&.map { |k, v| [k, Reference.load(v) || Example.load(v)] }.to_h,
27
+ request_bodies: hash["requestBodies"]&.map { |k, v| [k, Reference.load(v) || RequestBody.load(v)] }.to_h,
28
+ headers: hash["headers"]&.map { |k, v| [k, Reference.load(v) || Header.load(v)] }.to_h,
29
+ security_schemes: hash["securitySchemes"]&.map { |k, v| [k, Reference.load(v) || SecuritySchema.load(v)] }.to_h,
30
+ links: hash["links"]&.map { |k, v| [k, Reference.load(v) || Link.load(v)] }.to_h,
31
+ callbacks: hash["callbacks"]&.map { |k, v| [k, Reference.load(v) || Callback.load(v)] }.to_h,
32
+ )
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#contactObject
3
+ class Contact
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :name, :url, :email
7
+
8
+ def initialize(name: nil, url: nil, email: nil)
9
+ self.name = name
10
+ self.url = url
11
+ self.email = email
12
+ end
13
+
14
+ def self.load(hash)
15
+ return unless hash
16
+ new(
17
+ name: hash["name"]&.to_s,
18
+ url: hash["url"]&.to_s,
19
+ email: hash["email"]&.to_s,
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#discriminatorObject
3
+ class Discriminator
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :property_name, :mapping
7
+
8
+ def initialize(property_name: nil, mapping: {}, **other_fields_hash)
9
+ self.property_name = property_name
10
+ self.mapping = mapping.with_indifferent_access
11
+ self.other_fields_hash = other_fields_hash
12
+
13
+ other_fields_hash.keys.each do |field_name|
14
+ define_singleton_method(field_name) do
15
+ other_fields_hash[field_name]
16
+ end
17
+ define_singleton_method("#{field_name}=") do |value|
18
+ other_fields_hash[field_name] = value
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.load(hash)
24
+ return unless hash
25
+
26
+ fixed_field_names = %w(propertyName mapping)
27
+ other_fields_hash = hash.reject { |key| key.to_s.in?(fixed_field_names) }
28
+
29
+ new(
30
+ property_name: hash["propertyName"].to_s,
31
+ mapping: hash["mapping"],
32
+ **other_fields_hash.symbolize_keys,
33
+ )
34
+ end
35
+
36
+ private
37
+
38
+ attr_accessor :other_fields_hash
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#encodingObject
3
+ class Encoding
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :content_type, :headers, :style, :explode, :allow_reserved
7
+
8
+ def initialize(content_type: nil, headers: nil, style: nil, explode: nil, allow_reserved: false)
9
+ self.content_type = content_type
10
+ self.headers = headers
11
+ self.style = style
12
+ self.explode = explode
13
+ self.allow_reserved = allow_reserved
14
+ end
15
+
16
+ def self.load(hash)
17
+ new(
18
+ content_type: hash["contentType"]&.to_s,
19
+ headers: hash["headers"]&.map { |k, v| [k, Reference.load(v) || Header.load(v)] }.to_h,
20
+ style: hash["style"]&.to_s,
21
+ explode: hash["explode"],
22
+ allow_reserved: hash["allowReserved"].nil? ? false : hash["allowReserved"],
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module OpenApi
2
+ module EquatableAsContent
3
+ def ==(other)
4
+ self.all_instance_variables == other.all_instance_variables
5
+ end
6
+
7
+ protected
8
+
9
+ def all_instance_variables
10
+ instance_variables.map { |name| instance_variable_get(name) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#exampleObject
3
+ class Example
4
+ attr_accessor :summary, :description, :value, :external_value
5
+
6
+ def initialize(summary: nil, description: nil, value: nil, external_value: nil)
7
+ self.summary = summary
8
+ self.description = description
9
+ self.value = value
10
+ self.external_value = external_value
11
+ end
12
+
13
+ def self.load(hash)
14
+ return unless hash
15
+
16
+ new(
17
+ summary: hash["summary"]&.to_s,
18
+ description: hash["description"]&.to_s,
19
+ value: hash["value"],
20
+ external_value: hash["externalValue"],
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#externalDocumentationObject
3
+ class ExternalDocumentation
4
+ attr_accessor :description, :url
5
+
6
+ def initialize(description: nil, url:)
7
+ self.description = description
8
+ self.url = url
9
+ end
10
+
11
+ def self.load(hash)
12
+ return unless hash
13
+
14
+ new(
15
+ description: hash["description"]&.to_s,
16
+ url: hash["url"].to_s,
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#header-object
3
+ class Header
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :description, :required, :deprecated, :allow_empty_value
7
+
8
+ def initialize(description: nil, required: false, deprecated: nil, allow_empty_value: false, **other_fields_hash)
9
+ self.description = description
10
+ self.required = required
11
+ self.deprecated = deprecated
12
+ self.allow_empty_value = allow_empty_value
13
+ self.other_fields_hash = other_fields_hash.with_indifferent_access
14
+
15
+ other_fields_hash.keys.each do |field_name|
16
+ define_singleton_method(field_name) do
17
+ other_fields_hash[field_name]
18
+ end
19
+ define_singleton_method("#{field_name}=") do |value|
20
+ other_fields_hash[field_name] = value
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.load(hash)
26
+ fixed_field_names = [:description, :required, :deprecated, :allowEmptyValue]
27
+ other_fields_hash = hash.reject { |key| key.to_sym.in?(fixed_field_names) }
28
+
29
+ new(
30
+ description: hash["description"],
31
+ required: hash["required"].nil? ? false : hash["required"],
32
+ deprecated: hash["deprecated"].nil? ? false : hash["deprecated"],
33
+ allow_empty_value: hash["allowEmptyValue"].nil? ? false : hash["allowEmptyValue"],
34
+ **other_fields_hash.symbolize_keys,
35
+ )
36
+ end
37
+
38
+ private
39
+
40
+ attr_accessor :other_fields_hash
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#info-object
3
+ class Info
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :title, :description, :terms_of_service, :contact, :license, :version
7
+
8
+ def initialize(title:, description: nil, terms_of_service: nil, contact: nil, license: nil, version:)
9
+ self.title = title
10
+ self.description = description
11
+ self.terms_of_service = terms_of_service
12
+ self.contact = contact
13
+ self.license = license
14
+ self.version = version
15
+ end
16
+
17
+ def serializable_hash
18
+ {
19
+ "title" => title.to_s,
20
+ "description" => description&.to_s,
21
+ "termsOfService" => terms_of_service&.to_s,
22
+ "contact" => contact&.serializable_hash,
23
+ "license" => license&.serializable_hash,
24
+ "version" => version.to_s,
25
+ }.compact
26
+ end
27
+
28
+ def self.load(hash)
29
+ new(
30
+ title: hash["title"].to_s,
31
+ description: hash["description"]&.to_s,
32
+ terms_of_service: hash["termsOfService"]&.to_s,
33
+ contact: Contact.load(hash["contact"]),
34
+ license: License.load(hash["license"]),
35
+ version: hash["version"].to_s,
36
+ )
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#license-object
3
+ class License
4
+ attr_accessor :name, :url
5
+
6
+ def initialize(name:, url: nil)
7
+ self.name = name
8
+ self.url = url
9
+ end
10
+
11
+ def self.load(hash)
12
+ return unless hash
13
+
14
+ new(
15
+ name: hash["name"],
16
+ url: hash["url"],
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ module OpenApi
2
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#link-object
3
+ class Link
4
+ prepend EquatableAsContent
5
+
6
+ attr_accessor :operation_ref, :operation_id, :parameters, :request_body, :description, :server
7
+
8
+ def initialize(operation_ref: nil, operation_id: nil, parameters: nil, request_body: nil, description: nil, server: nil, **other_fields_hash)
9
+ self.operation_ref = operation_ref
10
+ self.operation_id = operation_id
11
+ self.parameters = parameters
12
+ self.request_body = request_body
13
+ self.description = description
14
+ self.server = server
15
+ self.other_fields_hash = other_fields_hash.with_indifferent_access
16
+
17
+ other_fields_hash.keys.each do |field_name|
18
+ define_singleton_method(field_name) do
19
+ other_fields_hash[field_name]
20
+ end
21
+ define_singleton_method("#{field_name}=") do |value|
22
+ other_fields_hash[field_name] = value
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.load(hash)
28
+ return unless hash
29
+
30
+ fixed_field_names = [:operationRef, :operationId, :parameters, :requestBody, :description, :server]
31
+ other_fields_hash = hash.reject { |key|
32
+ key.to_sym.in?(fixed_field_names)
33
+ }.symbolize_keys
34
+
35
+ new(
36
+ operation_ref: hash["operationRef"]&.to_s,
37
+ operation_id: hash["operationId"]&.to_s,
38
+ parameters: hash["parameters"],
39
+ request_body: RequestBody.load(hash["requestBody"]),
40
+ description: hash["description"]&.to_s,
41
+ server: Server.load(hash["server"]),
42
+ **other_fields_hash,
43
+ )
44
+ end
45
+
46
+ private
47
+
48
+ attr_accessor :other_fields_hash
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ module OpenApi
2
+ class MediaType
3
+ prepend EquatableAsContent
4
+
5
+ attr_accessor :schema, :example, :examples, :encoding
6
+
7
+ def initialize(schema: nil, example: nil, examples: nil, encoding: nil)
8
+ self.schema = schema
9
+ self.example = example
10
+ self.examples = examples
11
+ self.encoding = encoding
12
+ end
13
+
14
+ def serializable_hash
15
+ {
16
+ "schema" => schema&.serializable_hash,
17
+ "example" => example,
18
+ "examples" => examples&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_hash,
19
+ "encoding" => encoding&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_hash,
20
+ }.compact
21
+ end
22
+
23
+ def self.load(hash)
24
+ return unless hash
25
+
26
+ new(
27
+ schema: Reference.load(hash["schema"]) || Schema.load(hash["schema"]),
28
+ example: hash["example"],
29
+ examples: hash["examples"]&.map { |k, v| [k, Reference.load(v) || Example.load(v)] }&.to_h,
30
+ encoding: hash["encoding"]&.map { |k, v| [k, Encoding.load(v)] }&.to_h
31
+ )
32
+ end
33
+ end
34
+ end