open_api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/open_api/components.rb +9 -9
- data/lib/open_api/schema.rb +108 -0
- data/lib/open_api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cb3780237e228de5aba05e77e13f1e7ad7699a0fa7e0f7650c6a959b533a248
|
4
|
+
data.tar.gz: 1f85ba19940b862a3829e02e8db6c10a1fd31028b43771c417578d0fc869c765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4acc8b5ab843a7aa5fa47ec5f528ba4d42851f7577ed02ac797c6940f77e06eb183a43cc2a885dad2451ce96f1631338bffa66b61bdda264c56f45672c79bdd8
|
7
|
+
data.tar.gz: 2487a600e7d723351712d83b0307960a61c1caaad328c57333a52540ee658220418647d8acd9ca226b1c41d9fc0db1aacc0eefa327cd80a6ba5e28b2129e47f0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
* Allow Schema to behave like OpenStruct 5a698cf796f0467b726062bcd7c2cf2c20693950
|
3
|
+
* Allow to serialize `schema.properties` fb6f2a0a5d58de7c0bfb113b3a6636a50df7de3d
|
4
|
+
* Fix dir for `open_api/schema` 1e8d9ffcccd89d89844af7eecb418e352ad6b5f3
|
5
|
+
|
6
|
+
|
7
|
+
## 0.1.0
|
8
|
+
First release
|
9
|
+
|
10
|
+
* Implement all classes for OpenAPI v3.0.1
|
11
|
+
* Allow to YAML serializing/deserializing
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
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)
|
1
|
+
# OpenApi [![Gem Version](https://badge.fury.io/rb/open_api.svg)](https://badge.fury.io/rb/open_api) [![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
2
|
|
3
3
|
`open_api` provides PORO and serializers for OpenAPI and it supports OpenAPI v3.0.1.
|
4
4
|
|
data/lib/open_api/components.rb
CHANGED
@@ -20,15 +20,15 @@ module OpenApi
|
|
20
20
|
return unless hash
|
21
21
|
|
22
22
|
new(
|
23
|
-
schemas: hash["schemas"]&.map { |k, v| [k, Reference.load(v) || Schema.load(v)] }
|
24
|
-
responses: hash["responses"]&.map { |k, v| [k, Reference.load(v) || Response.load(v)] }
|
25
|
-
parameters: hash["parameters"]&.map { |k, v| [k, Reference.load(v) || Parameter.load(v)] }
|
26
|
-
examples: hash["examples"]&.map { |k, v| [k, Reference.load(v) || Example.load(v)] }
|
27
|
-
request_bodies: hash["requestBodies"]&.map { |k, v| [k, Reference.load(v) || RequestBody.load(v)] }
|
28
|
-
headers: hash["headers"]&.map { |k, v| [k, Reference.load(v) || Header.load(v)] }
|
29
|
-
security_schemes: hash["securitySchemes"]&.map { |k, v| [k, Reference.load(v) || SecuritySchema.load(v)] }
|
30
|
-
links: hash["links"]&.map { |k, v| [k, Reference.load(v) || Link.load(v)] }
|
31
|
-
callbacks: hash["callbacks"]&.map { |k, v| [k, Reference.load(v) || Callback.load(v)] }
|
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
32
|
)
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module OpenApi
|
2
|
+
class Schema
|
3
|
+
prepend EquatableAsContent
|
4
|
+
|
5
|
+
attr_accessor :nullable, :discriminator, :read_only, :write_only, :xml, :external_docs, :example, :deprecated
|
6
|
+
|
7
|
+
def initialize(nullable: false, discriminator: nil, read_only: false, write_only: false, xml: nil, external_docs: nil, example: nil, deprecated: false, **other_fields_hash)
|
8
|
+
self.nullable = nullable
|
9
|
+
self.discriminator = discriminator
|
10
|
+
self.read_only = read_only
|
11
|
+
self.write_only = write_only
|
12
|
+
self.xml = xml
|
13
|
+
self.external_docs = external_docs
|
14
|
+
self.example = example
|
15
|
+
self.deprecated = deprecated
|
16
|
+
self.other_fields_hash = other_fields_hash.symbolize_keys
|
17
|
+
|
18
|
+
other_fields_hash.keys.each { |name| new_field(name) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(mid, *args)
|
22
|
+
len = args.length
|
23
|
+
if mname = mid[/.*(?==\z)/m]
|
24
|
+
if len != 1
|
25
|
+
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
|
26
|
+
end
|
27
|
+
new_field(mname)
|
28
|
+
other_fields_hash[mname.to_sym] = args[0]
|
29
|
+
elsif len == 0
|
30
|
+
if other_fields_hash.key?(mname.to_s)
|
31
|
+
new_field(mname)
|
32
|
+
other_fields_hash[mname]
|
33
|
+
end
|
34
|
+
else
|
35
|
+
begin
|
36
|
+
super
|
37
|
+
rescue NoMethodError => err
|
38
|
+
err.backtrace.shift
|
39
|
+
raise
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def new_field(name)
|
45
|
+
name = name.to_sym
|
46
|
+
define_singleton_method(name) { other_fields_hash[name] }
|
47
|
+
define_singleton_method("#{name}=") { |value| other_fields_hash[name] = value }
|
48
|
+
end
|
49
|
+
|
50
|
+
def serializable_hash
|
51
|
+
converted_other_fields_hash = other_fields_hash.map { |k, v|
|
52
|
+
value =
|
53
|
+
case k.to_sym
|
54
|
+
when :items then v.serializable_hash
|
55
|
+
when :properties then v.map { |k, v| [k.to_s, v.serializable_hash] }.to_h
|
56
|
+
else
|
57
|
+
v
|
58
|
+
end
|
59
|
+
[k.to_s, value]
|
60
|
+
}.to_h
|
61
|
+
|
62
|
+
{
|
63
|
+
"nullable" => nullable == false ? nil : nullable,
|
64
|
+
"discriminator" => discriminator&.serializable_hash,
|
65
|
+
"readOnly" => read_only == false ? nil : read_only,
|
66
|
+
"writeOnly" => write_only == false ? nil : write_only,
|
67
|
+
"xml" => xml&.serializable_hash,
|
68
|
+
"externalDocs" => external_docs&.serializable_hash,
|
69
|
+
"example" => example,
|
70
|
+
"deprecated" => deprecated == false ? nil : deprecated,
|
71
|
+
}
|
72
|
+
.merge(converted_other_fields_hash)
|
73
|
+
.compact
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.load(hash)
|
77
|
+
other_fields_hash = hash.reject { |key|
|
78
|
+
key.to_sym.in?([:nullable, :discriminator, :readOnly, :writeOnly, :xml, :externalDocs, :example, :deprecated])
|
79
|
+
}.map { |k, v|
|
80
|
+
loaded_value =
|
81
|
+
case k.to_sym
|
82
|
+
when :items then Reference.load(v)
|
83
|
+
when :properties then v.map { |k, v| [k, Reference.new(v) || Schema.new(v)] }.to_h
|
84
|
+
else
|
85
|
+
v
|
86
|
+
end
|
87
|
+
|
88
|
+
[k, loaded_value]
|
89
|
+
}.to_h
|
90
|
+
|
91
|
+
new(
|
92
|
+
nullable: hash["nullable"].nil? ? false : hash["nullable"],
|
93
|
+
discriminator: hash["discriminator"],
|
94
|
+
read_only: hash["readOnly"].nil? ? false : hash["readOnly"],
|
95
|
+
write_only: hash["writeOnly"].nil? ? false : hash["writeOnly"],
|
96
|
+
xml: Xml.load(hash["xml"]),
|
97
|
+
external_docs: ExternalDocumentation.load(hash["externalDocs"]),
|
98
|
+
example: Example.load(hash["example"]),
|
99
|
+
deprecated: hash["deprecated"].nil? ? false : hash["deprecated"],
|
100
|
+
**other_fields_hash.symbolize_keys,
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
attr_accessor :other_fields_hash
|
107
|
+
end
|
108
|
+
end
|
data/lib/open_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kent Nagata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ".rspec"
|
106
106
|
- ".ruby-version"
|
107
107
|
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
108
109
|
- CODE_OF_CONDUCT.md
|
109
110
|
- Gemfile
|
110
111
|
- LICENSE.txt
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- lib/open_api/request_body.rb
|
137
138
|
- lib/open_api/response.rb
|
138
139
|
- lib/open_api/responses.rb
|
140
|
+
- lib/open_api/schema.rb
|
139
141
|
- lib/open_api/security_requirement.rb
|
140
142
|
- lib/open_api/security_schema.rb
|
141
143
|
- lib/open_api/serializers.rb
|