ree_lib 1.0.6 → 1.0.9

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: 6435a1a89e1206bbb9256d8b3f51c8b65116c7f4587c7a39da3e9abe1be80927
4
- data.tar.gz: 2803a3779d1c97ba0f03d46d747dfdec525305f5a5949db87f1c9a4f1396b825
3
+ metadata.gz: 756ef68a2b67f69d7b39d4877f51bebef0bf9f16c2d826f75a66fa43784ac779
4
+ data.tar.gz: f9668ac762030ae0b4e0d53d9edafd7751396b30e4b1f4ae67188b889aef6360
5
5
  SHA512:
6
- metadata.gz: d374c9f45acc8d5ba2c06b8646fe3959235b7270ae5d95738b26017622a475c06dd5666592ac80e57a7a0217a3086fe8e474c1480a623352eee91e1340df467b
7
- data.tar.gz: 8b173afe2cdcc4b65f0b5424c9ed621c3f351206566ca801eb9edd1555ba8ff48532fcaa3f53407ecc78976b8c3a652ab4c0fb5e1555d2bbb63851b0b6a69911
6
+ metadata.gz: 7f0f85267b26e8249d4c8c9d46532717acc53a4378e19e20e5f07e2431b751cee6591ac97677ffc528b651fef7428f868a73e9d87ef44103f94a21b412ff5f6d
7
+ data.tar.gz: c31dd2b537126f8590b656002f169fbce184448bedc79d4c0c58b7de769a940e5f780a7d73e70595a68966bafda85a13ef73031da79df69808d3eea5fb224352
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.6)
4
+ ree_lib (1.0.9)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -40,7 +40,7 @@ GEM
40
40
  racc (~> 1.4)
41
41
  nokogiri (1.13.8-x86_64-linux)
42
42
  racc (~> 1.4)
43
- oj (3.13.19)
43
+ oj (3.13.20)
44
44
  pg (1.4.2)
45
45
  public_suffix (4.0.7)
46
46
  racc (1.6.0)
@@ -5,7 +5,7 @@ class ReeHttp::BuildRequestExecutor
5
5
 
6
6
  fn :build_request_executor do
7
7
  link 'ree_http/constants', -> {
8
- DEFAULT_TIMEOUT & DEFAULT_WRITE_TIMEOUT & DEFAULT_FORCE_SSL
8
+ HTTPS & DEFAULT_TIMEOUT & DEFAULT_WRITE_TIMEOUT & DEFAULT_FORCE_SSL
9
9
  }
10
10
  end
11
11
 
@@ -47,7 +47,8 @@ class ReeHttp::BuildRequestExecutor
47
47
  request_executor.write_timeout = opts[:write_timeout]
48
48
  request_executor.read_timeout = opts[:timeout]
49
49
 
50
- request_executor.use_ssl = opts[:force_ssl]
50
+ request_executor.use_ssl = opts[:force_ssl] || uri.scheme == HTTPS
51
+
51
52
 
52
53
  if opts[:ca_certs?]
53
54
  request_executor = build_ca_certs(request_executor, opts[:ca_certs?])
@@ -48,6 +48,10 @@
48
48
  "name": "get_caster_definition",
49
49
  "schema": "packages/ree_swagger/schemas/ree_swagger/functions/get_caster_definition.schema.json"
50
50
  },
