ree_lib 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_enum/Package.schema.json +3 -0
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/dsl.rb +21 -0
- data/lib/ree_lib/packages/ree_enum/package/ree_enum.rb +1 -0
- data/lib/ree_lib/packages/ree_swagger/Package.schema.json +3 -0
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/beans/type_definitions_repo.rb +16 -16
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_endpoint_schema.rb +2 -20
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_caster_definition.rb +1 -1
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_serializer_definition.rb +1 -1
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/register_type.rb +1 -1
- data/lib/ree_lib/packages/ree_swagger/package/ree_swagger.rb +1 -0
- data/lib/ree_lib/packages/ree_swagger/spec/functions/build_endpoint_schema_spec.rb +37 -38
- data/lib/ree_lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff525a1db86ff974abe2f0095d70921fa49e324b808723042b1671140b372809
|
4
|
+
data.tar.gz: 899723f369a42828b8dc094cdcaf96c10d78704e23f95b9500ed76d453858f3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a8630ad6fbb14f70ffef61be34708befd543be814a29fb81afda8a9020b8b46222e4aca37662e8504dbab8d43d408e9850168acc50595962245c93a4b377155
|
7
|
+
data.tar.gz: 1eb4b5d094c9b5aabf5882f5c055594348ea7a818920a1e55e87f48765e66dd0e2718a6643d7d4ba65f70ded911dd2a5575ad401497a5c69765f0700f34804cc
|
data/Gemfile.lock
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
package_require 'ree_swagger/functions/register_type'
|
2
|
+
|
1
3
|
module ReeEnum
|
2
4
|
module DSL
|
3
5
|
def self.included(base)
|
@@ -92,7 +94,26 @@ module ReeEnum
|
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
97
|
+
def register_as_swagger_type
|
98
|
+
swagger_type_registrator = ReeSwagger::RegisterType.new
|
99
|
+
|
100
|
+
[:casters, :serializers].each do |kind|
|
101
|
+
swagger_type_registrator.call(
|
102
|
+
kind,
|
103
|
+
type_for_mapper.class,
|
104
|
+
->(*) {
|
105
|
+
{
|
106
|
+
type: 'string',
|
107
|
+
enum: values.all.map(&:to_s)
|
108
|
+
}
|
109
|
+
}
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
95
114
|
def register_as_mapper_type
|
115
|
+
register_as_swagger_type
|
116
|
+
|
96
117
|
mapper_factory = ReeMapper.get_mapper_factory(
|
97
118
|
Object.const_get(self.name.split('::').first)
|
98
119
|
)
|
@@ -9,40 +9,40 @@ class ReeSwagger::TypeDefinitionsRepo
|
|
9
9
|
def build
|
10
10
|
{
|
11
11
|
serializers: {
|
12
|
-
|
12
|
+
ReeMapper::Integer => ->(*) {
|
13
13
|
{ type: 'integer' }
|
14
14
|
},
|
15
|
-
|
15
|
+
ReeMapper::String => ->(*) {
|
16
16
|
{ type: 'string' }
|
17
17
|
},
|
18
|
-
|
18
|
+
ReeMapper::Bool => ->(*) {
|
19
19
|
{ type: 'boolean' }
|
20
20
|
},
|
21
|
-
|
21
|
+
ReeMapper::Float => ->(*) {
|
22
22
|
{
|
23
23
|
type: 'number',
|
24
24
|
format: 'float'
|
25
25
|
}
|
26
26
|
},
|
27
|
-
|
27
|
+
ReeMapper::Array => ->(type, build_serializer_schema) {
|
28
28
|
{
|
29
29
|
type: 'array',
|
30
30
|
items: build_serializer_schema.(type.of.type)
|
31
31
|
}
|
32
32
|
},
|
33
|
-
|
33
|
+
ReeMapper::DateTime => ->(*) {
|
34
34
|
{
|
35
35
|
type: 'string',
|
36
36
|
format: 'date-time'
|
37
37
|
}
|
38
38
|
},
|
39
|
-
|
39
|
+
ReeMapper::Date => ->(*) {
|
40
40
|
{
|
41
41
|
type: 'string',
|
42
42
|
format: 'date'
|
43
43
|
}
|
44
44
|
},
|
45
|
-
|
45
|
+
ReeMapper::Time => ->(*) {
|
46
46
|
{
|
47
47
|
type: 'string',
|
48
48
|
format: 'date-time'
|
@@ -50,40 +50,40 @@ class ReeSwagger::TypeDefinitionsRepo
|
|
50
50
|
}
|
51
51
|
},
|
52
52
|
casters: {
|
53
|
-
|
53
|
+
ReeMapper::Integer => ->(*) {
|
54
54
|
{ type: 'integer' }
|
55
55
|
},
|
56
|
-
|
56
|
+
ReeMapper::String => ->(*) {
|
57
57
|
{ type: 'string' }
|
58
58
|
},
|
59
|
-
|
59
|
+
ReeMapper::Bool => ->(*) {
|
60
60
|
{ type: 'boolean' }
|
61
61
|
},
|
62
|
-
|
62
|
+
ReeMapper::Float => ->(*) {
|
63
63
|
{
|
64
64
|
type: 'number',
|
65
65
|
format: 'float'
|
66
66
|
}
|
67
67
|
},
|
68
|
-
|
68
|
+
ReeMapper::Array => ->(type, build_caster_schema) {
|
69
69
|
{
|
70
70
|
type: 'array',
|
71
71
|
items: build_caster_schema.(type.of.type)
|
72
72
|
}
|
73
73
|
},
|
74
|
-
|
74
|
+
ReeMapper::DateTime => ->(*) {
|
75
75
|
{
|
76
76
|
type: 'string',
|
77
77
|
format: 'date-time'
|
78
78
|
}
|
79
79
|
},
|
80
|
-
|
80
|
+
ReeMapper::Date => ->(*) {
|
81
81
|
{
|
82
82
|
type: 'string',
|
83
83
|
format: 'date'
|
84
84
|
}
|
85
85
|
},
|
86
|
-
|
86
|
+
ReeMapper::Time => ->(*) {
|
87
87
|
{
|
88
88
|
type: 'string',
|
89
89
|
format: 'date-time'
|
data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_endpoint_schema.rb
CHANGED
@@ -90,30 +90,12 @@ class ReeSwagger::BuildEndpointSchema
|
|
90
90
|
|
91
91
|
endpoint.errors.each do |error|
|
92
92
|
if responses.key?(error.status)
|
93
|
-
responses[error.status][:description] += "\n
|
93
|
+
responses[error.status][:description] += "\n- #{error.description}"
|
94
94
|
next
|
95
95
|
end
|
96
96
|
|
97
97
|
responses[error.status] = {
|
98
|
-
description: error.description,
|
99
|
-
content: {
|
100
|
-
:'application/json' => {
|
101
|
-
schema: {
|
102
|
-
type: 'object',
|
103
|
-
properties: {
|
104
|
-
code: {
|
105
|
-
type: "string"
|
106
|
-
},
|
107
|
-
message: {
|
108
|
-
type: "string"
|
109
|
-
},
|
110
|
-
type: {
|
111
|
-
type: "string"
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
98
|
+
description: "- #{error.description}",
|
117
99
|
}
|
118
100
|
end
|
119
101
|
|
data/lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/get_serializer_definition.rb
CHANGED
@@ -10,7 +10,7 @@ class ReeSwagger::GetSerializerDefinition
|
|
10
10
|
contract(Any, Proc => Nilor[Hash])
|
11
11
|
def call(type, build_serializer_schema)
|
12
12
|
type_definitions_repo
|
13
|
-
.dig(:serializers, type.class
|
13
|
+
.dig(:serializers, type.class)
|
14
14
|
&.(type, build_serializer_schema)
|
15
15
|
end
|
16
16
|
end
|
@@ -12,7 +12,7 @@ class ReeSwagger::RegisterType
|
|
12
12
|
contract(Or[:casters, :serializers], Any, Proc => nil)
|
13
13
|
def call(kind, type, definition)
|
14
14
|
SEMAPHORE.synchronize do
|
15
|
-
type_definitions_repo[kind][type
|
15
|
+
type_definitions_repo[kind][type] = definition
|
16
16
|
end
|
17
17
|
|
18
18
|
nil
|
@@ -3,6 +3,14 @@ RSpec.describe :build_endpoint_schema do
|
|
3
3
|
link :build_mapper_factory, from: :ree_mapper
|
4
4
|
link :build_mapper_strategy, from: :ree_mapper
|
5
5
|
|
6
|
+
before :all do
|
7
|
+
Ree.enable_irb_mode
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
Ree.disable_irb_mode
|
12
|
+
end
|
13
|
+
|
6
14
|
let(:mapper_factory) {
|
7
15
|
strategies = [
|
8
16
|
build_mapper_strategy(method: :serialize, output: :symbol_key_hash),
|
@@ -15,6 +23,27 @@ RSpec.describe :build_endpoint_schema do
|
|
15
23
|
}
|
16
24
|
|
17
25
|
it {
|
26
|
+
module ReeSwaggerTest
|
27
|
+
include Ree::PackageDSL
|
28
|
+
|
29
|
+
package
|
30
|
+
|
31
|
+
class Locales
|
32
|
+
include ReeEnum::DSL
|
33
|
+
|
34
|
+
enum :locales
|
35
|
+
|
36
|
+
val :en, 0
|
37
|
+
val :ru, 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
mapper_factory.register_type(
|
42
|
+
:locales, ReeSwaggerTest::Locales.type_for_mapper
|
43
|
+
)
|
44
|
+
|
45
|
+
ReeSwaggerTest::Locales.register_as_swagger_type
|
46
|
+
|
18
47
|
serializer = mapper_factory.call.use(:serialize) do
|
19
48
|
integer :id
|
20
49
|
end
|
@@ -28,6 +57,7 @@ RSpec.describe :build_endpoint_schema do
|
|
28
57
|
integer :id
|
29
58
|
string :name
|
30
59
|
tag :tag
|
60
|
+
locales :locale
|
31
61
|
end
|
32
62
|
|
33
63
|
schema = build_endpoint_schema(ReeSwagger::EndpointDto.new(
|
@@ -78,6 +108,10 @@ RSpec.describe :build_endpoint_schema do
|
|
78
108
|
name: { type: 'string' },
|
79
109
|
value: { type: 'string' }
|
80
110
|
}
|
111
|
+
},
|
112
|
+
locale: {
|
113
|
+
type: 'string',
|
114
|
+
enum: ['en', 'ru']
|
81
115
|
}
|
82
116
|
}
|
83
117
|
}
|
@@ -99,46 +133,11 @@ RSpec.describe :build_endpoint_schema do
|
|
99
133
|
}
|
100
134
|
},
|
101
135
|
400 => {
|
102
|
-
description: "1st 400 error\n
|
103
|
-
|
104
|
-
:'application/json' => {
|
105
|
-
schema: {
|
106
|
-
type: 'object',
|
107
|
-
properties: {
|
108
|
-
code: {
|
109
|
-
type: "string"
|
110
|
-
},
|
111
|
-
message: {
|
112
|
-
type: "string"
|
113
|
-
},
|
114
|
-
type: {
|
115
|
-
type: "string"
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
136
|
+
description: "- 1st 400 error\n- 2nd 400 error",
|
137
|
+
|
121
138
|
},
|
122
139
|
401 => {
|
123
|
-
description: "401 error",
|
124
|
-
content: {
|
125
|
-
:'application/json' => {
|
126
|
-
schema: {
|
127
|
-
type: 'object',
|
128
|
-
properties: {
|
129
|
-
code: {
|
130
|
-
type: "string"
|
131
|
-
},
|
132
|
-
message: {
|
133
|
-
type: "string"
|
134
|
-
},
|
135
|
-
type: {
|
136
|
-
type: "string"
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
140
|
+
description: "- 401 error",
|
142
141
|
}
|
143
142
|
}
|
144
143
|
}
|
data/lib/ree_lib/version.rb
CHANGED