eazypi 0.0.11 → 0.0.13
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/lib/eazypi/schema.rb +4 -4
- data/lib/eazypi/serializer.rb +20 -12
- data/lib/eazypi/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afad13d28348701818a13c38dd0c9902d54bacc4ad61b5aa5883f4968be2726f
|
4
|
+
data.tar.gz: 66e4f1c6c763a185a364da9e5b1187a87c96a6f99c80d193f5af52d01daa5ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b327da1939bdeec54f0bedc33aacaddb80dad8c5aa1e7f8f2015586809e49e3b352290e99b5eabc2af6d3dd6b19435f2213776d720b6c4492e3ae68af1e355b
|
7
|
+
data.tar.gz: da9fabdab32f333588e9998e1020b0ee09bdd6e664f042b6b4c0f4fb3b883cfa5f6cda2e6db74539c66d6e79c59f94698c71993572dc7fcd94c953798eb7cd41
|
data/lib/eazypi/schema.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
module Eazypi
|
4
4
|
# JSON schema
|
5
5
|
module Schema
|
6
|
-
def self.from_object(object,
|
6
|
+
def self.from_object(object, parents: []) # rubocop:todo Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
7
7
|
if object == :boolean
|
8
8
|
Schema::Primitive.new(type: "boolean")
|
9
9
|
elsif object.is_a?(::Array)
|
10
10
|
raise "Array needs to have one element" if object.length != 1
|
11
11
|
|
12
|
-
Schema::Array.new(Schema.from_object(object[0],
|
12
|
+
Schema::Array.new(Schema.from_object(object[0], parents: parents))
|
13
13
|
elsif object == String
|
14
14
|
Schema::Primitive.new(type: "string")
|
15
15
|
elsif object == Date
|
@@ -21,10 +21,10 @@ module Eazypi
|
|
21
21
|
elsif object == Float
|
22
22
|
Schema::Primitive.new(type: "number")
|
23
23
|
elsif object.respond_to?(:to_schema)
|
24
|
-
if object
|
24
|
+
if parents.include?(object)
|
25
25
|
object.to_schema_reference
|
26
26
|
else
|
27
|
-
object.to_schema
|
27
|
+
object.to_schema(parents)
|
28
28
|
end
|
29
29
|
else
|
30
30
|
raise "Can not convert #{object} to a schema"
|
data/lib/eazypi/serializer.rb
CHANGED
@@ -17,10 +17,10 @@ module Eazypi
|
|
17
17
|
@required = required
|
18
18
|
end
|
19
19
|
|
20
|
-
def serialize(object)
|
21
|
-
the_value = value(object)
|
20
|
+
def serialize(object, context)
|
21
|
+
the_value = value(object, context)
|
22
22
|
|
23
|
-
Serializer.serialize_object(type, the_value)
|
23
|
+
Serializer.serialize_object(type, the_value, context)
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
@@ -33,9 +33,13 @@ module Eazypi
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def value(object)
|
36
|
+
def value(object, context) # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
|
37
37
|
if @method
|
38
|
-
@method.
|
38
|
+
if @method.arity == 1
|
39
|
+
@method.call(object)
|
40
|
+
else
|
41
|
+
@method.call(object, context)
|
42
|
+
end
|
39
43
|
elsif @method_name
|
40
44
|
object.send(@method_name)
|
41
45
|
elsif object.is_a?(Hash)
|
@@ -50,15 +54,16 @@ module Eazypi
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
53
|
-
def initialize(object)
|
57
|
+
def initialize(object, context = nil)
|
54
58
|
@object = object
|
59
|
+
@context = context
|
55
60
|
end
|
56
61
|
|
57
62
|
def to_json(*_args)
|
58
63
|
return nil if @object.nil?
|
59
64
|
|
60
65
|
self.class.attributes.to_h do |attribute|
|
61
|
-
[attribute.name, attribute.serialize(@object)]
|
66
|
+
[attribute.name, attribute.serialize(@object, @context)]
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
@@ -79,11 +84,14 @@ module Eazypi
|
|
79
84
|
@attributes
|
80
85
|
end
|
81
86
|
|
82
|
-
def self.to_schema
|
87
|
+
def self.to_schema(parents = [])
|
83
88
|
schema = Schema::Object.new(object_name)
|
84
89
|
|
85
90
|
@attributes.each do |attribute|
|
86
|
-
schema.property attribute.name.to_s,
|
91
|
+
schema.property attribute.name.to_s,
|
92
|
+
Schema.from_object(attribute.type,
|
93
|
+
parents: parents + [self]),
|
94
|
+
required: attribute.required
|
87
95
|
end
|
88
96
|
|
89
97
|
schema
|
@@ -98,19 +106,19 @@ module Eazypi
|
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
101
|
-
def self.serialize_object(type_object, object) # rubocop:disable Metrics/MethodLength
|
109
|
+
def self.serialize_object(type_object, object, context = nil) # rubocop:disable Metrics/MethodLength
|
102
110
|
if type_object.nil?
|
103
111
|
nil
|
104
112
|
elsif type_object.is_a?(Array)
|
105
113
|
object&.map do |value|
|
106
|
-
serialize_object(type_object[0], value)
|
114
|
+
serialize_object(type_object[0], value, context)
|
107
115
|
end
|
108
116
|
elsif [Date, Time].include?(type_object)
|
109
117
|
object&.iso8601
|
110
118
|
elsif [String, Integer, Float, :boolean].include?(type_object)
|
111
119
|
object
|
112
120
|
else
|
113
|
-
type_object.new(object).to_json
|
121
|
+
type_object.new(object, context).to_json
|
114
122
|
end
|
115
123
|
end
|
116
124
|
end
|
data/lib/eazypi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eazypi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Samson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.5.
|
101
|
+
rubygems_version: 3.5.11
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: An opinionated framework to generate OpenAPI API's for Rails
|