oapi 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oapi/open_api/v30/components.rb +1 -15
- data/lib/oapi/open_api/v30/links.rb +24 -0
- data/lib/oapi/open_api/v30/responses.rb +2 -0
- data/lib/oapi/open_api/v30/serializers/ruby.rb +16 -5
- data/lib/oapi/types/map.rb +5 -1
- data/lib/oapi/types/object.rb +2 -2
- data/lib/oapi/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37dbb0c32ad9fbb1b11e79026bfb3dc6264d33e2f7f37e86415b8db74b4d2139
|
4
|
+
data.tar.gz: 769f5aa94adce67c2dd25386fde708ededd589cbfb04505b6dfb87ca76c9210b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb093caf6f99bafff9e46bd00f08f8b761f3af8fafb7acf8996bb615ac69fcc377303431d82918925fbb30747ede4e2640996dc3aa1a76621a66dc85f2265a96
|
7
|
+
data.tar.gz: cabca79f246baaf09a41dee4991ee08ea8289f3b9c12d7838416e5d0e0c59800eb4190dd44afa92bdd4405f178d613136bd69b0a7cdf5e90c723fe502945ab74
|
data/Gemfile.lock
CHANGED
@@ -43,20 +43,6 @@ class OAPI::OpenAPI::V30::Components < OAPI::Types::Object
|
|
43
43
|
item :scheme, Scheme
|
44
44
|
end
|
45
45
|
|
46
|
-
class Links < OAPI::Types::Map
|
47
|
-
class Link < OAPI::Types::Object
|
48
|
-
property :operation_ref
|
49
|
-
property :operation_id
|
50
|
-
property :request_body
|
51
|
-
property :description
|
52
|
-
|
53
|
-
property :parameters # TODO: a custom type? https://spec.openapis.org/oas/v3.0.3#fixed-fields-16
|
54
|
-
property :server, OAPI::OpenAPI::V30::Servers::Server
|
55
|
-
end
|
56
|
-
|
57
|
-
item :link, Link
|
58
|
-
end
|
59
|
-
|
60
46
|
property :schemas, Schemas
|
61
47
|
property :responses, OAPI::OpenAPI::V30::Responses
|
62
48
|
property :parameters, Parameters
|
@@ -64,6 +50,6 @@ class OAPI::OpenAPI::V30::Components < OAPI::Types::Object
|
|
64
50
|
property :request_bodies, RequestBodies
|
65
51
|
property :headers, OAPI::OpenAPI::V30::Headers
|
66
52
|
property :security_schemes, SecuritySchemes
|
67
|
-
property :links, Links
|
53
|
+
property :links, OAPI::OpenAPI::V30::Links
|
68
54
|
property :callbacks, OAPI::OpenAPI::V30::Callbacks
|
69
55
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class OAPI::OpenAPI::V30::Links < OAPI::Types::Map
|
4
|
+
class Link < OAPI::Types::Object
|
5
|
+
property :operation_ref
|
6
|
+
property :operation_id
|
7
|
+
property :request_body
|
8
|
+
property :description
|
9
|
+
|
10
|
+
property :parameters # TODO: a custom type? https://spec.openapis.org/oas/v3.0.3#fixed-fields-16
|
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
|
+
end
|
22
|
+
|
23
|
+
item :link, Link
|
24
|
+
end
|
@@ -5,9 +5,13 @@ class OAPI::OpenAPI::V30::Serializers::Ruby < OAPI::OpenAPI::V30::Serializers::S
|
|
5
5
|
|
6
6
|
MAP_TEMPLATE = %(
|
7
7
|
<% object.store.each do |key, value| -%>
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
<% if value.is_a?(OAPI::Ref) -%>
|
9
|
+
<%= object.class.item_name %>("<%= key %>", ref: <%= serialize(value) %>)
|
10
|
+
<% else -%>
|
11
|
+
<%= object.class.item_name %>("<%= key %>") do
|
12
|
+
<%= serialize_if_supported(value) %>
|
13
|
+
end
|
14
|
+
<% end -%>
|
11
15
|
<% end -%>
|
12
16
|
)
|
13
17
|
|
@@ -22,13 +26,13 @@ end
|
|
22
26
|
OBJECT_TEMPLATE = %(
|
23
27
|
<% object.properties.each do |prop, value| -%>
|
24
28
|
<% if value.is_a?(OAPI::Ref) -%>
|
25
|
-
<%= prop%>(ref: <%= serialize(value) %>)
|
29
|
+
<%= prop %>(ref: <%= serialize(value) %>)
|
26
30
|
<% elsif supported?(value) -%>
|
27
31
|
<%= prop %> do
|
28
32
|
<%= serialize(value) %>
|
29
33
|
end
|
30
34
|
<% elsif !value.nil? -%>
|
31
|
-
<%= prop %> <%= value
|
35
|
+
<%= prop %> <%= value_to_ruby(value) %>
|
32
36
|
<% end -%>
|
33
37
|
<% end -%>
|
34
38
|
)
|
@@ -43,6 +47,13 @@ end
|
|
43
47
|
def serialize(node) = OAPI::OpenAPI::V30::Serializers::Ruby.serialize(node)
|
44
48
|
def supported?(node) = OAPI::OpenAPI::V30::Serializers::Ruby.supported?(node)
|
45
49
|
def serialize_if_supported(node) = OAPI::OpenAPI::V30::Serializers::Ruby.serialize_if_supported(node)
|
50
|
+
|
51
|
+
def value_to_ruby(value)
|
52
|
+
return value.inspect if [Numeric, String, Array, TrueClass, FalseClass].any? { value.is_a?(_1) }
|
53
|
+
return "(#{value.inspect})" if value.is_a?(Hash)
|
54
|
+
|
55
|
+
raise ArgumentError, "value: #{value}"
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
def serialize_ref(ref) = ref.ref.inspect
|
data/lib/oapi/types/map.rb
CHANGED
@@ -15,9 +15,13 @@ class OAPI::Types::Map < OAPI::Types::Object
|
|
15
15
|
@item_name = name
|
16
16
|
@item_type = type
|
17
17
|
|
18
|
-
define_method(name) do |key, &block|
|
18
|
+
define_method(name) do |key, ref: nil, &block|
|
19
19
|
raise ArgumentError, "'#{key}' already exists" if @store.include?(key.to_s)
|
20
20
|
|
21
|
+
raise ArgumentError, "ref and block are mutual exclusive" if ref && block
|
22
|
+
|
23
|
+
return @store[key] = OAPI::Ref.new(ref) if ref
|
24
|
+
|
21
25
|
@store[key] = type.new(&block)
|
22
26
|
end
|
23
27
|
end
|
data/lib/oapi/types/object.rb
CHANGED
@@ -8,11 +8,11 @@ class OAPI::Types::Object
|
|
8
8
|
class << self
|
9
9
|
def parse(json)
|
10
10
|
new.tap do |obj|
|
11
|
-
|
11
|
+
properties.each do |name, type|
|
12
12
|
value = json[name.camelize]
|
13
13
|
next if value.nil?
|
14
14
|
|
15
|
-
value = type.parse(value) if
|
15
|
+
value = type.parse(value) if type
|
16
16
|
obj.send(name, value)
|
17
17
|
end
|
18
18
|
end
|
data/lib/oapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Sinyavskiy
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/oapi/open_api/v30/external_docs.rb
|
51
51
|
- lib/oapi/open_api/v30/headers.rb
|
52
52
|
- lib/oapi/open_api/v30/info.rb
|
53
|
+
- lib/oapi/open_api/v30/links.rb
|
53
54
|
- lib/oapi/open_api/v30/media_type.rb
|
54
55
|
- lib/oapi/open_api/v30/parameters.rb
|
55
56
|
- lib/oapi/open_api/v30/paths.rb
|