swagger-serializer 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9117f21413014f63963039d2bc4b9bd5af69822848e7171ab138db2f577e426f
4
- data.tar.gz: 9f8b7698fb58f7519642ca076962928ec7fbc6503307432e0f42a97900a20738
3
+ metadata.gz: a3b95443bcdbd807222b38fe709504b87c73ded014428c3b097e477f798352b1
4
+ data.tar.gz: 74dc8b92f4b88bbb6e631e099cb2a5ccc0700386836356e6b222b21d0f247a80
5
5
  SHA512:
6
- metadata.gz: 8cf2998a61d2755e0ac01ece1cf2d03e63e52013eb82add89a2fdc85d0249754ca8054dfb2edaf54bbb90bb9c5ef07280cabb1d0c946f749551a2e628cc7a330
7
- data.tar.gz: e46a73c62aa9e9d4217943df68d943b3370dd14da3b6c0db13b4897c7931177bc5379b1d4fed0ee9a653e1a10e51af46cf2cc17b35f579a97ef35bed9d1fcc64
6
+ metadata.gz: 66c21502bb24dafdf67de2b0c8d29204f25c5269fd0025ad0385f6cd04588363edd87d51a08e4c5460ff271bb63dc85a059dd29cc0a30f0d0d3f1e16fc5118d3
7
+ data.tar.gz: 7629f949146f38f9065b6401aecd7953b0086bfa4544b1d29b90c1400fd2e7746f81439109f92520c41da7771e83e8db46f28cff6ebc52a08500dc41f7eafe92
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+
5
+ - change store interface
6
+
7
+ ## 0.3.0
8
+
9
+ - change store interface
10
+
3
11
  ## 0.2.0
4
12
 
5
13
  - implove: injectors
data/README.md CHANGED
@@ -23,13 +23,123 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- ### Rails
26
+ ### Rails with swagger-dsl
27
+
28
+ use "[swagger-dsl](https://github.com/Narazaka/swagger-dsl)"!
29
+
30
+ Load it in initializer.
31
+
32
+ ```ruby
33
+ # config/initializers/swagger_serializer.rb
34
+
35
+ if Rails.application.config.eager_load
36
+ Rails.application.config.after_initialize do
37
+ Swagger::Schema.current = Swagger::Schema.new(Swagger::DSL.current.resolved)
38
+ end
39
+ else
40
+ Swagger::Schema.current = Swagger::Schema.new(Swagger::DSL.current)
41
+ Swagger::Serializer::Store.current.options[:resolver] = Swagger::DSL.current.resolver
42
+ end
43
+ ```
44
+
45
+ Use it in controllers.
46
+
47
+ ```ruby
48
+ # app/controllers/application_controller.rb
49
+ class ApplicationController < ActionController::Base
50
+ include Swagger::Serializer::RailsController
51
+
52
+ def render_ok(data)
53
+ render_as_schema 200, :json, data
54
+ end
55
+ end
56
+ ```
57
+
58
+ ```ruby
59
+ # app/controllers/users_controller.rb
60
+ class UsersController < ApplicationController
61
+ swagger :index do
62
+ render 200 do
63
+ array! { cref! UserSerializer }
64
+ end
65
+ end
66
+
67
+ def index
68
+ render_ok User.all
69
+ end
70
+
71
+ swagger :show do
72
+ params do
73
+ path :id, schema: :integer, required: true
74
+ end
75
+
76
+ render 200 do
77
+ cref! UserSerializer
78
+ end
79
+ end
80
+
81
+ def show
82
+ render_ok User.find(params[:id])
83
+ end
84
+ end
85
+ ```
86
+
87
+ Would you want to customize serialization?
88
+
89
+ ```ruby
90
+ # app/serializers/base_serializer.rb
91
+ class BaseSerializer
92
+ include Swagger::Serializer
93
+ end
94
+ ```
95
+
96
+ ```ruby
97
+ # app/serializers/user_serializer.rb
98
+ class UserSerializer < BaseSerializer
99
+ swagger do
100
+ id :integer
101
+ name :string, optional: true
102
+ end
103
+
104
+ def name
105
+ "#{@model.name}!!!!"
106
+ end
107
+ end
108
+ ```
109
+
110
+ Now you can get `{ "id" => 42, "name" => "me!!!!" }`.
111
+
112
+ This serializer class detection uses the schema's `title` key.
113
+ If you want to use `Foo::BarSerializer`, set `Foo::Bar` to `title` key.
114
+
115
+ The key is configurable by
116
+
117
+ ```ruby
118
+ # in config/initializers/swagger_serializer.rb
119
+ Swagger::Serializer::Store.current.options[:inject_key] = "my_inject_key"
120
+ Swagger::DSL.current.config.inject_key = "my_inject_key"
121
+ ```
122
+
123
+ Sometimes model needs direct serialize.
124
+
125
+ ```ruby
126
+ # app/models/application_record.rb
127
+ class ApplicationRecord < ActiveRecord::Base
128
+ self.abstract_class = true
129
+
130
+ include Swagger::Serializer::Model
131
+ end
132
+ ```
133
+
134
+ Now you can get serialized result by `p User.first.serialize`.
135
+
136
+ ### Rails with raw schema
27
137
 
28
138
  Write your OpenAPI spec.
29
139
 
30
140
  ```yaml
31
141
  # swagger.yml
32
- openapi: "3.0"
142
+ openapi: 3.0.0
33
143
  info:
34
144
  title: example api
35
145
  version: 0.1.0
@@ -71,16 +181,6 @@ Load it in initializer.
71
181
  Swagger::Schema.load_file_to_current(
72
182
  __dir__ + "/../../swagger.yml",
73
183
  )
74
-
75
- # Swagger::Schema accepts lazy load. So your swagger schema data instance may also be accepted.
76
- #
77
- # class SwaggerData
78
- # def paths
79
- # load_paths_now
80
- # end
81
- # end
82
- #
83
- # Swagger::Schema.current = Swagger::Schema.new(SwaggerData.new)
84
184
  ```
85
185
 
86
186
  Use it in controllers.
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Serializer
3
- VERSION = "0.4.0".freeze
3
+ VERSION = "0.4.1".freeze
4
4
  end
5
5
  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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narazaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2019-12-01 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.4.0
237
+ documentation_uri: https://www.rubydoc.info/gems/swagger-serializer/0.4.1
238
238
  post_install_message:
239
239
  rdoc_options: []
240
240
  require_paths: