Skip to content

Commit 8dbf90f

Browse files
Add enum specification in order filter API docs
1 parent d047d85 commit 8dbf90f

File tree

6 files changed

+250
-2
lines changed

6 files changed

+250
-2
lines changed

src/Bridge/Doctrine/Common/Filter/OrderFilterTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public function getDescription(string $resourceClass): array
5252
'property' => $propertyName,
5353
'type' => 'string',
5454
'required' => false,
55+
'schema' => [
56+
'type' => 'string',
57+
'enum' => [
58+
strtolower(OrderFilterInterface::DIRECTION_ASC),
59+
strtolower(OrderFilterInterface::DIRECTION_DESC),
60+
],
61+
],
5562
];
5663
}
5764

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ private function getFiltersParameters(bool $v3, string $resourceClass, string $o
690690
$type = \in_array($data['type'], Type::$builtinTypes, true) ? $this->jsonSchemaTypeFactory->getType(new Type($data['type'], false, null, $data['is_collection'] ?? false)) : ['type' => 'string'];
691691
$v3 ? $parameter['schema'] = $type : $parameter += $type;
692692

693+
if ($v3 && isset($data['schema'])) {
694+
$parameter['schema'] = $data['schema'];
695+
}
696+
693697
if ('array' === ($type['type'] ?? '')) {
694698
$deepObject = \in_array($data['type'], [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT], true);
695699

tests/Bridge/Doctrine/Common/Filter/OrderFilterTestTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,25 @@ public function testGetDescription()
2828
'property' => 'id',
2929
'type' => 'string',
3030
'required' => false,
31+
'schema' => [
32+
'type' => 'string',
33+
'enum' => [
34+
'asc',
35+
'desc',
36+
],
37+
],
3138
],
3239
'order[name]' => [
3340
'property' => 'name',
3441
'type' => 'string',
3542
'required' => false,
43+
'schema' => [
44+
'type' => 'string',
45+
'enum' => [
46+
'asc',
47+
'desc',
48+
],
49+
],
3650
],
3751
], $filter->getDescription($this->resourceClass));
3852
}

tests/Bridge/Doctrine/MongoDbOdm/Filter/OrderFilterTest.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,81 +39,193 @@ public function testGetDescriptionDefaultFields()
3939
'property' => 'id',
4040
'type' => 'string',
4141
'required' => false,
42+
'schema' => [
43+
'type' => 'string',
44+
'enum' => [
45+
'asc',
46+
'desc',
47+
],
48+
],
4249
],
4350
'order[name]' => [
4451
'property' => 'name',
4552
'type' => 'string',
4653
'required' => false,
54+
'schema' => [
55+
'type' => 'string',
56+
'enum' => [
57+
'asc',
58+
'desc',
59+
],
60+
],
4761
],
4862
'order[alias]' => [
4963
'property' => 'alias',
5064
'type' => 'string',
5165
'required' => false,
66+
'schema' => [
67+
'type' => 'string',
68+
'enum' => [
69+
'asc',
70+
'desc',
71+
],
72+
],
5273
],
5374
'order[description]' => [
5475
'property' => 'description',
5576
'type' => 'string',
5677
'required' => false,
78+
'schema' => [
79+
'type' => 'string',
80+
'enum' => [
81+
'asc',
82+
'desc',
83+
],
84+
],
5785
],
5886
'order[dummy]' => [
5987
'property' => 'dummy',
6088
'type' => 'string',
6189
'required' => false,
90+
'schema' => [
91+
'type' => 'string',
92+
'enum' => [
93+
'asc',
94+
'desc',
95+
],
96+
],
6297
],
6398
'order[dummyDate]' => [
6499
'property' => 'dummyDate',
65100
'type' => 'string',
66101
'required' => false,
102+
'schema' => [
103+
'type' => 'string',
104+
'enum' => [
105+
'asc',
106+
'desc',
107+
],
108+
],
67109
],
68110
'order[dummyFloat]' => [
69111
'property' => 'dummyFloat',
70112
'type' => 'string',
71113
'required' => false,
114+
'schema' => [
115+
'type' => 'string',
116+
'enum' => [
117+
'asc',
118+
'desc',
119+
],
120+
],
72121
],
73122
'order[dummyPrice]' => [
74123
'property' => 'dummyPrice',
75124
'type' => 'string',
76125
'required' => false,
126+
'schema' => [
127+
'type' => 'string',
128+
'enum' => [
129+
'asc',
130+
'desc',
131+
],
132+
],
77133
],
78134
'order[jsonData]' => [
79135
'property' => 'jsonData',
80136
'type' => 'string',
81137
'required' => false,
138+
'schema' => [
139+
'type' => 'string',
140+
'enum' => [
141+
'asc',
142+
'desc',
143+
],
144+
],
82145
],
83146
'order[arrayData]' => [
84147
'property' => 'arrayData',
85148
'type' => 'string',
86149
'required' => false,
150+
'schema' => [
151+
'type' => 'string',
152+
'enum' => [
153+
'asc',
154+
'desc',
155+
],
156+
],
87157
],
88158
'order[name_converted]' => [
89159
'property' => 'name_converted',
90160
'type' => 'string',
91161
'required' => false,
162+
'schema' => [
163+
'type' => 'string',
164+
'enum' => [
165+
'asc',
166+
'desc',
167+
],
168+
],
92169
],
93170
'order[dummyBoolean]' => [
94171
'property' => 'dummyBoolean',
95172
'type' => 'string',
96173
'required' => false,
174+
'schema' => [
175+
'type' => 'string',
176+
'enum' => [
177+
'asc',
178+
'desc',
179+
],
180+
],
97181
],
98182
'order[relatedDummy]' => [
99183
'property' => 'relatedDummy',
100184
'type' => 'string',
101185
'required' => false,
186+
'schema' => [
187+
'type' => 'string',
188+
'enum' => [
189+
'asc',
190+
'desc',
191+
],
192+
],
102193
],
103194
'order[relatedDummies]' => [
104195
'property' => 'relatedDummies',
105196
'type' => 'string',
106197
'required' => false,
198+
'schema' => [
199+
'type' => 'string',
200+
'enum' => [
201+
'asc',
202+
'desc',
203+
],
204+
],
107205
],
108206
'order[relatedOwnedDummy]' => [
109207
'property' => 'relatedOwnedDummy',
110208
'type' => 'string',
111209
'required' => false,
210+
'schema' => [
211+
'type' => 'string',
212+
'enum' => [
213+
'asc',
214+
'desc',
215+
],
216+
],
112217
],
113218
'order[relatedOwningDummy]' => [
114219
'property' => 'relatedOwningDummy',
115220
'type' => 'string',
116221
'required' => false,
222+
'schema' => [
223+
'type' => 'string',
224+
'enum' => [
225+
'asc',
226+
'desc',
227+
],
228+
],
117229
],
118230
], $filter->getDescription($this->resourceClass));
119231
}

tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,61 +40,145 @@ public function testGetDescriptionDefaultFields()
4040
'property' => 'id',
4141
'type' => 'string',
4242
'required' => false,
43+
'schema' => [
44+
'type' => 'string',
45+
'enum' => [
46+
'asc',
47+
'desc',
48+
],
49+
],
4350
],
4451
'order[name]' => [
4552
'property' => 'name',
4653
'type' => 'string',
4754
'required' => false,
55+
'schema' => [
56+
'type' => 'string',
57+
'enum' => [
58+
'asc',
59+
'desc',
60+
],
61+
],
4862
],
4963
'order[alias]' => [
5064
'property' => 'alias',
5165
'type' => 'string',
5266
'required' => false,
67+
'schema' => [
68+
'type' => 'string',
69+
'enum' => [
70+
'asc',
71+
'desc',
72+
],
73+
],
5374
],
5475
'order[description]' => [
5576
'property' => 'description',
5677
'type' => 'string',
5778
'required' => false,
79+
'schema' => [
80+
'type' => 'string',
81+
'enum' => [
82+
'asc',
83+
'desc',
84+
],
85+
],
5886
],
5987
'order[dummy]' => [
6088
'property' => 'dummy',
6189
'type' => 'string',
6290
'required' => false,
91+
'schema' => [
92+
'type' => 'string',
93+
'enum' => [
94+
'asc',
95+
'desc',
96+
],
97+
],
6398
],
6499
'order[dummyDate]' => [
65100
'property' => 'dummyDate',
66101
'type' => 'string',
67102
'required' => false,
103+
'schema' => [
104+
'type' => 'string',
105+
'enum' => [
106+
'asc',
107+
'desc',
108+
],
109+
],
68110
],
69111
'order[dummyFloat]' => [
70112
'property' => 'dummyFloat',
71113
'type' => 'string',
72114
'required' => false,
115+
'schema' => [
116+
'type' => 'string',
117+
'enum' => [
118+
'asc',
119+
'desc',
120+
],
121+
],
73122
],
74123
'order[dummyPrice]' => [
75124
'property' => 'dummyPrice',
76125
'type' => 'string',
77126
'required' => false,
127+
'schema' => [
128+
'type' => 'string',
129+
'enum' => [
130+
'asc',
131+
'desc',
132+
],
133+
],
78134
],
79135
'order[jsonData]' => [
80136
'property' => 'jsonData',
81137
'type' => 'string',
82138
'required' => false,
139+
'schema' => [
140+
'type' => 'string',
141+
'enum' => [
142+
'asc',
143+
'desc',
144+
],
145+
],
83146
],
84147
'order[arrayData]' => [
85148
'property' => 'arrayData',
86149
'type' => 'string',
87150
'required' => false,
151+
'schema' => [
152+
'type' => 'string',
153+
'enum' => [
154+
'asc',
155+
'desc',
156+
],
157+
],
88158
],
89159
'order[name_converted]' => [
90160
'property' => 'name_converted',
91161
'type' => 'string',
92162
'required' => false,
163+
'schema' => [
164+
'type' => 'string',
165+
'enum' => [
166+
'asc',
167+
'desc',
168+
],
169+
],
93170
],
94171
'order[dummyBoolean]' => [
95172
'property' => 'dummyBoolean',
96173
'type' => 'string',
97174
'required' => false,
175+
'schema' => [
176+
'type' => 'string',
177+
'enum' => [
178+
'asc',
179+
'desc',
180+
],
181+
],
98182
],
99183
], $filter->getDescription($this->resourceClass));
100184
}

0 commit comments

Comments
 (0)