51
+ {
52
+ "name": "get_mime_type",
53
+ "schema": "packages/ree_swagger/schemas/ree_swagger/functions/get_mime_type.schema.json"
54
+ },
51
55
  {
52
56
  "name": "get_serializer_definition",
53
57
  "schema": "packages/ree_swagger/schemas/ree_swagger/functions/get_serializer_definition.schema.json"
@@ -3,12 +3,17 @@ class ReeSwagger::EndpointDto
3
3
  include Ree::LinkDSL
4
4
 
5
5
  link 'ree_swagger/dto/error_dto', -> { ErrorDto }
6
+ link 'ree_swagger/functions/get_mime_type', -> { MIME_TYPES }
7
+
6
8
 
7
9
  properties(
8
10
  method: Or[:get, :post, :put, :patch, :delete],
11
+ respond_to: Or[*MIME_TYPES.keys],
12
+ sections: Nilor[ArrayOf[String]],
9
13
  path: String,
10
14
  caster: Nilor[ReeMapper::Mapper],
11
15
  serializer: Nilor[ReeMapper::Mapper],
16
+ summary: Nilor[String],
12
17
  description: Nilor[String],
13
18
  response_status: Integer,
14
19
  response_description: Nilor[String],
@@ -4,6 +4,7 @@ class ReeSwagger::BuildEndpointSchema
4
4
  include Ree::FnDSL
5
5
 
6
6
  fn :build_endpoint_schema do
7
+ link :get_mime_type
7
8
  link :build_parameters
8
9
  link :build_request_body_schema
9
10
  link :build_serializer_schema
@@ -14,7 +15,7 @@ class ReeSwagger::BuildEndpointSchema
14
15
  METHODS_WITH_BODY = [:post, :put, :patch].freeze
15
16
  MissingCasterError = Class.new(StandardError)
16
17
 
17
- contract(EndpointDto => ReeSwagger::PathDto)
18
+ contract(EndpointDto => PathDto)
18
19
  def call(endpoint)
19
20
  path_params = []
20
21
 
@@ -31,6 +32,8 @@ class ReeSwagger::BuildEndpointSchema
31
32
  }
32
33
  .join('/')
33
34
 
35
+ mime_type = get_mime_type(endpoint.respond_to)
36
+
34
37
  missed_caster = path_params - endpoint.caster&.fields&.keys.to_a
35
38
 
36
39
  if missed_caster.any?
@@ -47,7 +50,7 @@ class ReeSwagger::BuildEndpointSchema
47
50
 
48
51
  request_body = request_body_schema && {
49
52
  content: {
50
- :'application/json' => {
53
+ :"#{mime_type}" => {
51
54
  schema: request_body_schema
52
55
  }
53
56
  }
@@ -65,7 +68,7 @@ class ReeSwagger::BuildEndpointSchema
65
68
 
66
69
  request_body_schema && {
67
70
  content: {
68
- :'application/json' => {
71
+ :"#{mime_type}" => {
69
72
  schema: request_body_schema
70
73
  }
71
74
  }
@@ -78,7 +81,7 @@ class ReeSwagger::BuildEndpointSchema
78
81
 
79
82
  if endpoint.serializer
80
83
  response_schema[:content] = {
81
- :'application/json' => {
84
+ :"#{mime_type}" => {
82
85
  schema: build_serializer_schema(endpoint.serializer)
83
86
  }
84
87
  }
@@ -103,12 +106,16 @@ class ReeSwagger::BuildEndpointSchema
103
106
  responses: responses
104
107
  }
105
108
 
109
+ method_schema[:summary] = endpoint.summary if endpoint.summary
110
+ method_schema[:description] = endpoint.description if endpoint.description
111
+ method_schema[:tags] = endpoint.sections if endpoint.sections
112
+
106
113
  method_schema[:parameters] = parameters if parameters
107
114
  method_schema[:requestBody] = request_body if request_body
108
115
 
109
116
  schema = {endpoint.method => method_schema}
110
117
 
111
- ReeSwagger::PathDto.new(
118
+ PathDto.new(
112
119
  path: path,
113
120
  schema: schema
114
121
  )
@@ -16,11 +16,14 @@ class ReeSwagger::BuildRequestBodySchema
16
16
  return get_caster_definition(mapper.type, method(:call).to_proc)
17
17
  end
18
18
 
19
+ required_fields = []
20
+
19
21
  properties = mapper.fields.each_with_object({}) do |(_name, field), acc|
20
22
  next if path_params.include?(field.name)
21
23
 
22
24
  swagger_field = {}
23
25
 
26
+ required_fields << field.name.to_s if !field.optional
24
27
  field_mapper = field.type
25
28
  swagger_type = call(field_mapper)
26
29
  swagger_field.merge!(swagger_type) if swagger_type
@@ -37,7 +40,8 @@ class ReeSwagger::BuildRequestBodySchema
37
40
 
38
41
  {
39
42
  type: 'object',
40
- properties: properties
43
+ properties: properties,
44
+ required: required_fields
41
45
  }
42
46
  end
43
47
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ReeSwagger::GetMimeType
4
+ include Ree::FnDSL
5
+
6
+ MIME_TYPES = {
7
+ :html => "text/html",
8
+ :text => "text/plain",
9
+ :js => "text/javascript",
10
+ :css => "text/css",
11
+ :ics => "text/calendar",
12
+ :csv => "text/csv",
13
+ :vcf => "text/vcard",
14
+ :vtt => "text/vtt",
15
+ :png => "image/png",
16
+ :jpeg => "image/jpeg",
17
+ :gif => "image/gif",
18
+ :bmp => "image/bmp",
19
+ :tiff => "image/tiff",
20
+ :svg => "image/svg+xml",
21
+ :mpeg => "video/mpeg",
22
+ :mp3 => "audio/mpeg",
23
+ :ogg => "audio/ogg",
24
+ :m4a => "audio/aac",
25
+ :webm => "video/webm",
26
+ :mp4 => "video/mp4",
27
+ :otf => "font/otf",
28
+ :ttf => "font/ttf",
29
+ :woff => "font/woff",
30
+ :woff2 => "font/woff2",
31
+ :xml => "application/xml",
32
+ :rss => "application/rss+xml",
33
+ :atom => "application/atom+xml",
34
+ :yaml => "application/x-yaml",
35
+ :multipart_form => "multipart/form-data",
36
+ :url_encoded_form => "application/x-www-form-urlencoded",
37
+ :json => "application/json",
38
+ :pdf => "application/pdf",
39
+ :zip => "application/zip",
40
+ :gzip => "application/gzip"
41
+ }.freeze
42
+
43
+ fn :get_mime_type
44
+
45
+ contract(Or[*MIME_TYPES.keys] => String)
46
+ def call(type)
47
+ MIME_TYPES.fetch(type)
48
+ end
49
+ end
@@ -44,6 +44,14 @@
44
44
  "as": "build_serializer_schema",
45
45
  "imports": [
46
46
 
47
+ ]
48
+ },
49
+ {
50
+ "target": "get_mime_type",
51
+ "package_name": "ree_swagger",
52
+ "as": "get_mime_type",
53
+ "imports": [
54
+
47
55
  ]
48
56
  }
49
57
  ]
@@ -0,0 +1,27 @@
1
+ {
2
+ "schema_type": "object",
3
+ "schema_version": "1.0",
4
+ "name": "get_mime_type",
5
+ "path": "packages/ree_swagger/package/ree_swagger/functions/get_mime_type.rb",
6
+ "mount_as": "fn",
7
+ "class": "ReeSwagger::GetMimeType",
8
+ "factory": null,
9
+ "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
13
+
14
+ ],
15
+ "return": "String",
16
+ "args": [
17
+ {
18
+ "arg": "type",
19
+ "type": "Or[html, text, js, css, ics, csv, vcf, vtt, png, jpeg, gif, bmp, tiff, svg, mpeg, mp3, ogg, m4a, webm, mp4, otf, ttf, woff, woff2, xml, rss, atom, yaml, multipart_f..., url_encoded..., json, pdf, zip, gzip]"
20
+ }
21
+ ]
22
+ }
23
+ ],
24
+ "links": [
25
+
26
+ ]
27
+ }
@@ -60,13 +60,24 @@ RSpec.describe :build_endpoint_schema do
60
60
  locales :locale
61
61
  end
62
62
 
63
+ file_caster = mapper_factory.call.use(:cast) do
64
+ integer :id
65
+ end
66
+
67
+ file_serializer = mapper_factory.call.use(:serialize) do
68
+ string :data
69
+ end
70
+
63
71
  schema = build_endpoint_schema(ReeSwagger::EndpointDto.new(
64
72
  method: :post,
73
+ respond_to: :json,
65
74
  path: '/versions/:id',
75
+ sections: ["versions"],
66
76
  caster: caster,
67
77
  serializer: serializer,
68
78
  response_status: 200,
69
- description: nil,
79
+ description: "description",
80
+ summary: "summary",
70
81
  errors: [
71
82
  ReeSwagger::ErrorDto.new(
72
83
  status: 400,
@@ -83,6 +94,19 @@ RSpec.describe :build_endpoint_schema do
83
94
  ]
84
95
  ))
85
96
 
97
+ csv_schema = build_endpoint_schema(ReeSwagger::EndpointDto.new(
98
+ method: :get,
99
+ respond_to: :csv,
100
+ path: '/files/:id',
101
+ sections: ["files"],
102
+ caster: file_caster,
103
+ serializer: file_serializer,
104
+ response_status: 200,
105
+ description: "file",
106
+ summary: "file summary",
107
+ errors: []
108
+ ))
109
+
86
110
  expect(schema).to eq(ReeSwagger::PathDto.new(
87
111
  path: '/versions/{id}',
88
112
  schema: {
@@ -107,13 +131,15 @@ RSpec.describe :build_endpoint_schema do
107
131
  properties: {
108
132
  name: { type: 'string' },
109
133
  value: { type: 'string' }
110
- }
134
+ },
135
+ required: ['name', 'value']
111
136
  },
112
137
  locale: {
113
138
  type: 'string',
114
139
  enum: ['en', 'ru']
115
140
  }
116
- }
141
+ },
142
+ required: ['name', 'tag', 'locale']
117
143
  }
