ree_lib 1.0.7 → 1.0.10

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: 956fffa1a41176330384decf8f4f3b45ce70801785ea5498a07e0cb0afdd6b0f
4
- data.tar.gz: 4745a3465a5ad18a6353ba21a8ef62b13991cd3cfc0fde7bf05ec41c7e561433
3
+ metadata.gz: 44e1a436822756b530e7f11947c68f43377096b4b15d8c6d60880a8f2116d1b2
4
+ data.tar.gz: cea2b849ec06361e461b282c93632cbcc2131bedfcbf260c87fcca56dfb53539
5
5
  SHA512:
6
- metadata.gz: afd9719357108c5bff745a3112c581f333de679e0ac9d41e02624d43f006584cdfec1080f40047be3fcfb816ea74275509ca2a841e718c06463e489d32e7a473
7
- data.tar.gz: 398d3fc0469aa20e71d37eaaf6422c76f8a0a86d155d548199bff1867a27612f0602ea7919715efd1aaf4f479417a2f03e2254d2e9ff4ba09b97fd2d1250632a
6
+ metadata.gz: 53f014bef46e41b7f1826ef4487ff0fce03c66b4578a7d6ddd65a37aaa94989aef52523dd368514f1e533b141aac9e9fedc341e4cc14b69dc4a1528482c53ed1
7
+ data.tar.gz: fe75d4036275c8a4013fbb064ced2f61b014c7ccccb5e48b7966e83f22f44adbc47345b37c01c2498f6f1d1dc035a21bf3ffa6a86a9aca0ac85665d8a13ac74b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.7)
4
+ ree_lib (1.0.10)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -36,9 +36,11 @@ GEM
36
36
  crass (~> 1.0.2)
37
37
  nokogiri (>= 1.5.9)
38
38
  msgpack (1.5.4)
39
+ nokogiri (1.13.8-x86_64-darwin)
40
+ racc (~> 1.4)
39
41
  nokogiri (1.13.8-x86_64-linux)
40
42
  racc (~> 1.4)
41
- oj (3.13.19)
43
+ oj (3.13.20)
42
44
  pg (1.4.2)
43
45
  public_suffix (4.0.7)
44
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
+ authenticate: Bool,
12
17
  summary: Nilor[String],
13
18
  description: Nilor[String],
14
19
  response_status: Integer,
@@ -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
@@ -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
  }
@@ -105,9 +108,11 @@ class ReeSwagger::BuildEndpointSchema
105
108
 
106
109
  method_schema[:summary] = endpoint.summary if endpoint.summary
107
110
  method_schema[:description] = endpoint.description if endpoint.description
111
+ method_schema[:tags] = endpoint.sections if endpoint.sections
108
112
 
109
113
  method_schema[:parameters] = parameters if parameters
110
114
  method_schema[:requestBody] = request_body if request_body
115
+ method_schema[:security] = [{ ApiKeyAuth: [] }] if endpoint.authenticate
111
116
 
112
117
  schema = {endpoint.method => method_schema}
113
118
 
@@ -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
@@ -35,9 +38,11 @@ class ReeSwagger::BuildRequestBodySchema
35
38
 
36
39
  return if properties.empty?
37
40
 
38
- {
41
+ obj = {
39
42
  type: 'object',
40
- properties: properties
43
+ properties: properties,
41
44
  }
45
+ obj[:required] = required_fields if required_fields.size != 0
46
+ obj
42
47
  end
43
48
  end
@@ -8,8 +8,8 @@ class ReeSwagger::BuildSchema
8
8
  link 'ree_swagger/dto/endpoint_dto', -> { EndpointDto }
9
9
  end
10
10
 
11
- contract(String, String, String, ArrayOf[EndpointDto] => Hash)
12
- def call(title:, description:, version:, endpoints:)
11
+ contract(String, String, String, String, ArrayOf[EndpointDto] => Hash)
12
+ def call(title:, description:, version:, api_url:, endpoints:)
13
13
  {
14
14
  openapi: "3.0.0",
15
15
  info: {
@@ -17,6 +17,16 @@ class ReeSwagger::BuildSchema
17
17
  description: description,
18
18
  version: version
19
19
  },
20
+ components: {
21
+ securitySchemes: {
22
+ ApiKeyAuth: {
23
+ type: 'apiKey',
24
+ in: 'header',
25
+ name: 'Authorization'
26
+ }
27
+ }
28
+ },
29
+ servers: [{ url: api_url }],
20
30
  paths: endpoints.each_with_object(Hash.new { _1[_2] = {} }) {
21
31
  path_dto = build_endpoint_schema(_1)
22
32
  _2[path_dto.path].merge!(path_dto.schema)
@@ -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
  ]
@@ -26,6 +26,10 @@
26
26
  "arg": "version",
27
27
  "type": "String"
28
28
  },
29
+ {
30
+ "arg": "api_url",
31
+ "type": "String"
32
+ },
29
33
  {
30
34
  "arg": "endpoints",
31
35
  "type": "ArrayOf[ReeSwagger::EndpointDto]"
@@ -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,9 +60,20 @@ 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,
74
+ authenticate: false,
65
75
  path: '/versions/:id',
76
+ sections: ["versions"],
66
77
  caster: caster,
67
78
  serializer: serializer,
68
79
  response_status: 200,
@@ -84,6 +95,20 @@ RSpec.describe :build_endpoint_schema do
84
95
  ]
85
96
  ))
