swagger-serializer 0.8.3 → 0.9.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 +12 -0
- data/README.md +11 -10
- data/lib/swagger/schema/component_set.rb +19 -0
- data/lib/swagger/schema/components.rb +21 -0
- data/lib/swagger/schema.rb +5 -7
- data/lib/swagger/serializer/model.rb +1 -1
- data/lib/swagger/serializer/store.rb +3 -2
- data/lib/swagger/serializer/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbb250d6c1883291921652478c9a65725bf1c81a9d6ce93280160157ffbfd806
|
4
|
+
data.tar.gz: b653e8be0346bb4ca79d8283edcba2ce53426afd50a7e178b833541dcd0aa674
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f88dec0338b293ec30285ebdb167264e546cb809a322b716e19cd92711ac89721c919b2b2a5749ffea53dfbdcf033fc3c5455ab93de3edfebdcdfb810c8951
|
7
|
+
data.tar.gz: dbccb3a869dc576bb118999dce2183620d93f6ff8808bd6de0352f72542930080df3298f0b8cbde05608661cffd0e5c3466e56bba9f5e48f1b0a57b934af8583
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -184,7 +184,7 @@ end
|
|
184
184
|
Now you can get `{ "id" => 42, "name" => "me!!!!" }`.
|
185
185
|
|
186
186
|
This serializer class detection uses the schema's `title` key.
|
187
|
-
If you want to use `Foo::BarSerializer`, set `Foo
|
187
|
+
If you want to use `Foo::BarSerializer`, set `Foo-Bar` to `title` key.
|
188
188
|
|
189
189
|
The key is configurable by
|
190
190
|
|
@@ -219,15 +219,16 @@ info:
|
|
219
219
|
title: example api
|
220
220
|
version: 0.1.0
|
221
221
|
components:
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
222
|
+
schemas:
|
223
|
+
User: &User
|
224
|
+
title: User
|
225
|
+
type: object
|
226
|
+
properties:
|
227
|
+
id:
|
228
|
+
type: integer
|
229
|
+
name:
|
230
|
+
type: string
|
231
|
+
required: [id]
|
231
232
|
paths:
|
232
233
|
/users:
|
233
234
|
get:
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "./util"
|
2
|
+
require_relative "./component"
|
3
|
+
|
4
|
+
module Swagger
|
5
|
+
class Schema
|
6
|
+
class ComponentSet
|
7
|
+
def initialize(schema)
|
8
|
+
@schema = schema
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](name)
|
12
|
+
# HogeSerializer
|
13
|
+
name = name.name.sub(/Serializer$/, "").gsub(/::/, '-') if name.class == Class
|
14
|
+
component = Util.try_hash(@schema, name)
|
15
|
+
Component.new(component) if component
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "./util"
|
2
|
+
require_relative "./component_set"
|
3
|
+
|
4
|
+
module Swagger
|
5
|
+
class Schema
|
6
|
+
class Components
|
7
|
+
def initialize(schema)
|
8
|
+
@schema = schema
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](name)
|
12
|
+
component_set = Util.try_hash(@schema, name)
|
13
|
+
ComponentSet.new(component_set) if component_set
|
14
|
+
end
|
15
|
+
|
16
|
+
def schemas
|
17
|
+
self[:schemas]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/swagger/schema.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative "./schema/
|
1
|
+
require_relative "./schema/components"
|
2
2
|
require_relative "./schema/path_item"
|
3
3
|
require_relative "./schema/server"
|
4
4
|
require_relative "./schema/schema_accessor"
|
@@ -29,18 +29,16 @@ module Swagger
|
|
29
29
|
@schema = schema
|
30
30
|
end
|
31
31
|
|
32
|
-
define_schema_accessor :paths
|
32
|
+
define_schema_accessor :paths
|
33
33
|
|
34
34
|
def path(path)
|
35
35
|
path_item = Util.try_hash(paths, path)
|
36
36
|
PathItem.new(path_item) if path_item
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
component = Util.try_hash(components, name)
|
43
|
-
Component.new(component) if component
|
39
|
+
def components
|
40
|
+
components = Util.try_hash(@schema, 'components')
|
41
|
+
Components.new(components) if components
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Swagger::Serializer::Model
|
2
2
|
def serialize(name = self.class.name)
|
3
3
|
serializer =
|
4
|
-
Swagger::Schema.current.
|
4
|
+
Swagger::Schema.current.components.schemas[name].serializer(Swagger::Serializer::Store.current.serialize_options)
|
5
5
|
serializer.serialize(self)
|
6
6
|
end
|
7
7
|
end
|
@@ -27,10 +27,11 @@ module Swagger
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def [](name)
|
30
|
+
serializer_name = name.to_s.gsub(/-/, '::').sub(/(?:Serializer)?$/, "Serializer")
|
30
31
|
if @cache
|
31
|
-
@injectors[name] ||=
|
32
|
+
@injectors[name] ||= serializer_name.safe_constantize
|
32
33
|
else
|
33
|
-
|
34
|
+
serializer_name.safe_constantize
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Narazaka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema-serializer
|
@@ -207,6 +207,8 @@ files:
|
|
207
207
|
- bin/setup
|
208
208
|
- lib/swagger/schema.rb
|
209
209
|
- lib/swagger/schema/component.rb
|
210
|
+
- lib/swagger/schema/component_set.rb
|
211
|
+
- lib/swagger/schema/components.rb
|
210
212
|
- lib/swagger/schema/content.rb
|
211
213
|
- lib/swagger/schema/handle_servers.rb
|
212
214
|
- lib/swagger/schema/header.rb
|
@@ -240,7 +242,7 @@ metadata:
|
|
240
242
|
homepage_uri: https://github.com/Narazaka/swagger-serializer
|
241
243
|
source_code_uri: https://github.com/Narazaka/swagger-serializer.git
|
242
244
|
changelog_uri: https://github.com/Narazaka/swagger-serializer/blob/master/CHANGELOG.md
|
243
|
-
documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.
|
245
|
+
documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.9.0
|
244
246
|
post_install_message:
|
245
247
|
rdoc_options: []
|
246
248
|
require_paths:
|
@@ -256,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
258
|
- !ruby/object:Gem::Version
|
257
259
|
version: '0'
|
258
260
|
requirements: []
|
259
|
-
rubygems_version: 3.
|
261
|
+
rubygems_version: 3.1.4
|
260
262
|
signing_key:
|
261
263
|
specification_version: 4
|
262
264
|
summary: Swagger (OpenAPI 3) schema based Serializer
|