swagger-serializer 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -0
  3. data/.gitignore +0 -0
  4. data/.prettierrc +0 -0
  5. data/.rspec +0 -0
  6. data/.rubocop.yml +0 -0
  7. data/.rubocop_airbnb.yml +0 -0
  8. data/CHANGELOG.md +4 -0
  9. data/Gemfile +0 -0
  10. data/LICENSE +0 -0
  11. data/README.md +44 -3
  12. data/Rakefile +0 -0
  13. data/bin/console +0 -0
  14. data/bin/fmt +0 -0
  15. data/bin/setup +0 -0
  16. data/lib/swagger/schema/component.rb +0 -0
  17. data/lib/swagger/schema/content.rb +0 -0
  18. data/lib/swagger/schema/handle_servers.rb +0 -0
  19. data/lib/swagger/schema/header.rb +0 -0
  20. data/lib/swagger/schema/headers.rb +0 -0
  21. data/lib/swagger/schema/media_type/deserializer.rb +0 -0
  22. data/lib/swagger/schema/media_type/validator.rb +0 -0
  23. data/lib/swagger/schema/media_type.rb +0 -0
  24. data/lib/swagger/schema/operation.rb +0 -0
  25. data/lib/swagger/schema/parameter.rb +0 -0
  26. data/lib/swagger/schema/parameter_base.rb +0 -0
  27. data/lib/swagger/schema/parameters/deserializer.rb +0 -0
  28. data/lib/swagger/schema/parameters/validator.rb +0 -0
  29. data/lib/swagger/schema/parameters.rb +0 -0
  30. data/lib/swagger/schema/path_item.rb +0 -0
  31. data/lib/swagger/schema/request_body.rb +0 -0
  32. data/lib/swagger/schema/response.rb +0 -0
  33. data/lib/swagger/schema/responses.rb +0 -0
  34. data/lib/swagger/schema/schema_accessor.rb +0 -0
  35. data/lib/swagger/schema/server.rb +0 -0
  36. data/lib/swagger/schema/util.rb +0 -0
  37. data/lib/swagger/schema.rb +0 -0
  38. data/lib/swagger/serializer/model.rb +1 -1
  39. data/lib/swagger/serializer/rails_controller.rb +3 -3
  40. data/lib/swagger/serializer/store.rb +10 -8
  41. data/lib/swagger/serializer/version.rb +1 -1
  42. data/lib/swagger/serializer.rb +0 -0
  43. data/swagger-serializer.gemspec +0 -0
  44. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61118ea5e4e0ae6447a27235d6598b05a0bab8105975b7f0e8abd555799c1669
4
- data.tar.gz: 5b05814e65641cf2837bfcf775c512623b3b7acf13007f1c08120ced272445a3
3
+ metadata.gz: 760497bfcf59acd2efe9eee552e575d03d7e44ceab60fcee05e145bd0d502c6c
4
+ data.tar.gz: 73359aa85e506537e7924bb3a7d6e9d9a9973667561886f59b2a71e5c6f6273b
5
5
  SHA512:
6
- metadata.gz: 6404071f5f13a26de10418980785d7c763430919b8cb503d57c7a832c7522c730bce6612a911b4ed9088081930492633786e384ec80fe2cc0303b7976d42d86e
7
- data.tar.gz: a4eea6355374a9e6860ff70fcda0289b782128801c422879242331b28e067142fea151cf46ba38269e234e293eb65a262b5aa2f59e6c326af936058060ec95e8
6
+ metadata.gz: 4dfed538f9c7b71651a8bd024b115d407c77ce97a82a0cc1d2d5fca51f01b57faaf9c3c6567f3e881fcd1903c41acb486a48b08685688563ca28e17cc9cc08cc
7
+ data.tar.gz: 5a10fc7abff49e5a9846baa72289f8fb968ea3b1dfc88b5c3d65f1682f303f43f7b9ba5ef005db3b12b3ed561d4b84b379d18576feab80e5108e0449163cc439
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
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.0
4
+
5
+ - mod(brake): separate serialize_options and deserialize_options
6
+
3
7
  ## 0.5.2
4
8
 
5
9
  - fix: body params missing error
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -48,6 +48,7 @@ Use it in controllers.
48
48
  # app/controllers/application_controller.rb
49
49
  class ApplicationController < ActionController::Base
50
50
  include Swagger::Serializer::RailsController
51
+ extend Swagger::DSL::RailsController
51
52
 
52
53
  def render_ok(data)
53
54
  render_as_schema 200, :json, data
@@ -67,21 +68,19 @@ class UsersController < ApplicationController
67
68
  array! { cref! UserSerializer }
68
69
  end
69
70
  end
70
-
71
71
  def index
72
72
  render_ok User.all
73
73
  end
74
74
 
75
75
  swagger :show do
76
76
  params do
77
- path :id, schema: :integer, required: true
77
+ path :id, schema: :integer
78
78
  end
79
79
 
80
80
  render 200 do
81
81
  cref! UserSerializer
82
82
  end
83
83
  end
84
-
85
84
  def show