86
97
 
98
+ csv_schema = build_endpoint_schema(ReeSwagger::EndpointDto.new(
99
+ method: :get,
100
+ respond_to: :csv,
101
+ authenticate: false,
102
+ path: '/files/:id',
103
+ sections: ["files"],
104
+ caster: file_caster,
105
+ serializer: file_serializer,
106
+ response_status: 200,
107
+ description: "file",
108
+ summary: "file summary",
109
+ errors: []
110
+ ))
111
+
87
112
  expect(schema).to eq(ReeSwagger::PathDto.new(
88
113
  path: '/versions/{id}',
89
114
  schema: {
@@ -108,13 +133,15 @@ RSpec.describe :build_endpoint_schema do
108
133
  properties: {
109
134
  name: { type: 'string' },
110
135
  value: { type: 'string' }
111
- }
136
+ },
137
+ required: ['name', 'value']
112
138
  },
113
139
  locale: {
114
140
  type: 'string',
115
141
  enum: ['en', 'ru']
116
142
  }
117
- }
143
+ },
144
+ required: ['name', 'tag', 'locale']
118
145
  }
119
146
  }
120
147
  }
@@ -143,6 +170,41 @@ RSpec.describe :build_endpoint_schema do
143
170
  },
144
171
  summary: "summary",
145
172
  description: "description",
173
+ tags: ["versions"]
174
+ }
175
+ }
176
+ ))
177
+
178
+ expect(csv_schema).to eq(ReeSwagger::PathDto.new(
179
+ path: '/files/{id}',
180
+ schema: {
181
+ get: {
182
+ parameters: [
183
+ {
184
+ name: 'id',
185
+ in: 'path',
186
+ required: true,
187
+ schema: { type: 'integer' }
188
+ }
189
+ ],
190
+ responses: {
191
+ 200 => {
192
+ description: '',
193
+ content: {
194
+ :'text/csv' => {
195
+ schema: {
196
+ type: 'object',
197
+ properties: {
198
+ data: { type: 'string' }
199
+ }
200
+ }
201
+ }
202
+ }
203
+ }
204
+ },
205
+ summary: "file summary",
206
+ description: "file",
207
+ tags: ["files"]
146
208
  }
147
209
  }
148
210
  ))
@@ -165,6 +227,8 @@ RSpec.describe :build_endpoint_schema do
165
227
  method: :get,
166
228
  path: '/versions/:id',
167
229
  caster: caster,
230
+ respond_to: :json,
231
+ authenticate: false,
168
232
  serializer: nil,
169
233
  response_status: 200,
170
234
  description: nil,
@@ -202,9 +266,11 @@ RSpec.describe :build_endpoint_schema do
202
266
  properties: {
203
267
  x: { type: 'integer' },
204
268
  y: { type: 'integer' }
205
- }
269
+ },
270
+ required: ['x', 'y']
206
271
  }
207
- }
272
+ },
273
+ required: ['text', 'point']
208
274
  },
209
275
  style: 'deepObject'
210
276
  }
@@ -224,6 +290,8 @@ RSpec.describe :build_endpoint_schema do
224
290
  build_endpoint_schema(ReeSwagger::EndpointDto.new(
225
291
  method: :get,
226
292
  path: '/versions/:id',
293
+ respond_to: :json,
294
+ authenticate: false,
227
295
  caster: nil,
228
296
  serializer: nil,
229
297
  response_status: 200,
@@ -246,6 +314,8 @@ RSpec.describe :build_endpoint_schema do
246
314
  build_endpoint_schema(ReeSwagger::EndpointDto.new(
247
315
  method: :get,
248
316
  path: '/versions/:id',
317
+ respond_to: :json,
318
+ authenticate: false,
249
319
  caster: caster,
250
320
  serializer: nil,
251
321
  response_status: 200,
@@ -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
@@ -6,9 +6,12 @@ RSpec.describe :build_schema do
6
6
  title: 'Sample API',
7
7
  description: 'Sample API description',
8
8
  version: '0.0.1',
9
+ api_url: 'https://some-api.com/api/v1',
9
10
  endpoints: [ReeSwagger::EndpointDto.new(
10
11
  method: :get,
12
+ authenticate: true,
11
13
  path: '/version',
14
+ respond_to: :json,
12
15
  caster: nil,
13
16
  serializer: nil,
14
17
  response_status: 200,
@@ -26,9 +29,24 @@ RSpec.describe :build_schema do
26
29
  description: 'Sample API description',
27
30
  version: '0.0.1'
28
31
  },
32
+ components: {
33
+ securitySchemes: {
34
+ bearerAuth: {
35
+ type: 'http',
36
+ scheme: 'bearer',
37
+ bearerFormat: 'JWT'
38
+ }
39
+ }
40
+ },
41
+ servers: [
42
+ { url: 'https://some-api.com/api/v1' }
43
+ ],
29
44
  paths: {
30
45
  '/version' => {
31
46
  get: {
47
+ security: [
48
+ {bearerAuth: []}
49
+ ],
32
50
  responses: {
33
51
  200 => {
34
52
  description: ''
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.7"
4
+ VERSION = "1.0.10"
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.7
4
+ version: 1.0.10
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-07 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