oapi 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oapi/open_api/v30/links.rb +0 -9
- data/lib/oapi/open_api/v30/parsers/json.rb +38 -0
- data/lib/oapi/schema.rb +0 -9
- data/lib/oapi/types/array.rb +0 -2
- data/lib/oapi/types/map.rb +0 -7
- data/lib/oapi/types/object.rb +0 -16
- data/lib/oapi/version.rb +1 -1
- data/lib/oapi.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51585744c9a5a8787b4cbc8235ca2f613fdad0fc8d28aea14ad8242b2d39d107
|
4
|
+
data.tar.gz: b68db8b06768f24ead377f085cd5cb546aba3a9912ebe550229f3ca037621621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96f581933db469a307cfe53e22611a5821540d1b6fdadb77d9e81ab70deaf2097c748108c559105ca0bab6c6097f8d80baeb4d0f36f63ad50fb3709e7d06c0af
|
7
|
+
data.tar.gz: a2ea340668ebd92716f3434094ae809e5c8c25f1e07e0fe6fc329f225c88125c2d62cb35c378f388ae9e1ab755ed88adf86d5a084f080544eb2960298512f9e6
|
data/Gemfile.lock
CHANGED
@@ -9,15 +9,6 @@ class OAPI::OpenAPI::V30::Links < OAPI::Types::Map
|
|
9
9
|
|
10
10
|
property :parameters # TODO: a custom type? https://spec.openapis.org/oas/v3.0.3#fixed-fields-16
|
11
11
|
property :server, OAPI::OpenAPI::V30::Servers::Server
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def parse(json)
|
15
|
-
ref = json[:$ref]
|
16
|
-
return OAPI::Ref.new(ref) if ref
|
17
|
-
|
18
|
-
super
|
19
|
-
end
|
20
|
-
end
|
21
12
|
end
|
22
13
|
|
23
14
|
item :link, Link
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class OAPI::OpenAPI::V30::Parsers::JSON
|
4
|
+
using OAPI::Monkey
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def parse(input) = parse_object(input, OAPI::OpenAPI::V30::Definition)
|
8
|
+
|
9
|
+
def parse_type(input, type)
|
10
|
+
return input if type.nil?
|
11
|
+
|
12
|
+
return parse_array(input, type) if type <= OAPI::Types::Array
|
13
|
+
|
14
|
+
return parse_map(input, type) if type <= OAPI::Types::Map
|
15
|
+
|
16
|
+
return OAPI::Ref.new(input[:$ref]) if input[:$ref]
|
17
|
+
|
18
|
+
return type.new { input } if type <= OAPI::Schema
|
19
|
+
|
20
|
+
return parse_object(input, type) if type <= OAPI::Types::Object
|
21
|
+
|
22
|
+
raise ArgumentError, "unknown type #{type}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_object(input, klass)
|
26
|
+
klass.new.tap do |obj|
|
27
|
+
klass.properties.each do |name, type|
|
28
|
+
value = input[name.camelize]
|
29
|
+
|
30
|
+
obj.send(name, parse_type(value, type)) unless value.nil?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_array(input, klass) = klass.new(input.map { parse_type(_1, klass.item_type) })
|
36
|
+
def parse_map(input, klass) = klass.new(input.transform_values { parse_type(_1, klass.item_type) })
|
37
|
+
end
|
38
|
+
end
|
data/lib/oapi/schema.rb
CHANGED
data/lib/oapi/types/array.rb
CHANGED
data/lib/oapi/types/map.rb
CHANGED
data/lib/oapi/types/object.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class OAPI::Types::Object
|
4
|
-
using OAPI::Monkey
|
5
|
-
|
6
4
|
include OAPI::Properties
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def parse(json)
|
10
|
-
new.tap do |obj|
|
11
|
-
properties.each do |name, type|
|
12
|
-
value = json[name.camelize]
|
13
|
-
next if value.nil?
|
14
|
-
|
15
|
-
value = type.parse(value) if type
|
16
|
-
obj.send(name, value)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
5
|
end
|
data/lib/oapi/version.rb
CHANGED
data/lib/oapi.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Sinyavskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/oapi/open_api/v30/links.rb
|
54
54
|
- lib/oapi/open_api/v30/media_type.rb
|
55
55
|
- lib/oapi/open_api/v30/parameters.rb
|
56
|
+
- lib/oapi/open_api/v30/parsers/json.rb
|
56
57
|
- lib/oapi/open_api/v30/paths.rb
|
57
58
|
- lib/oapi/open_api/v30/request_body.rb
|
58
59
|
- lib/oapi/open_api/v30/responses.rb
|