118
144
  }
119
145
  }
@@ -139,7 +165,44 @@ RSpec.describe :build_endpoint_schema do
139
165
  401 => {
140
166
  description: "- 401 error",
141
167
  }
142
- }
168
+ },
169
+ summary: "summary",
170
+ description: "description",
171
+ tags: ["versions"]
172
+ }
173
+ }
174
+ ))
175
+
176
+ expect(csv_schema).to eq(ReeSwagger::PathDto.new(
177
+ path: '/files/{id}',
178
+ schema: {
179
+ get: {
180
+ parameters: [
181
+ {
182
+ name: 'id',
183
+ in: 'path',
184
+ required: true,
185
+ schema: { type: 'integer' }
186
+ }
187
+ ],
188
+ responses: {
189
+ 200 => {
190
+ description: '',
191
+ content: {
192
+ :'text/csv' => {
193
+ schema: {
194
+ type: 'object',
195
+ properties: {
196
+ data: { type: 'string' }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ },
203
+ summary: "file summary",
204
+ description: "file",
205
+ tags: ["files"]
143
206
  }
144
207
  }
145
208
  ))
@@ -162,9 +225,11 @@ RSpec.describe :build_endpoint_schema do
162
225
  method: :get,
163
226
  path: '/versions/:id',
164
227
  caster: caster,
228
+ respond_to: :json,
165
229
  serializer: nil,
166
230
  response_status: 200,
167
231
  description: nil,
232
+ summary: nil,
168
233
  errors: []
169
234
  ))
170
235
 
@@ -198,9 +263,11 @@ RSpec.describe :build_endpoint_schema do
198
263
  properties: {
199
264
  x: { type: 'integer' },
200
265
  y: { type: 'integer' }
201
- }
266
+ },
267
+ required: ['x', 'y']
202
268
  }
203
- }
269
+ },
270
+ required: ['text', 'point']
204
271
  },
