open_api 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 +13 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +15 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/open_api/callback.rb +22 -0
- data/lib/open_api/components.rb +35 -0
- data/lib/open_api/contact.rb +23 -0
- data/lib/open_api/discriminator.rb +40 -0
- data/lib/open_api/encoding.rb +26 -0
- data/lib/open_api/equatable_as_content.rb +13 -0
- data/lib/open_api/example.rb +24 -0
- data/lib/open_api/external_documentation.rb +20 -0
- data/lib/open_api/header.rb +42 -0
- data/lib/open_api/info.rb +39 -0
- data/lib/open_api/license.rb +20 -0
- data/lib/open_api/link.rb +50 -0
- data/lib/open_api/media_type.rb +34 -0
- data/lib/open_api/o_auth_flow.rb +26 -0
- data/lib/open_api/o_auth_flows.rb +26 -0
- data/lib/open_api/operation.rb +58 -0
- data/lib/open_api/parameter.rb +52 -0
- data/lib/open_api/path_item.rb +42 -0
- data/lib/open_api/paths.rb +26 -0
- data/lib/open_api/reference.rb +25 -0
- data/lib/open_api/request_body.rb +23 -0
- data/lib/open_api/response.rb +34 -0
- data/lib/open_api/responses.rb +34 -0
- data/lib/open_api/security_requirement.rb +20 -0
- data/lib/open_api/security_schema.rb +34 -0
- data/lib/open_api/serializers/yaml_serializer.rb +17 -0
- data/lib/open_api/serializers.rb +6 -0
- data/lib/open_api/server.rb +22 -0
- data/lib/open_api/server_variable.rb +22 -0
- data/lib/open_api/specification.rb +44 -0
- data/lib/open_api/tag.rb +24 -0
- data/lib/open_api/version.rb +3 -0
- data/lib/open_api/xml.rb +26 -0
- data/lib/open_api.rb +47 -0
- data/open_api.gemspec +30 -0
- metadata +174 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oauthFlowObject
|
3
|
+
class OAuthFlow
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :authorization_url, :token_url, :refresh_url ,:scopes
|
7
|
+
|
8
|
+
def initialize(authorization_url:, token_url:, refresh_url: nil, scopes:)
|
9
|
+
self.authorization_url = authorization_url
|
10
|
+
self.token_url = token_url
|
11
|
+
self.refresh_url = refresh_url
|
12
|
+
self.scopes = scopes.with_indifferent_access
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load(hash)
|
16
|
+
return unless hash
|
17
|
+
|
18
|
+
new(
|
19
|
+
authorization_url: hash["authorizationUrl"],
|
20
|
+
token_url: hash["tokenUrl"],
|
21
|
+
refresh_url: hash["refreshUrl"],
|
22
|
+
scopes: hash["scopes"],
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oauth-flows-object
|
3
|
+
class OAuthFlows
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :implicit, :password, :client_credentials, :authorization_code
|
7
|
+
|
8
|
+
def initialize(implicit: nil, password: nil, client_credentials: nil, authorization_code: nil)
|
9
|
+
self.implicit = implicit
|
10
|
+
self.password = password
|
11
|
+
self.client_credentials = client_credentials
|
12
|
+
self.authorization_code = authorization_code
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load(hash)
|
16
|
+
return unless hash
|
17
|
+
|
18
|
+
new(
|
19
|
+
implicit: OAuthFlow.load(hash["implicit"]),
|
20
|
+
password: OAuthFlow.load(hash["password"]),
|
21
|
+
client_credentials: OAuthFlow.load(hash["clientCredentials"]),
|
22
|
+
authorization_code: OAuthFlow.load(hash["authorizationCode"]),
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module OpenApi
|
2
|
+
class Operation
|
3
|
+
prepend EquatableAsContent
|
4
|
+
|
5
|
+
attr_accessor :tags, :summary, :description, :external_docs, :operation_id, :parameters, :request_body, :responses, :callbacks, :deprecated, :security, :servers
|
6
|
+
|
7
|
+
def initialize(responses:, tags: nil, summary: nil, description: nil, external_docs: nil, operation_id: nil, parameters: nil, request_body: nil, callbacks: nil, deprecated: nil, security: nil, servers: nil)
|
8
|
+
self.responses = responses
|
9
|
+
self.tags = tags
|
10
|
+
self.summary = summary
|
11
|
+
self.description = description
|
12
|
+
self.external_docs = external_docs
|
13
|
+
self.operation_id = operation_id
|
14
|
+
self.parameters = parameters
|
15
|
+
self.request_body = request_body
|
16
|
+
self.callbacks = callbacks
|
17
|
+
self.deprecated = deprecated
|
18
|
+
self.security = security
|
19
|
+
self.servers = servers
|
20
|
+
end
|
21
|
+
|
22
|
+
def serializable_hash
|
23
|
+
{
|
24
|
+
"description" => description&.to_s,
|
25
|
+
"responses" => responses.serializable_hash,
|
26
|
+
"tags" => tags&.map(&:to_s),
|
27
|
+
"summary" => summary&.to_s,
|
28
|
+
"externalDocs" => external_docs&.serializable_hash,
|
29
|
+
"operationId" => operation_id&.to_s,
|
30
|
+
"parameters" => parameters&.map(&:serializable_hash),
|
31
|
+
"requestBody" => request_body&.serializable_hash,
|
32
|
+
"callbacks" => callbacks&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_hash,
|
33
|
+
"deprecated" => deprecated,
|
34
|
+
"security" => security&.map(&:serializable_hash),
|
35
|
+
"servers" => servers&.map(&:server),
|
36
|
+
}.compact
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load(hash)
|
40
|
+
return unless hash
|
41
|
+
|
42
|
+
new(
|
43
|
+
responses: Responses.load(hash["responses"]),
|
44
|
+
tags: hash["tags"],
|
45
|
+
summary: hash["summary"]&.to_s,
|
46
|
+
description: hash["description"]&.to_s,
|
47
|
+
external_docs: ExternalDocumentation.load(hash["externalDocs"]),
|
48
|
+
operation_id: hash["operationId"]&.to_s,
|
49
|
+
parameters: hash["parameters"]&.map { |h| Reference.load(h) || Parameter.load(h) },
|
50
|
+
request_body: Reference.load(hash["requestBody"]) || RequestBody.load(hash["requestBody"]),
|
51
|
+
callbacks: hash["callbacks"]&.map { |k, v| [k, Reference.load(v) || Callback.load(v)] }&.to_h,
|
52
|
+
deprecated: hash["deprecated"],
|
53
|
+
security: hash["security"]&.map { |h| SecurityRequirement.load(h) },
|
54
|
+
servers: hash["servers"]&.map { |h| Server.load(h) },
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#parameterObject
|
3
|
+
class Parameter
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :name, :in, :description, :required, :deprecated, :allow_empty_value
|
7
|
+
|
8
|
+
def initialize(name:, in:, description: nil, required: nil, deprecated: nil, allow_empty_value: nil, **other_fields_hash)
|
9
|
+
self.name = name
|
10
|
+
self.in = binding.local_variable_get(:in) # `in` is reserved keyword
|
11
|
+
self.required = required
|
12
|
+
self.deprecated = deprecated
|
13
|
+
self.allow_empty_value = allow_empty_value
|
14
|
+
self.other_fields_hash = other_fields_hash.with_indifferent_access
|
15
|
+
|
16
|
+
other_fields_hash.keys.each do |key|
|
17
|
+
define_singleton_method(key) do
|
18
|
+
other_fields_hash[key]
|
19
|
+
end
|
20
|
+
define_singleton_method("#{key}=") do |value|
|
21
|
+
other_fields_hash[key] = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.load(hash)
|
27
|
+
other_fields_hash = hash.reject { |key|
|
28
|
+
key.to_sym.in?([:name, :in, :description, :required, :deprecated, :allow_empty_value])
|
29
|
+
}.symbolize_keys.map { |k, v|
|
30
|
+
value =
|
31
|
+
case k
|
32
|
+
when :schema then Schema.load(v)
|
33
|
+
end
|
34
|
+
[k, value]
|
35
|
+
}.to_h
|
36
|
+
|
37
|
+
new(
|
38
|
+
name: hash["name"].to_s,
|
39
|
+
in: hash["in"].to_s,
|
40
|
+
description: hash["description"]&.to_s,
|
41
|
+
required: hash["required"],
|
42
|
+
deprecated: hash["deprecated"],
|
43
|
+
allow_empty_value: hash["allowEmptyValue"],
|
44
|
+
**other_fields_hash,
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_accessor :other_fields_hash
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#path-item-object
|
3
|
+
class PathItem
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :ref, :summary, :description, :servers, :parameters, :operations
|
7
|
+
|
8
|
+
OPERATION_NAMES = [:get, :put, :post, :delete, :options, :head, :patch, :trace]
|
9
|
+
|
10
|
+
def initialize(ref: nil, summary: nil, description: nil, servers: nil, parameters: nil, **operations)
|
11
|
+
self.ref = ref
|
12
|
+
self.summary = summary
|
13
|
+
self.description = description
|
14
|
+
self.servers = servers
|
15
|
+
self.parameters = parameters
|
16
|
+
self.operations = operations.with_indifferent_access
|
17
|
+
end
|
18
|
+
|
19
|
+
def serializable_hash
|
20
|
+
{
|
21
|
+
"ref" => ref&.to_s,
|
22
|
+
"summary" => summary&.to_s,
|
23
|
+
"description" => description&.to_s,
|
24
|
+
"servers" => servers&.map(&:serializable_hash),
|
25
|
+
"parameters" => parameters&.map(&:serializable_hash),
|
26
|
+
}.merge(operations.map { |k, v| [k.to_s, v.serializable_hash] }.to_h)
|
27
|
+
.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load(hash)
|
31
|
+
operations = hash.select { |key| key.to_sym.in?(OPERATION_NAMES) }
|
32
|
+
new(
|
33
|
+
ref: hash["$ref"]&.to_s,
|
34
|
+
summary: hash["summary"]&.to_s,
|
35
|
+
description: hash["description"]&.to_s,
|
36
|
+
servers: hash["servers"]&.map { |server_hash| Server.load(server_hash) },
|
37
|
+
parameters: hash["parameters"]&.map { |h| Reference.load(h) || Parameter.load(h) },
|
38
|
+
**operations.map { |k ,v| [k.to_sym, Operation.load(v)] }.to_h,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#pathsObject
|
3
|
+
class Paths
|
4
|
+
extend Forwardable
|
5
|
+
prepend EquatableAsContent
|
6
|
+
|
7
|
+
def initialize(**path_hash)
|
8
|
+
self.path_hash = path_hash.with_indifferent_access
|
9
|
+
end
|
10
|
+
|
11
|
+
def_delegator :path_hash, :[]
|
12
|
+
|
13
|
+
def self.load(hash)
|
14
|
+
hash = hash.map { |k, v| [k.to_sym, PathItem.load(v)] }.to_h
|
15
|
+
new(**hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
def serializable_hash
|
19
|
+
path_hash.map { |k, v| [k.to_s, v.serializable_hash] }.to_h
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_accessor :path_hash
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#referenceObject
|
3
|
+
class Reference
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :ref
|
7
|
+
|
8
|
+
def initialize(ref:)
|
9
|
+
self.ref = ref
|
10
|
+
end
|
11
|
+
|
12
|
+
def serializable_hash
|
13
|
+
{
|
14
|
+
"$ref" => ref.to_s,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load(hash)
|
19
|
+
return unless hash
|
20
|
+
return unless hash["$ref"]
|
21
|
+
|
22
|
+
new(ref: hash["$ref"])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OpenApi
|
2
|
+
class RequestBody
|
3
|
+
prepend EquatableAsContent
|
4
|
+
|
5
|
+
attr_accessor :description, :content, :required
|
6
|
+
|
7
|
+
def initialize(description: nil, content:, required: false)
|
8
|
+
self.description = description
|
9
|
+
self.content = content.with_indifferent_access
|
10
|
+
self.required = required
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load(hash)
|
14
|
+
return unless hash
|
15
|
+
|
16
|
+
new(
|
17
|
+
description: hash["description"]&.to_s,
|
18
|
+
content: hash["content"].map { |k, v| [k, MediaType.load(v)] }.to_h,
|
19
|
+
required: hash["required"].nil? ? false : hash["required"]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OpenApi
|
2
|
+
class Response
|
3
|
+
prepend EquatableAsContent
|
4
|
+
|
5
|
+
attr_accessor :description, :headers, :content, :links
|
6
|
+
|
7
|
+
def initialize(description:, headers: nil, content: nil, links: nil)
|
8
|
+
self.description = description
|
9
|
+
self.headers = headers&.with_indifferent_access
|
10
|
+
self.content = content&.with_indifferent_access
|
11
|
+
self.links = links&.with_indifferent_access
|
12
|
+
end
|
13
|
+
|
14
|
+
def serializable_hash
|
15
|
+
{
|
16
|
+
"description" => description.to_s,
|
17
|
+
"headers" => headers&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
|
18
|
+
"content" => content&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
|
19
|
+
"links" => links&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
|
20
|
+
}.compact
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load(hash)
|
24
|
+
return unless hash
|
25
|
+
|
26
|
+
new(
|
27
|
+
description: hash["description"].to_s,
|
28
|
+
headers: hash["headers"]&.map { |k, v| [k, Header.load(v)] }&.to_h,
|
29
|
+
content: hash["content"]&.map { |k, v| [k, MediaType.load(v)] }&.to_h,
|
30
|
+
links: hash["links"]&.map { |k, v| [k, Reference.load(v) || Link.load(v)] }&.to_h,
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OpenApi
|
2
|
+
class Responses
|
3
|
+
extend Forwardable
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :default
|
7
|
+
|
8
|
+
def initialize(default: nil, **responses_hash)
|
9
|
+
self.default = default
|
10
|
+
self.responses_hash = responses_hash.with_indifferent_access
|
11
|
+
end
|
12
|
+
|
13
|
+
def_delegator :responses_hash, :[]
|
14
|
+
|
15
|
+
def serializable_hash
|
16
|
+
{
|
17
|
+
"default" => default&.serializable_hash,
|
18
|
+
}
|
19
|
+
.merge(responses_hash.map { |k, v| [k.to_s, v.serializable_hash] }.to_h)
|
20
|
+
.compact
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load(hash)
|
24
|
+
return unless hash
|
25
|
+
|
26
|
+
hash = hash.map { |k, v| [k.to_s.to_sym, Response.load(v)] }.to_h
|
27
|
+
new(**hash)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_accessor :responses_hash
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#security-requirement-object
|
3
|
+
class SecurityRequirement
|
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
|
+
new(**hash.symbolize_keys)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_accessor :hash
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#security-scheme-object
|
3
|
+
class SecuritySchema
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :type, :description, :name, :in, :scheme, :bearer_format, :flows, :open_id_connect_url
|
7
|
+
|
8
|
+
def initialize(type:, description: nil, name:, in:, scheme:, bearer_format: nil, flows:, open_id_connect_url:)
|
9
|
+
self.type = type
|
10
|
+
self.description = description
|
11
|
+
self.name = name
|
12
|
+
self.in = binding.local_variable_get(:in)
|
13
|
+
self.scheme = scheme
|
14
|
+
self.bearer_format = bearer_format
|
15
|
+
self.flows = flows
|
16
|
+
self.open_id_connect_url = open_id_connect_url
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load(hash)
|
20
|
+
return unless hash
|
21
|
+
|
22
|
+
new(
|
23
|
+
type: hash["type"].to_s,
|
24
|
+
description: hash["description"]&.to_s,
|
25
|
+
name: hash["name"].to_s,
|
26
|
+
in: hash["in"].to_s,
|
27
|
+
scheme: hash["scheme"].to_s,
|
28
|
+
bearer_format: hash["bearerFormat"]&.to_s,
|
29
|
+
flows: OAuthFlows.load(hash["flows"]),
|
30
|
+
open_id_connect_url: hash["openIdConnectUrl"].to_s,
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module OpenApi
|
4
|
+
module Serializers
|
5
|
+
class YamlSerializer
|
6
|
+
def serialize(specification)
|
7
|
+
hash = specification.serializable_hash
|
8
|
+
YAML.dump(hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
def deserialize(yaml_string)
|
12
|
+
hash = YAML.load(yaml_string)
|
13
|
+
Specification.load(hash)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#server-object
|
3
|
+
class Server
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :url, :description, :variables
|
7
|
+
|
8
|
+
def initialize(url:, description: nil, variables: nil)
|
9
|
+
self.url = url
|
10
|
+
self.description = description
|
11
|
+
self.variables = variables
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load(hash)
|
15
|
+
new(
|
16
|
+
url: hash["url"].to_s,
|
17
|
+
description: hash["description"]&.to_s,
|
18
|
+
variables: hash["variables"]&.map { |h| ServerVariable.load(h) }
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#server-variable-object
|
3
|
+
class ServerVariable
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :enum, :default, :description
|
7
|
+
|
8
|
+
def initialize(enum: nil, default:, description: nil)
|
9
|
+
self.enum = enum
|
10
|
+
self.default = default
|
11
|
+
self.description = description
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load(hash)
|
15
|
+
new(
|
16
|
+
enum: hash["enum"],
|
17
|
+
default: hash["default"],
|
18
|
+
description: hash["description"],
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oasObject
|
3
|
+
class Specification
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs
|
7
|
+
|
8
|
+
def initialize(openapi:, info:, servers: nil, paths:, components: nil, security: nil, tags: nil, external_docs: nil)
|
9
|
+
self.openapi = openapi
|
10
|
+
self.info = info
|
11
|
+
self.paths = paths
|
12
|
+
self.components = components
|
13
|
+
self.security = security
|
14
|
+
self.tags = tags
|
15
|
+
self.external_docs = external_docs
|
16
|
+
end
|
17
|
+
|
18
|
+
def serializable_hash
|
19
|
+
{
|
20
|
+
"openapi" => openapi.to_s,
|
21
|
+
"info" => info.serializable_hash,
|
22
|
+
"paths" => paths.serializable_hash,
|
23
|
+
"components" => components&.serializable_hash,
|
24
|
+
"security" => security&.map(&:serializable_hash),
|
25
|
+
"tags" => tags&.map(&:serializable_hash),
|
26
|
+
"externalDocs" => external_docs&.serializable_hash,
|
27
|
+
}.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load(hash)
|
31
|
+
return unless hash
|
32
|
+
|
33
|
+
new(
|
34
|
+
openapi: hash["openapi"].to_s,
|
35
|
+
info: Info.load(hash["info"]),
|
36
|
+
paths: Paths.load(hash["paths"]),
|
37
|
+
components: Components.load(hash["components"]),
|
38
|
+
security: hash["security"]&.map { |requirement_hash| SecurityRequirement.load(requirement_hash) },
|
39
|
+
tags: hash["tags"]&.map { |tag_hash| Tag.load(tag_hash) },
|
40
|
+
external_docs: ExternalDocumentation.load(hash["externalDocs"]),
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/open_api/tag.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#tagObject
|
3
|
+
class Tag
|
4
|
+
prepend EquatableAsContent
|
5
|
+
|
6
|
+
attr_accessor :name, :description, :external_docs
|
7
|
+
|
8
|
+
def initialize(name:, description: nil, external_docs: nil)
|
9
|
+
self.name = name
|
10
|
+
self.description = description
|
11
|
+
self.external_docs = external_docs
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load(hash)
|
15
|
+
return unless hash
|
16
|
+
|
17
|
+
new(
|
18
|
+
name: hash["name"].to_s,
|
19
|
+
description: hash["description"]&.to_s,
|
20
|
+
external_docs: ExternalDocumentation.load(hash["externalDocs"]),
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/open_api/xml.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenApi
|
2
|
+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#xml-object
|
3
|
+
class Xml
|
4
|
+
attr_accessor :name, :namespace, :prefix, :attribute, :wrapped
|
5
|
+
|
6
|
+
def initialize(name: nil, namespace: nil, prefix: nil, attribute: false, wrapped: false)
|
7
|
+
self.name = name
|
8
|
+
self.namespace = namespace
|
9
|
+
self.prefix = prefix
|
10
|
+
self.attribute = attribute
|
11
|
+
self.wrapped = wrapped
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load(hash)
|
15
|
+
return unless hash
|
16
|
+
|
17
|
+
new(
|
18
|
+
name: hash["name"],
|
19
|
+
namespace: hash["namespace"],
|
20
|
+
prefix: hash["prefix"],
|
21
|
+
attribute: hash["attribute"],
|
22
|
+
wrapped: hash["wrapped"],
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/open_api.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Dependant libraries
|
2
|
+
require "active_support"
|
3
|
+
require "active_support/core_ext/hash"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
|
+
require "active_support/core_ext/object/inclusion"
|
6
|
+
|
7
|
+
# open_api/*
|
8
|
+
require "open_api/equatable_as_content"
|
9
|
+
require "open_api/version"
|
10
|
+
|
11
|
+
# Models
|
12
|
+
require "open_api/specification"
|
13
|
+
require "open_api/info"
|
14
|
+
require "open_api/contact"
|
15
|
+
require "open_api/license"
|
16
|
+
require "open_api/server"
|
17
|
+
require "open_api/server_variable"
|
18
|
+
require "open_api/components"
|
19
|
+
require "open_api/paths"
|
20
|
+
require "open_api/path_item"
|
21
|
+
require "open_api/operation"
|
22
|
+
require "open_api/external_documentation"
|
23
|
+
require "open_api/parameter"
|
24
|
+
require "open_api/request_body"
|
25
|
+
require "open_api/media_type"
|
26
|
+
require "open_api/encoding"
|
27
|
+
require "open_api/responses"
|
28
|
+
require "open_api/response"
|
29
|
+
require "open_api/callback"
|
30
|
+
require "open_api/example"
|
31
|
+
require "open_api/link"
|
32
|
+
require "open_api/header"
|
33
|
+
require "open_api/tag"
|
34
|
+
require "open_api/reference"
|
35
|
+
require "open_api/schema"
|
36
|
+
require "open_api/discriminator"
|
37
|
+
require "open_api/xml"
|
38
|
+
require "open_api/security_schema"
|
39
|
+
require "open_api/o_auth_flows"
|
40
|
+
require "open_api/o_auth_flow"
|
41
|
+
require "open_api/security_requirement"
|
42
|
+
|
43
|
+
# Serializer
|
44
|
+
require "open_api/serializers"
|
45
|
+
|
46
|
+
module OpenApi
|
47
|
+
end
|
data/open_api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "open_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "open_api"
|
8
|
+
spec.version = OpenApi::VERSION
|
9
|
+
spec.authors = ["Kent Nagata"]
|
10
|
+
spec.email = ["ngtknt@me.com"]
|
11
|
+
|
12
|
+
spec.summary = "Provide PORO of OpenAPI specification"
|
13
|
+
spec.description = "It provides PORO of OpenAPI specification. It only support OpenAPI v3."
|
14
|
+
spec.homepage = "https://github.com/ngtk/open_api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "activesupport", "~> 5.0"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "simplecov"
|
30
|
+
end
|