swagger-serializer 0.6.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +0 -0
- data/.gitignore +0 -0
- data/.prettierrc +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.rubocop_airbnb.yml +0 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/README.md +43 -6
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/fmt +0 -0
- data/bin/setup +0 -0
- data/lib/swagger/schema.rb +2 -0
- data/lib/swagger/schema/component.rb +3 -2
- data/lib/swagger/schema/content.rb +0 -0
- data/lib/swagger/schema/handle_servers.rb +0 -0
- data/lib/swagger/schema/header.rb +0 -0
- data/lib/swagger/schema/headers.rb +0 -0
- data/lib/swagger/schema/media_type.rb +6 -4
- data/lib/swagger/schema/media_type/deserializer.rb +0 -0
- data/lib/swagger/schema/media_type/validator.rb +0 -0
- data/lib/swagger/schema/operation.rb +0 -0
- data/lib/swagger/schema/parameter.rb +0 -0
- data/lib/swagger/schema/parameter_base.rb +11 -11
- data/lib/swagger/schema/parameters.rb +6 -4
- data/lib/swagger/schema/parameters/deserializer.rb +0 -0
- data/lib/swagger/schema/parameters/validator.rb +0 -0
- data/lib/swagger/schema/path_item.rb +0 -0
- data/lib/swagger/schema/request_body.rb +0 -0
- data/lib/swagger/schema/response.rb +0 -0
- data/lib/swagger/schema/responses.rb +0 -0
- data/lib/swagger/schema/schema_accessor.rb +0 -0
- data/lib/swagger/schema/server.rb +0 -0
- data/lib/swagger/schema/util.rb +0 -0
- data/lib/swagger/serializer.rb +4 -3
- data/lib/swagger/serializer/model.rb +0 -0
- data/lib/swagger/serializer/rails_controller.rb +6 -8
- data/lib/swagger/serializer/store.rb +0 -0
- data/lib/swagger/serializer/version.rb +1 -1
- data/swagger-serializer.gemspec +1 -1
- metadata +18 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64f8aa131df07ce9de11beb3384f3c8bd94431136b0fd0032b05bc1a102a06cd
|
4
|
+
data.tar.gz: 56b1e7f8f3364a3df476bd12b4e08760c8dd5e8f39ebb079b15bc798a3a64d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8c0b337e81158f0384139aca9be740108567bb6c8d3e94ac7d4d6d404a0353bec53505938771a1bd4fab010e7170dcf8659e35d20fe14113b59267477923cd2
|
7
|
+
data.tar.gz: 97c6fc013f5e9339d23f38a1850fe20c4b5b21c0de715d7a5e0f1e019e33a6e95b52372b96503e00f411e194b376491656a0e0e5d5cf41237270c0dbc928b65f
|
data/.github/workflows/ruby.yml
CHANGED
File without changes
|
data/.gitignore
CHANGED
File without changes
|
data/.prettierrc
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.rubocop_airbnb.yml
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -54,12 +54,12 @@ class ApplicationController < ActionController::Base
|
|
54
54
|
include Swagger::Serializer::RailsController
|
55
55
|
extend Swagger::DSL::RailsController
|
56
56
|
|
57
|
-
def render_ok(data)
|
58
|
-
render_as_schema 200, :json, data
|
57
|
+
def render_ok(data, context = nil)
|
58
|
+
render_as_schema 200, :json, data, context
|
59
59
|
end
|
60
60
|
|
61
|
-
def render_bad(data)
|
62
|
-
render_as_schema 400, :json, data
|
61
|
+
def render_bad(data, context = nil)
|
62
|
+
render_as_schema 400, :json, data, context
|
63
63
|
end
|
64
64
|
end
|
65
65
|
```
|
@@ -265,8 +265,8 @@ Use it in controllers.
|
|
265
265
|
class ApplicationController < ActionController::Base
|
266
266
|
include Swagger::Serializer::RailsController
|
267
267
|
|
268
|
-
def render_ok(data)
|
269
|
-
render_as_schema 200, :json, data
|
268
|
+
def render_ok(data, context = nil)
|
269
|
+
render_as_schema 200, :json, data, context
|
270
270
|
end
|
271
271
|
end
|
272
272
|
```
|
@@ -317,6 +317,43 @@ end
|
|
317
317
|
|
318
318
|
Now you can get serialized result by `p User.first.serialize`.
|
319
319
|
|
320
|
+
### @context
|
321
|
+
|
322
|
+
Collection serialization sometimes needs context data for avoiding N+1 access or some other reason.
|
323
|
+
|
324
|
+
`render_as_schema`'s 4th parameter is the context that will be passed to serializers `@context`.
|
325
|
+
|
326
|
+
```ruby
|
327
|
+
# app/serializers/item_serializer.rb
|
328
|
+
class ItemSerializer < BaseSerializer
|
329
|
+
swagger do
|
330
|
+
id :integer
|
331
|
+
rate :integer
|
332
|
+
end
|
333
|
+
|
334
|
+
def rate
|
335
|
+
@context[:rates][id]
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# app/controllers/items_controller.rb
|
340
|
+
class ItemsController < ApplicationController
|
341
|
+
swagger :index do
|
342
|
+
render 200 do
|
343
|
+
array! do
|
344
|
+
cref! ItemSerializer
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def index
|
350
|
+
items = Item.all
|
351
|
+
rates = ItemRate.calc_item_rates(items)
|
352
|
+
render_ok items, { rates: rates }
|
353
|
+
end
|
354
|
+
end
|
355
|
+
```
|
356
|
+
|
320
357
|
## Development
|
321
358
|
|
322
359
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/fmt
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
data/lib/swagger/schema.rb
CHANGED
@@ -9,8 +9,9 @@ module Swagger
|
|
9
9
|
@schema = schema
|
10
10
|
end
|
11
11
|
|
12
|
-
def serializer(options = {})
|
13
|
-
|
12
|
+
def serializer(options = {}, store = true)
|
13
|
+
use_options = store ? Swagger::Serializer::Store.current.serialize_options.merge(options) : options
|
14
|
+
JSON::Schema::Serializer.new(@schema, use_options)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -14,12 +14,14 @@ module Swagger
|
|
14
14
|
|
15
15
|
define_schema_accessor :schema, :example, :examples, :encoding
|
16
16
|
|
17
|
-
def serializer(options = {})
|
18
|
-
|
17
|
+
def serializer(options = {}, store = true)
|
18
|
+
use_options = store ? Swagger::Serializer::Store.current.serialize_options.merge(options) : options
|
19
|
+
JSON::Schema::Serializer.new(schema, use_options)
|
19
20
|
end
|
20
21
|
|
21
|
-
def deserializer(options = {})
|
22
|
-
|
22
|
+
def deserializer(options = {}, store = true)
|
23
|
+
use_options = store ? Swagger::Serializer::Store.current.deserialize_options.merge(options) : options
|
24
|
+
Deserializer.new(schema, use_options)
|
23
25
|
end
|
24
26
|
|
25
27
|
def validator
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -11,17 +11,17 @@ module Swagger
|
|
11
11
|
end
|
12
12
|
|
13
13
|
define_schema_accessor %i[
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
description
|
15
|
+
required
|
16
|
+
deprecated
|
17
|
+
allowEmptyValue
|
18
|
+
style
|
19
|
+
explode
|
20
|
+
allowReserved
|
21
|
+
schema
|
22
|
+
example
|
23
|
+
examples
|
24
|
+
].freeze
|
25
25
|
|
26
26
|
def to_json_schema
|
27
27
|
schema
|
@@ -57,12 +57,14 @@ module Swagger
|
|
57
57
|
schema
|
58
58
|
end
|
59
59
|
|
60
|
-
def serializer(options = {})
|
61
|
-
|
60
|
+
def serializer(options = {}, store = true)
|
61
|
+
use_options = store ? Swagger::Serializer::Store.current.serialize_options.merge(options) : options
|
62
|
+
JSON::Schema::Serializer.new(to_json_schema, use_options)
|
62
63
|
end
|
63
64
|
|
64
|
-
def deserializer(options = {})
|
65
|
-
|
65
|
+
def deserializer(options = {}, store = true)
|
66
|
+
use_options = store ? Swagger::Serializer::Store.current.deserialize_options.merge(options) : options
|
67
|
+
Deserializer.new(self, use_options)
|
66
68
|
end
|
67
69
|
|
68
70
|
def validator
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/swagger/schema/util.rb
CHANGED
File without changes
|
data/lib/swagger/serializer.rb
CHANGED
@@ -7,8 +7,9 @@ require "yaml"
|
|
7
7
|
|
8
8
|
module Swagger
|
9
9
|
module Serializer
|
10
|
-
def initialize(model)
|
10
|
+
def initialize(model, context = nil)
|
11
11
|
@model = model
|
12
|
+
@context = context
|
12
13
|
end
|
13
14
|
|
14
15
|
def respond_to_missing?(name, include_private)
|
@@ -21,8 +22,8 @@ module Swagger
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def method_missing(name, *args)
|
25
|
-
@model.public_send(name, *args)
|
25
|
+
def method_missing(name, *args, &block)
|
26
|
+
@model.public_send(name, *args, &block)
|
26
27
|
end
|
27
28
|
|
28
29
|
def nil?
|
File without changes
|
@@ -3,13 +3,13 @@ module Swagger::Serializer::RailsController
|
|
3
3
|
|
4
4
|
# render
|
5
5
|
|
6
|
-
def render_as_schema(code, format, data)
|
7
|
-
render format => render_serializer(code, format).serialize(data)
|
6
|
+
def render_as_schema(code, format, data, context = nil)
|
7
|
+
render format => render_serializer(code, format, context).serialize(data)
|
8
8
|
end
|
9
9
|
|
10
|
-
def render_serializer(code, format)
|
10
|
+
def render_serializer(code, format, context = nil)
|
11
11
|
response_obj = swagger_operation.responses[code]
|
12
|
-
response_obj.content.send(format).serializer(
|
12
|
+
response_obj.content.send(format).serializer(inject_context: context)
|
13
13
|
end
|
14
14
|
|
15
15
|
def swagger_operation
|
@@ -37,7 +37,7 @@ module Swagger::Serializer::RailsController
|
|
37
37
|
|
38
38
|
def parameter_deserializer
|
39
39
|
@parameter_deserializer ||=
|
40
|
-
swagger_operation.parameters.deserializer
|
40
|
+
swagger_operation.parameters.deserializer
|
41
41
|
end
|
42
42
|
|
43
43
|
def body_params
|
@@ -47,9 +47,7 @@ module Swagger::Serializer::RailsController
|
|
47
47
|
def body_deserializer
|
48
48
|
@body_deserializer ||=
|
49
49
|
if request.content_type
|
50
|
-
swagger_operation.request_body.content[request.content_type]&.deserializer
|
51
|
-
Swagger::Serializer::Store.current.deserialize_options,
|
52
|
-
)
|
50
|
+
swagger_operation.request_body.content[request.content_type]&.deserializer
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
File without changes
|
data/swagger-serializer.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = %w[lib]
|
29
29
|
|
30
|
-
spec.add_dependency "json-schema-serializer", "
|
30
|
+
spec.add_dependency "json-schema-serializer", [">= 1.6", "< 3"]
|
31
31
|
spec.add_dependency "snake_camel", "~> 1.1"
|
32
32
|
spec.add_development_dependency "bundler", "~> 2"
|
33
33
|
spec.add_development_dependency "rake", "~> 13.0"
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Narazaka
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema-serializer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
29
|
+
version: '1.6'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: snake_camel
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,7 +184,7 @@ dependencies:
|
|
178
184
|
- - "~>"
|
179
185
|
- !ruby/object:Gem::Version
|
180
186
|
version: '0.9'
|
181
|
-
description:
|
187
|
+
description:
|
182
188
|
email:
|
183
189
|
- info@narazaka.net
|
184
190
|
executables: []
|
@@ -234,8 +240,8 @@ metadata:
|
|
234
240
|
homepage_uri: https://github.com/Narazaka/swagger-serializer
|
235
241
|
source_code_uri: https://github.com/Narazaka/swagger-serializer.git
|
236
242
|
changelog_uri: https://github.com/Narazaka/swagger-serializer/blob/master/CHANGELOG.md
|
237
|
-
documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.
|
238
|
-
post_install_message:
|
243
|
+
documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.8.3
|
244
|
+
post_install_message:
|
239
245
|
rdoc_options: []
|
240
246
|
require_paths:
|
241
247
|
- lib
|
@@ -250,9 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
256
|
- !ruby/object:Gem::Version
|
251
257
|
version: '0'
|
252
258
|
requirements: []
|
253
|
-
|
254
|
-
|
255
|
-
signing_key:
|
259
|
+
rubygems_version: 3.2.3
|
260
|
+
signing_key:
|
256
261
|
specification_version: 4
|
257
262
|
summary: Swagger (OpenAPI 3) schema based Serializer
|
258
263
|
test_files: []
|