ruby-gems-publish-test 0.1.0
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 +7 -0
- data/README.md +233 -0
- data/lib/ruby_gems_publish_test/async/services/pet.rb +64 -0
- data/lib/ruby_gems_publish_test/async/services/store.rb +44 -0
- data/lib/ruby_gems_publish_test/async/services/user.rb +59 -0
- data/lib/ruby_gems_publish_test/async_client.rb +54 -0
- data/lib/ruby_gems_publish_test/client.rb +63 -0
- data/lib/ruby_gems_publish_test/config.rb +54 -0
- data/lib/ruby_gems_publish_test/environment.rb +7 -0
- data/lib/ruby_gems_publish_test/error.rb +32 -0
- data/lib/ruby_gems_publish_test/http/auth.rb +19 -0
- data/lib/ruby_gems_publish_test/http/connection.rb +321 -0
- data/lib/ruby_gems_publish_test/http/hooks.rb +17 -0
- data/lib/ruby_gems_publish_test/http/response.rb +35 -0
- data/lib/ruby_gems_publish_test/models/api_response.rb +70 -0
- data/lib/ruby_gems_publish_test/models/category.rb +60 -0
- data/lib/ruby_gems_publish_test/models/find_pets_by_status_status.rb +12 -0
- data/lib/ruby_gems_publish_test/models/open_model.rb +30 -0
- data/lib/ruby_gems_publish_test/models/order.rb +104 -0
- data/lib/ruby_gems_publish_test/models/order_status.rb +12 -0
- data/lib/ruby_gems_publish_test/models/pet.rb +107 -0
- data/lib/ruby_gems_publish_test/models/pet_status.rb +12 -0
- data/lib/ruby_gems_publish_test/models/serializable.rb +63 -0
- data/lib/ruby_gems_publish_test/models/tag.rb +60 -0
- data/lib/ruby_gems_publish_test/models/union_type.rb +12 -0
- data/lib/ruby_gems_publish_test/models/user.rb +121 -0
- data/lib/ruby_gems_publish_test/serializers/form_serializer.rb +41 -0
- data/lib/ruby_gems_publish_test/serializers/json_serializer.rb +41 -0
- data/lib/ruby_gems_publish_test/serializers/xml_serializer.rb +56 -0
- data/lib/ruby_gems_publish_test/services/pet.rb +151 -0
- data/lib/ruby_gems_publish_test/services/store.rb +79 -0
- data/lib/ruby_gems_publish_test/services/user.rb +114 -0
- data/lib/ruby_gems_publish_test/validator.rb +42 -0
- data/lib/ruby_gems_publish_test/version.rb +5 -0
- data/lib/ruby_gems_publish_test.rb +37 -0
- metadata +196 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyGemsPublishTest
|
|
4
|
+
module Models
|
|
5
|
+
class Pet
|
|
6
|
+
include ::RubyGemsPublishTest::Models::Serializable
|
|
7
|
+
include ::RubyGemsPublishTest::Models::OpenModel
|
|
8
|
+
|
|
9
|
+
def self.wire_keys
|
|
10
|
+
{
|
|
11
|
+
id: 'id',
|
|
12
|
+
name: 'name',
|
|
13
|
+
category: 'category',
|
|
14
|
+
photo_urls: 'photoUrls',
|
|
15
|
+
tags: 'tags',
|
|
16
|
+
status: 'status',
|
|
17
|
+
}.freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def id
|
|
21
|
+
val = @id
|
|
22
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def name
|
|
26
|
+
val = @name
|
|
27
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def category
|
|
31
|
+
val = @category
|
|
32
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def photo_urls
|
|
36
|
+
val = @photo_urls
|
|
37
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def tags
|
|
41
|
+
val = @tags
|
|
42
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def status
|
|
46
|
+
val = @status
|
|
47
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
attr_reader :additional_properties
|
|
51
|
+
|
|
52
|
+
def initialize(
|
|
53
|
+
id: ::RubyGemsPublishTest::Models::UNSET,
|
|
54
|
+
name: ::RubyGemsPublishTest::Models::UNSET,
|
|
55
|
+
category: ::RubyGemsPublishTest::Models::UNSET,
|
|
56
|
+
photo_urls: ::RubyGemsPublishTest::Models::UNSET,
|
|
57
|
+
tags: ::RubyGemsPublishTest::Models::UNSET,
|
|
58
|
+
status: ::RubyGemsPublishTest::Models::UNSET,
|
|
59
|
+
additional_properties: {}
|
|
60
|
+
)
|
|
61
|
+
@id = id
|
|
62
|
+
@name = name
|
|
63
|
+
@category = category
|
|
64
|
+
@photo_urls = photo_urls
|
|
65
|
+
@tags = tags
|
|
66
|
+
@status = status
|
|
67
|
+
@additional_properties = additional_properties
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.from_hash(hash)
|
|
71
|
+
return unless hash
|
|
72
|
+
|
|
73
|
+
new(
|
|
74
|
+
id: hash.fetch('id', ::RubyGemsPublishTest::Models::UNSET),
|
|
75
|
+
name: hash.fetch('name', ::RubyGemsPublishTest::Models::UNSET),
|
|
76
|
+
category:
|
|
77
|
+
hash.key?('category') ? ::RubyGemsPublishTest::Models::Category.from_hash(hash['category']) : ::RubyGemsPublishTest::Models::UNSET,
|
|
78
|
+
photo_urls: hash.fetch('photoUrls', ::RubyGemsPublishTest::Models::UNSET),
|
|
79
|
+
tags: hash.fetch('tags', ::RubyGemsPublishTest::Models::UNSET),
|
|
80
|
+
status: hash.fetch('status', ::RubyGemsPublishTest::Models::UNSET),
|
|
81
|
+
additional_properties: hash.except('id', 'name', 'category', 'photoUrls', 'tags', 'status'),
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def attributes
|
|
86
|
+
{
|
|
87
|
+
id: @id,
|
|
88
|
+
name: @name,
|
|
89
|
+
category: @category,
|
|
90
|
+
photo_urls: @photo_urls,
|
|
91
|
+
tags: @tags,
|
|
92
|
+
status: @status,
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def validate!
|
|
97
|
+
@category&.validate! if !@category.equal?(::RubyGemsPublishTest::Models::UNSET) && @category.respond_to?(:validate!)
|
|
98
|
+
@tags&.each { |item| item.validate! if item.respond_to?(:validate!) } unless @tags.equal?(::RubyGemsPublishTest::Models::UNSET)
|
|
99
|
+
@status&.validate! if !@status.equal?(::RubyGemsPublishTest::Models::UNSET) && @status.respond_to?(:validate!)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def open_model_extras
|
|
103
|
+
@additional_properties
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyGemsPublishTest
|
|
4
|
+
module Models
|
|
5
|
+
# Sentinel value for model fields that were never explicitly set.
|
|
6
|
+
# Distinguishes "field not provided" from "field explicitly set to nil",
|
|
7
|
+
# which matters for PATCH requests where nil means "clear this field".
|
|
8
|
+
UNSET = Object.new.tap do |o|
|
|
9
|
+
o.define_singleton_method(:inspect) { 'UNSET' }
|
|
10
|
+
o.define_singleton_method(:to_s) { 'UNSET' }
|
|
11
|
+
end.freeze
|
|
12
|
+
|
|
13
|
+
# Marker module for generated model classes.
|
|
14
|
+
#
|
|
15
|
+
# Including classes must implement:
|
|
16
|
+
# - .wire_keys → { attr_sym: 'wire_name', ... }.freeze
|
|
17
|
+
# - .from_hash(hash) → model instance or nil
|
|
18
|
+
# - #attributes → { attr_sym: raw_value, ... }
|
|
19
|
+
#
|
|
20
|
+
# In return, this module provides:
|
|
21
|
+
# - #to_h → { attr_sym: value, ... } with nested models recursively converted,
|
|
22
|
+
# omitting fields set to UNSET but preserving explicit nil
|
|
23
|
+
module Serializable
|
|
24
|
+
def self.included(base)
|
|
25
|
+
base.extend(ClassMethods)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module ClassMethods
|
|
29
|
+
def wire_keys
|
|
30
|
+
raise NotImplementedError, "#{name} must implement .wire_keys"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def from_hash(_hash)
|
|
34
|
+
raise NotImplementedError, "#{name} must implement .from_hash"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def to_h
|
|
39
|
+
self.class.wire_keys.each_with_object({}) do |(attr, _key), hash|
|
|
40
|
+
val = attributes[attr]
|
|
41
|
+
next if val.equal?(UNSET)
|
|
42
|
+
|
|
43
|
+
hash[attr] = coerce_to_h(val)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def attributes
|
|
48
|
+
raise NotImplementedError, "#{self.class} must implement #attributes"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def coerce_to_h(val)
|
|
54
|
+
return val.to_h if val.is_a?(Serializable)
|
|
55
|
+
return val.map { |item| coerce_to_h(item) } if val.is_a?(Array)
|
|
56
|
+
# Typed maps (additionalProperties): recurse values, preserving the dynamic string keys.
|
|
57
|
+
return val.transform_values { |item| coerce_to_h(item) } if val.is_a?(Hash)
|
|
58
|
+
|
|
59
|
+
val
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyGemsPublishTest
|
|
4
|
+
module Models
|
|
5
|
+
class Tag
|
|
6
|
+
include ::RubyGemsPublishTest::Models::Serializable
|
|
7
|
+
include ::RubyGemsPublishTest::Models::OpenModel
|
|
8
|
+
|
|
9
|
+
def self.wire_keys
|
|
10
|
+
{
|
|
11
|
+
id: 'id',
|
|
12
|
+
name: 'name',
|
|
13
|
+
}.freeze
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def id
|
|
17
|
+
val = @id
|
|
18
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def name
|
|
22
|
+
val = @name
|
|
23
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
attr_reader :additional_properties
|
|
27
|
+
|
|
28
|
+
def initialize(
|
|
29
|
+
id: ::RubyGemsPublishTest::Models::UNSET,
|
|
30
|
+
name: ::RubyGemsPublishTest::Models::UNSET,
|
|
31
|
+
additional_properties: {}
|
|
32
|
+
)
|
|
33
|
+
@id = id
|
|
34
|
+
@name = name
|
|
35
|
+
@additional_properties = additional_properties
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.from_hash(hash)
|
|
39
|
+
return unless hash
|
|
40
|
+
|
|
41
|
+
new(
|
|
42
|
+
id: hash.fetch('id', ::RubyGemsPublishTest::Models::UNSET),
|
|
43
|
+
name: hash.fetch('name', ::RubyGemsPublishTest::Models::UNSET),
|
|
44
|
+
additional_properties: hash.except('id', 'name'),
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def attributes
|
|
49
|
+
{
|
|
50
|
+
id: @id,
|
|
51
|
+
name: @name,
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def open_model_extras
|
|
56
|
+
@additional_properties
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyGemsPublishTest
|
|
4
|
+
module Models
|
|
5
|
+
# Marker module for oneOf/anyOf union wrapper classes.
|
|
6
|
+
#
|
|
7
|
+
# Including classes hold one typed variant in +#value+.
|
|
8
|
+
# Serializers check for this module to delegate serialization to the wrapped value.
|
|
9
|
+
module UnionType
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyGemsPublishTest
|
|
4
|
+
module Models
|
|
5
|
+
class User
|
|
6
|
+
include ::RubyGemsPublishTest::Models::Serializable
|
|
7
|
+
include ::RubyGemsPublishTest::Models::OpenModel
|
|
8
|
+
|
|
9
|
+
def self.wire_keys
|
|
10
|
+
{
|
|
11
|
+
id: 'id',
|
|
12
|
+
username: 'username',
|
|
13
|
+
first_name: 'firstName',
|
|
14
|
+
last_name: 'lastName',
|
|
15
|
+
email: 'email',
|
|
16
|
+
password: 'password',
|
|
17
|
+
phone: 'phone',
|
|
18
|
+
user_status: 'userStatus',
|
|
19
|
+
}.freeze
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def id
|
|
23
|
+
val = @id
|
|
24
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def username
|
|
28
|
+
val = @username
|
|
29
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def first_name
|
|
33
|
+
val = @first_name
|
|
34
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def last_name
|
|
38
|
+
val = @last_name
|
|
39
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def email
|
|
43
|
+
val = @email
|
|
44
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def password
|
|
48
|
+
val = @password
|
|
49
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def phone
|
|
53
|
+
val = @phone
|
|
54
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def user_status
|
|
58
|
+
val = @user_status
|
|
59
|
+
val.equal?(::RubyGemsPublishTest::Models::UNSET) ? nil : val
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
attr_reader :additional_properties
|
|
63
|
+
|
|
64
|
+
def initialize(
|
|
65
|
+
id: ::RubyGemsPublishTest::Models::UNSET,
|
|
66
|
+
username: ::RubyGemsPublishTest::Models::UNSET,
|
|
67
|
+
first_name: ::RubyGemsPublishTest::Models::UNSET,
|
|
68
|
+
last_name: ::RubyGemsPublishTest::Models::UNSET,
|
|
69
|
+
email: ::RubyGemsPublishTest::Models::UNSET,
|
|
70
|
+
password: ::RubyGemsPublishTest::Models::UNSET,
|
|
71
|
+
phone: ::RubyGemsPublishTest::Models::UNSET,
|
|
72
|
+
user_status: ::RubyGemsPublishTest::Models::UNSET,
|
|
73
|
+
additional_properties: {}
|
|
74
|
+
)
|
|
75
|
+
@id = id
|
|
76
|
+
@username = username
|
|
77
|
+
@first_name = first_name
|
|
78
|
+
@last_name = last_name
|
|
79
|
+
@email = email
|
|
80
|
+
@password = password
|
|
81
|
+
@phone = phone
|
|
82
|
+
@user_status = user_status
|
|
83
|
+
@additional_properties = additional_properties
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.from_hash(hash)
|
|
87
|
+
return unless hash
|
|
88
|
+
|
|
89
|
+
new(
|
|
90
|
+
id: hash.fetch('id', ::RubyGemsPublishTest::Models::UNSET),
|
|
91
|
+
username: hash.fetch('username', ::RubyGemsPublishTest::Models::UNSET),
|
|
92
|
+
first_name: hash.fetch('firstName', ::RubyGemsPublishTest::Models::UNSET),
|
|
93
|
+
last_name: hash.fetch('lastName', ::RubyGemsPublishTest::Models::UNSET),
|
|
94
|
+
email: hash.fetch('email', ::RubyGemsPublishTest::Models::UNSET),
|
|
95
|
+
password: hash.fetch('password', ::RubyGemsPublishTest::Models::UNSET),
|
|
96
|
+
phone: hash.fetch('phone', ::RubyGemsPublishTest::Models::UNSET),
|
|
97
|
+
user_status: hash.fetch('userStatus', ::RubyGemsPublishTest::Models::UNSET),
|
|
98
|
+
additional_properties:
|
|
99
|
+
hash.except('id', 'username', 'firstName', 'lastName', 'email', 'password', 'phone', 'userStatus'),
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def attributes
|
|
104
|
+
{
|
|
105
|
+
id: @id,
|
|
106
|
+
username: @username,
|
|
107
|
+
first_name: @first_name,
|
|
108
|
+
last_name: @last_name,
|
|
109
|
+
email: @email,
|
|
110
|
+
password: @password,
|
|
111
|
+
phone: @phone,
|
|
112
|
+
user_status: @user_status,
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def open_model_extras
|
|
117
|
+
@additional_properties
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module RubyGemsPublishTest
|
|
6
|
+
module Serializers
|
|
7
|
+
# Serializes models or hashes to form-encoded and multipart bodies.
|
|
8
|
+
module Form
|
|
9
|
+
# Encodes a model or hash as application/x-www-form-urlencoded.
|
|
10
|
+
def self.to_urlencoded(value)
|
|
11
|
+
URI.encode_www_form(flatten(value))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Configures a Net::HTTP request for multipart/form-data.
|
|
15
|
+
def self.set_multipart(request, value)
|
|
16
|
+
request.set_form(
|
|
17
|
+
flatten(value).map { |k, v| [k.to_s, v.to_s] },
|
|
18
|
+
'multipart/form-data',
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private_class_method def self.flatten(value)
|
|
23
|
+
value = value.value if value.is_a?(Models::UnionType)
|
|
24
|
+
if value.is_a?(Models::Serializable)
|
|
25
|
+
declared = value.class.wire_keys.filter_map do |attr, key|
|
|
26
|
+
val = value.attributes[attr]
|
|
27
|
+
# Form encoding cannot represent null; both UNSET and explicit nil are omitted.
|
|
28
|
+
# Unlike JSON (which serializes nil as null), form bodies have no null concept.
|
|
29
|
+
[key, val] unless val.nil? || val.equal?(Models::UNSET)
|
|
30
|
+
end
|
|
31
|
+
extras = value.is_a?(Models::OpenModel) ? value.open_model_extras.compact.to_a : []
|
|
32
|
+
declared + extras
|
|
33
|
+
elsif value.is_a?(Hash)
|
|
34
|
+
value.compact.to_a
|
|
35
|
+
else
|
|
36
|
+
[['body', value.to_s]]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module RubyGemsPublishTest
|
|
6
|
+
module Serializers
|
|
7
|
+
# Serializes models to JSON-ready hashes and deserializes hashes back to models.
|
|
8
|
+
module Json
|
|
9
|
+
# Converts a model, array, or primitive to a plain Ruby hash/value
|
|
10
|
+
# suitable for JSON.generate / .to_json.
|
|
11
|
+
def self.serialize(value)
|
|
12
|
+
return value.map { |item| serialize(item) } if value.is_a?(Array)
|
|
13
|
+
# Typed maps (additionalProperties): serialize values, keeping the dynamic string keys.
|
|
14
|
+
return value.transform_values { |item| serialize(item) } if value.is_a?(Hash)
|
|
15
|
+
return serialize(value.value) if value.is_a?(Models::UnionType)
|
|
16
|
+
return serialize_model(value) if value.is_a?(Models::Serializable)
|
|
17
|
+
|
|
18
|
+
value
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Builds a model instance from a plain hash (already JSON.parsed).
|
|
22
|
+
# Returns the raw data unchanged when no model class is provided.
|
|
23
|
+
def self.deserialize(data, model_class = nil)
|
|
24
|
+
return data unless model_class
|
|
25
|
+
|
|
26
|
+
model_class.from_hash(data)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private_class_method def self.serialize_model(model)
|
|
30
|
+
result = model.class.wire_keys.each_with_object({}) do |(attr, key), hash|
|
|
31
|
+
val = model.attributes[attr]
|
|
32
|
+
next if val.equal?(Models::UNSET)
|
|
33
|
+
|
|
34
|
+
hash[key] = serialize(val)
|
|
35
|
+
end
|
|
36
|
+
model.open_model_extras.each { |k, v| result[k] = serialize(v) unless result.key?(k) } if model.is_a?(Models::OpenModel)
|
|
37
|
+
result
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
|
|
5
|
+
module RubyGemsPublishTest
|
|
6
|
+
module Serializers
|
|
7
|
+
# Serializes models to XML strings and deserializes XML strings back to models.
|
|
8
|
+
# Uses Ruby's stdlib REXML.
|
|
9
|
+
module Xml
|
|
10
|
+
# Converts a model or primitive to an XML string.
|
|
11
|
+
# root: the name of the wrapping XML element (defaults to 'root').
|
|
12
|
+
def self.serialize(value, root: 'root')
|
|
13
|
+
doc = REXML::Document.new
|
|
14
|
+
doc << REXML::XMLDecl.new('1.0', 'UTF-8')
|
|
15
|
+
build_element(doc.add_element(root.to_s), value)
|
|
16
|
+
doc.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Builds a model instance from an XML string.
|
|
20
|
+
# Returns the raw string unchanged when no model class is provided.
|
|
21
|
+
def self.deserialize(xml_string, model_class = nil, root: nil)
|
|
22
|
+
return xml_string unless model_class
|
|
23
|
+
return unless xml_string
|
|
24
|
+
|
|
25
|
+
doc = REXML::Document.new(xml_string)
|
|
26
|
+
el = root ? (doc.root.elements[root.to_s] || doc.root) : doc.root
|
|
27
|
+
hash = element_to_hash(el, model_class)
|
|
28
|
+
model_class.from_hash(hash)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private_class_method def self.build_element(parent, value)
|
|
32
|
+
case value
|
|
33
|
+
when Models::UnionType
|
|
34
|
+
build_element(parent, value.value)
|
|
35
|
+
when Models::Serializable
|
|
36
|
+
value.class.wire_keys.each do |attr, key|
|
|
37
|
+
build_element(parent.add_element(key.to_s), value.attributes[attr])
|
|
38
|
+
end
|
|
39
|
+
when Array
|
|
40
|
+
value.each { |item| build_element(parent.add_element('item'), item) }
|
|
41
|
+
when nil
|
|
42
|
+
nil
|
|
43
|
+
else
|
|
44
|
+
parent.text = value.to_s
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private_class_method def self.element_to_hash(element, model_class)
|
|
49
|
+
model_class.wire_keys.each_with_object({}) do |(_attr, key), hash|
|
|
50
|
+
child = element.elements[key.to_s]
|
|
51
|
+
hash[key] = child&.text
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module RubyGemsPublishTest
|
|
6
|
+
class Pet
|
|
7
|
+
NO_OVERRIDE = Object.new.freeze
|
|
8
|
+
private_constant :NO_OVERRIDE
|
|
9
|
+
|
|
10
|
+
def initialize(connection, config = nil)
|
|
11
|
+
@connection = connection
|
|
12
|
+
@config = config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Add a new pet to the store.
|
|
16
|
+
def add_pet(body:, config: NO_OVERRIDE)
|
|
17
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
18
|
+
body.validate! if body.respond_to?(:validate!)
|
|
19
|
+
conn = resolve_connection(config)
|
|
20
|
+
response = conn.post('/pet', body, headers: headers)
|
|
21
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
22
|
+
result = ::RubyGemsPublishTest::Models::Pet.from_hash(response.body)
|
|
23
|
+
result&.validate! if resolve_config(config)&.enable_response_validation
|
|
24
|
+
result
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Update an existing pet.
|
|
28
|
+
def update_pet(body:, config: NO_OVERRIDE)
|
|
29
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
30
|
+
body.validate! if body.respond_to?(:validate!)
|
|
31
|
+
conn = resolve_connection(config)
|
|
32
|
+
response = conn.put('/pet', body, headers: headers)
|
|
33
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
34
|
+
result = ::RubyGemsPublishTest::Models::Pet.from_hash(response.body)
|
|
35
|
+
result&.validate! if resolve_config(config)&.enable_response_validation
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Finds Pets by status.
|
|
40
|
+
def find_pets_by_status(status:, config: NO_OVERRIDE)
|
|
41
|
+
query_params = {
|
|
42
|
+
'status' => status,
|
|
43
|
+
}.compact
|
|
44
|
+
query_params = query_params.merge(resolve_config(config)&.additional_query_parameters || {})
|
|
45
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
46
|
+
conn = resolve_connection(config)
|
|
47
|
+
response = conn.get('/pet/findByStatus', query_params, headers)
|
|
48
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
49
|
+
result = response.body.map { |item| ::RubyGemsPublishTest::Models::Pet.from_hash(item) }
|
|
50
|
+
result&.each { |item| item&.validate! } if resolve_config(config)&.enable_response_validation
|
|
51
|
+
result
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Finds Pets by tags.
|
|
55
|
+
def find_pets_by_tags(tags:, config: NO_OVERRIDE)
|
|
56
|
+
query_params = {
|
|
57
|
+
'tags' => tags,
|
|
58
|
+
}.compact
|
|
59
|
+
query_params = query_params.merge(resolve_config(config)&.additional_query_parameters || {})
|
|
60
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
61
|
+
conn = resolve_connection(config)
|
|
62
|
+
response = conn.get('/pet/findByTags', query_params, headers)
|
|
63
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
64
|
+
result = response.body.map { |item| ::RubyGemsPublishTest::Models::Pet.from_hash(item) }
|
|
65
|
+
result&.each { |item| item&.validate! } if resolve_config(config)&.enable_response_validation
|
|
66
|
+
result
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Find pet by ID.
|
|
70
|
+
def get_pet_by_id(pet_id:, config: NO_OVERRIDE)
|
|
71
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
72
|
+
conn = resolve_connection(config)
|
|
73
|
+
response = conn.get("/pet/#{pet_id}", {}, headers)
|
|
74
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
75
|
+
result = ::RubyGemsPublishTest::Models::Pet.from_hash(response.body)
|
|
76
|
+
result&.validate! if resolve_config(config)&.enable_response_validation
|
|
77
|
+
result
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Updates a pet in the store with form data.
|
|
81
|
+
def update_pet_with_form(pet_id:, name: nil, status: nil, config: NO_OVERRIDE)
|
|
82
|
+
query_params = {
|
|
83
|
+
'name' => name,
|
|
84
|
+
'status' => status,
|
|
85
|
+
}.compact
|
|
86
|
+
query_params = query_params.merge(resolve_config(config)&.additional_query_parameters || {})
|
|
87
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
88
|
+
conn = resolve_connection(config)
|
|
89
|
+
url = query_params.empty? ? "/pet/#{pet_id}" : "/pet/#{pet_id}?#{URI.encode_www_form(query_params)}"
|
|
90
|
+
response = conn.post(url, nil, headers: headers)
|
|
91
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
92
|
+
result = ::RubyGemsPublishTest::Models::Pet.from_hash(response.body)
|
|
93
|
+
result&.validate! if resolve_config(config)&.enable_response_validation
|
|
94
|
+
result
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Deletes a pet.
|
|
98
|
+
def delete_pet(pet_id:, api_key: nil, config: NO_OVERRIDE)
|
|
99
|
+
headers = config_headers(config).merge(
|
|
100
|
+
{
|
|
101
|
+
'api_key' => api_key,
|
|
102
|
+
}.compact,
|
|
103
|
+
).merge(resolve_config(config)&.additional_headers || {})
|
|
104
|
+
conn = resolve_connection(config)
|
|
105
|
+
response = conn.delete("/pet/#{pet_id}", headers)
|
|
106
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
107
|
+
response.body
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Uploads an image.
|
|
111
|
+
def upload_file(pet_id:, additional_metadata: nil, body: nil, config: NO_OVERRIDE)
|
|
112
|
+
query_params = {
|
|
113
|
+
'additionalMetadata' => additional_metadata,
|
|
114
|
+
}.compact
|
|
115
|
+
query_params = query_params.merge(resolve_config(config)&.additional_query_parameters || {})
|
|
116
|
+
headers = config_headers(config).merge(resolve_config(config)&.additional_headers || {})
|
|
117
|
+
conn = resolve_connection(config)
|
|
118
|
+
url = query_params.empty? ? "/pet/#{pet_id}/uploadImage" : "/pet/#{pet_id}/uploadImage?#{URI.encode_www_form(query_params)}"
|
|
119
|
+
response = conn.post(url, body, content_type: 'application/octet-stream', headers: headers)
|
|
120
|
+
return response if !config.equal?(NO_OVERRIDE) && config&.return_raw
|
|
121
|
+
result = ::RubyGemsPublishTest::Models::ApiResponse.from_hash(response.body)
|
|
122
|
+
result&.validate! if resolve_config(config)&.enable_response_validation
|
|
123
|
+
result
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
def config_headers(override_config)
|
|
129
|
+
cfg = override_config.equal?(NO_OVERRIDE) ? @config : override_config
|
|
130
|
+
return {} unless cfg
|
|
131
|
+
|
|
132
|
+
HTTP::Auth.new(token: cfg.token, api_key: cfg.api_key).headers
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def resolve_connection(override_config)
|
|
136
|
+
cfg = override_config.equal?(NO_OVERRIDE) ? @config : override_config
|
|
137
|
+
return @connection unless cfg&.base_url || cfg&.timeout || cfg&.retry_config
|
|
138
|
+
|
|
139
|
+
HTTP::Connection.new(
|
|
140
|
+
cfg.base_url || @connection.base_url,
|
|
141
|
+
@connection.default_headers,
|
|
142
|
+
timeout: cfg.timeout || @connection.timeout,
|
|
143
|
+
retry_config: cfg.retry_config || @connection.retry_config,
|
|
144
|
+
)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def resolve_config(override_config)
|
|
148
|
+
override_config.equal?(NO_OVERRIDE) ? @config : override_config
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|