86
85
  render_ok User.find(schema_params[:id])
87
86
  end
@@ -104,12 +103,53 @@ class UsersController < ApplicationController
104
103
  end
105
104
  def create
106
105
  @user = User.new(schema_params[:user])
106
+
107
107
  if @user.save
108
108
  render_ok @user
109
109
  else
110
110
  render_bad @user.errors
111
111
  end
112
112
  end
113
+
114
+ swagger :update do
115
+ params do
116
+ path :id, schema: :string
117
+ end
118
+
119
+ body format: [:form, :json] do
120
+ user :object do
121
+ name :string
122
+ end
123
+ end
124
+
125
+ render 200 do
126
+ cref! UserSerializer
127
+ end
128
+ render 400 do
129
+ additionalProperties! do
130
+ array! { string! }
131
+ end
132
+ end
133
+ end
134
+ def update
135
+ @user = User.find(schema_params[:id])
136
+
137
+ if @user.update(schema_params[:user])
138
+ render_ok @user
139
+ else
140
+ render_bad @user.errors
141
+ end
142
+ end
143
+
144
+ swagger :destroy do
145
+ params do
146
+ path :id, schema: :string
147
+ end
148
+ end
149
+ def destroy
150
+ @user.destroy!
151
+ head :no_content
152
+ end
113
153
  end
114
154
  ```
115
155
 
@@ -119,6 +159,7 @@ Would you want to customize serialization?
119
159
  # app/serializers/base_serializer.rb
120
160
  class BaseSerializer
121
161
  include Swagger::Serializer
162
+ extend Swagger::DSL::Serializer
122
163
  end
123
164
  ```
124
165
 
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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.component(name).serializer(Swagger::Serializer::Store.current.serializer_options)
4
+ Swagger::Schema.current.component(name).serializer(Swagger::Serializer::Store.current.serialize_options)
5
5
  serializer.serialize(self)
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ module Swagger::Serializer::RailsController
9
9
 
10
10
  def render_serializer(code, format)
11
11
  response_obj = swagger_operation.responses[code]
12
- response_obj.content.send(format).serializer(Swagger::Serializer::Store.current.serializer_options)
12
+ response_obj.content.send(format).serializer(Swagger::Serializer::Store.current.serialize_options)
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(Swagger::Serializer::Store.current.serializer_options)
40
+ swagger_operation.parameters.deserializer(Swagger::Serializer::Store.current.deserialize_options)
41
41
  end
42
42
 
43
43
  def body_params
@@ -48,7 +48,7 @@ module Swagger::Serializer::RailsController
48
48
  @body_deserializer ||=
49
49
  if request.content_type
50
50
  swagger_operation.request_body.content[request.content_type]&.deserializer(
51
- Swagger::Serializer::Store.current.serializer_options,
51
+ Swagger::Serializer::Store.current.deserialize_options,
52
52
  )
53
53
  end
54
54
  end
@@ -7,16 +7,18 @@ module Swagger
7
7
  end
8
8
  end
9
9
 
10
- attr_reader :options
10
+ attr_reader :serialize_options, :deserialize_options
11
11
 
12
- def initialize(options = nil)
13
- @options = options || {}
14
- @options[:inject_key] ||= "title"
15
- @options[:injectors] ||= Injectors.new(cache: @options[:cache])
16
- end
12
+ def initialize(serialize_options: nil, deserialize_options: nil)
13
+ @serialize_options = serialize_options || {}
14
+ @deserialize_options = deserialize_options || {}
15
+
16
+ @serialize_options[:inject_key] ||= "title"
17
+ @deserialize_options[:inject_key] ||= "title"
17
18
 
18
- def serializer_options
19
- @options
19
+ injectors = Injectors.new(cache: @options[:cache])
20
+ @serialize_options[:injectors] ||= injectors
21
+ @deserialize_options[:injectors] ||= injectors
20
22
  end
21
23
 
22
24
  class Injectors
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Serializer
3
- VERSION = "0.5.2".freeze
3
+ VERSION = "0.6.0".freeze
4
4
  end
5
5
  end
File without changes
File without changes
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-01 00:00:00.000000000 Z
11
+ date: 2019-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema-serializer
@@ -234,7 +234,7 @@ metadata:
234
234
  homepage_uri: https://github.com/Narazaka/swagger-serializer
235
235
  source_code_uri: https://github.com/Narazaka/swagger-serializer.git
236
236
  changelog_uri: https://github.com/Narazaka/swagger-serializer/blob/master/CHANGELOG.md
237
- documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.5.2
237
+ documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.6.0
238
238
  post_install_message:
239
239
  rdoc_options: []
240
240
  require_paths:
@@ -250,7 +250,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  - !ruby/object:Gem::Version
251
251
  version: '0'
252
252
  requirements: []
253
- rubygems_version: 3.0.3
253
+ rubyforge_project:
254
+ rubygems_version: 2.7.6
254
255
  signing_key:
255
256
  specification_version: 4
256
257
  summary: Swagger (OpenAPI 3) schema based Serializer