205
272
  style: 'deepObject'
206
273
  }
@@ -220,10 +287,12 @@ RSpec.describe :build_endpoint_schema do
220
287
  build_endpoint_schema(ReeSwagger::EndpointDto.new(
221
288
  method: :get,
222
289
  path: '/versions/:id',
290
+ respond_to: :json,
223
291
  caster: nil,
224
292
  serializer: nil,
225
293
  response_status: 200,
226
294
  description: nil,
295
+ summary: nil,
227
296
  errors: []
228
297
  ))
229
298
  }.to raise_error(
@@ -241,10 +310,12 @@ RSpec.describe :build_endpoint_schema do
241
310
  build_endpoint_schema(ReeSwagger::EndpointDto.new(
242
311
  method: :get,
243
312
  path: '/versions/:id',
313
+ respond_to: :json,
244
314
  caster: caster,
245
315
  serializer: nil,
246
316
  response_status: 200,
247
317
  description: nil,
318
+ summary: nil,
248
319
  errors: []
249
320
  ))
250
321
  }.to raise_error(
@@ -0,0 +1,35 @@
1
+ RSpec.describe :build_request_body_schema_spec do
2
+ link :build_request_body_schema, from: :ree_swagger
3
+ link :build_mapper_factory, from: :ree_mapper
4
+ link :build_mapper_strategy, from: :ree_mapper
5
+
6
+ let(:mapper_factory) {
7
+ strategies = [
8
+ build_mapper_strategy(method: :cast, output: :symbol_key_hash),
9
+ ]
10
+
11
+ build_mapper_factory(
12
+ strategies: strategies
13
+ )
14
+ }
15
+
16
+ it {
17
+ caster = mapper_factory.call.use(:cast) do
18
+ string :name
19
+ string :email
20
+ string? :last_name
21
+ end
22
+
23
+ schema = {
24
+ type: "object",
25
+ properties: {
26
+ name: { type: "string" },
27
+ email: { type: "string" },
28
+ last_name: { type: "string" }
29
+ },
30
+ required: ["name", "email"]
31
+ }
32
+
33
+ expect(build_request_body_schema(caster)).to eq(schema)
34
+ }
35
+ end
@@ -9,10 +9,12 @@ RSpec.describe :build_schema do
9
9
  endpoints: [ReeSwagger::EndpointDto.new(
10
10
  method: :get,
11
11
  path: '/version',
12
+ respond_to: :json,
12
13
  caster: nil,
13
14
  serializer: nil,
14
15
  response_status: 200,
15
16
  description: nil,
17
+ summary: nil,
16
18
  errors: []
17
19
  )]
18
20
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree
@@ -1122,6 +1122,7 @@ files:
1122
1122
  - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_schema.rb
1123
1123
  - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
1124
1124
  - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_caster_definition.rb
1125
+ - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_mime_type.rb
1125
1126
  - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_serializer_definition.rb
1126
1127
  - lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/register_type.rb
1127
1128
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/beans/type_definitions_repo.schema.json
@@ -1131,10 +1132,12 @@ files:
1131
1132
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_schema.schema.json
1132
1133
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/build_serializer_schema.schema.json
1133
1134
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/get_caster_definition.schema.json
1135
+ - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/get_mime_type.schema.json
1134
1136
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/get_serializer_definition.schema.json
1135
1137
  - lib/ree_lib/packages/ree_swagger/schemas/ree_swagger/functions/register_type.schema.json
1136
1138
  - lib/ree_lib/packages/ree_swagger/spec/functions/build_endpoint_schema_spec.rb
1137
1139
  - lib/ree_lib/packages/ree_swagger/spec/functions/build_parameters_spec.rb
1140
+ - lib/ree_lib/packages/ree_swagger/spec/functions/build_request_body_spec.rb
1138
1141
  - lib/ree_lib/packages/ree_swagger/spec/functions/build_schema_spec.rb
1139
1142
  - lib/ree_lib/packages/ree_swagger/spec/functions/build_serializer_schema_spec.rb
1140
1143
  - lib/ree_lib/packages/ree_swagger/spec/functions/register_type_spec.rb