Skip to content

Commit 15bbb52

Browse files
authored
check for dot in path and throw exception if found (#6986)
1 parent 73cb68e commit 15bbb52

File tree

9 files changed

+273
-84
lines changed

9 files changed

+273
-84
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
104104
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
105105
@SuppressWarnings("unchecked")
106106
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
107+
108+
for (CodegenOperation op : operations) {
109+
op.httpMethod = op.httpMethod.toLowerCase();
110+
// check to see if the path contains ".", which is not supported by Lumen
111+
// ref: https://github.com/swagger-api/swagger-codegen/issues/6897
112+
if (op.path != null && op.path.contains(".")) {
113+
throw new IllegalArgumentException("'.' (dot) is not supported by PHP Lumen. Please refer to https://github.com/swagger-api/swagger-codegen/issues/6897 for more info.");
114+
}
115+
}
107116

108117
// sort the endpoints in ascending to avoid the route priority issure.
109118
// https://github.com/swagger-api/swagger-codegen/issues/2643
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.3-SNAPSHOT
1+
2.3.0-SNAPSHOT
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* Swagger Petstore
5+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
6+
*
7+
* OpenAPI spec version: 1.0.0
8+
* Contact: [email protected]
9+
*
10+
* NOTE: This class is auto generated by the swagger code generator program.
11+
* https://github.com/swagger-api/swagger-codegen.git
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
namespace App\Http\Controllers;
17+
18+
use Illuminate\Support\Facades\Request;
19+
20+
class AnotherFakeApi extends Controller
21+
{
22+
/**
23+
* Constructor
24+
*/
25+
public function __construct()
26+
{
27+
}
28+
29+
/**
30+
* Operation testSpecialTags
31+
*
32+
* To test special tags.
33+
*
34+
*
35+
* @return Http response
36+
*/
37+
public function testSpecialTags()
38+
{
39+
$input = Request::all();
40+
41+
//path params validation
42+
43+
44+
//not path params validation
45+
if (!isset($input['body'])) {
46+
throw new \InvalidArgumentException('Missing the required parameter $body when calling testSpecialTags');
47+
}
48+
$body = $input['body'];
49+
50+
51+
return response('How about implementing testSpecialTags as a patch method ?');
52+
}
53+
}

samples/server/petstore/lumen/lib/app/Http/Controllers/FakeApi.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testClientModel()
4848
$body = $input['body'];
4949

5050

51-
return response('How about implementing testClientModel as a PATCH method ?');
51+
return response('How about implementing testClientModel as a patch method ?');
5252
}
5353
/**
5454
* Operation testEndpointParameters
@@ -146,7 +146,7 @@ public function testEndpointParameters()
146146
$callback = $input['callback'];
147147

148148

149-
return response('How about implementing testEndpointParameters as a POST method ?');
149+
return response('How about implementing testEndpointParameters as a post method ?');
150150
}
151151
/**
152152
* Operation testEnumParameters
@@ -181,7 +181,60 @@ public function testEnumParameters()
181181
$enum_query_double = $input['enum_query_double'];
182182

183183

184-
return response('How about implementing testEnumParameters as a GET method ?');
184+
return response('How about implementing testEnumParameters as a get method ?');
185+
}
186+
/**
187+
* Operation testInlineAdditionalProperties
188+
*
189+
* test inline additionalProperties.
190+
*
191+
*
192+
* @return Http response
193+
*/
194+
public function testInlineAdditionalProperties()
195+
{
196+
$input = Request::all();
197+
198+
//path params validation
199+
200+
201+
//not path params validation
202+
if (!isset($input['param'])) {
203+
throw new \InvalidArgumentException('Missing the required parameter $param when calling testInlineAdditionalProperties');
204+
}
205+
$param = $input['param'];
206+
207+
208+
return response('How about implementing testInlineAdditionalProperties as a post method ?');
209+
}
210+
/**
211+
* Operation testJsonFormData
212+
*
213+
* test json serialization of form data.
214+
*
215+
*
216+
* @return Http response
217+
*/
218+
public function testJsonFormData()
219+
{
220+
$input = Request::all();
221+
222+
//path params validation
223+
224+
225+
//not path params validation
226+
if (!isset($input['param'])) {
227+
throw new \InvalidArgumentException('Missing the required parameter $param when calling testJsonFormData');
228+
}
229+
$param = $input['param'];
230+
231+
if (!isset($input['param2'])) {
232+
throw new \InvalidArgumentException('Missing the required parameter $param2 when calling testJsonFormData');
233+
}
234+
$param2 = $input['param2'];
235+
236+
237+
return response('How about implementing testJsonFormData as a get method ?');
185238
}
186239
/**
187240
* Operation fakeOuterBooleanSerialize
@@ -202,7 +255,7 @@ public function fakeOuterBooleanSerialize()
202255
$body = $input['body'];
203256

204257

205-
return response('How about implementing fakeOuterBooleanSerialize as a POST method ?');
258+
return response('How about implementing fakeOuterBooleanSerialize as a post method ?');
206259
}
207260
/**
208261
* Operation fakeOuterCompositeSerialize
@@ -223,7 +276,7 @@ public function fakeOuterCompositeSerialize()
223276
$body = $input['body'];
224277

225278

226-
return response('How about implementing fakeOuterCompositeSerialize as a POST method ?');
279+
return response('How about implementing fakeOuterCompositeSerialize as a post method ?');
227280
}
228281
/**
229282
* Operation fakeOuterNumberSerialize
@@ -244,7 +297,7 @@ public function fakeOuterNumberSerialize()
244297
$body = $input['body'];
245298

246299

247-
return response('How about implementing fakeOuterNumberSerialize as a POST method ?');
300+
return response('How about implementing fakeOuterNumberSerialize as a post method ?');
248301
}
249302
/**
250303
* Operation fakeOuterStringSerialize
@@ -265,6 +318,6 @@ public function fakeOuterStringSerialize()
265318
$body = $input['body'];
266319

267320

268-
return response('How about implementing fakeOuterStringSerialize as a POST method ?');
321+
return response('How about implementing fakeOuterStringSerialize as a post method ?');
269322
}
270323
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* Swagger Petstore
5+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
6+
*
7+
* OpenAPI spec version: 1.0.0
8+
* Contact: [email protected]
9+
*
10+
* NOTE: This class is auto generated by the swagger code generator program.
11+
* https://github.com/swagger-api/swagger-codegen.git
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
namespace App\Http\Controllers;
17+
18+
use Illuminate\Support\Facades\Request;
19+
20+
class FakeClassnameTags123Api extends Controller
21+
{
22+
/**
23+
* Constructor
24+
*/
25+
public function __construct()
26+
{
27+
}
28+
29+
/**
30+
* Operation testClassname
31+
*
32+
* To test class name in snake case.
33+
*
34+
*
35+
* @return Http response
36+
*/
37+
public function testClassname()
38+
{
39+
$input = Request::all();
40+
41+
//path params validation
42+
43+
44+
//not path params validation
45+
if (!isset($input['body'])) {
46+
throw new \InvalidArgumentException('Missing the required parameter $body when calling testClassname');
47+
}
48+
$body = $input['body'];
49+
50+
51+
return response('How about implementing testClassname as a patch method ?');
52+
}
53+
}

samples/server/petstore/lumen/lib/app/Http/Controllers/PetApi.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function addPet()
4848
$body = $input['body'];
4949

5050

51-
return response('How about implementing addPet as a POST method ?');
51+
return response('How about implementing addPet as a post method ?');
5252
}
5353
/**
5454
* Operation updatePet
@@ -72,7 +72,7 @@ public function updatePet()
7272
$body = $input['body'];
7373

7474

75-
return response('How about implementing updatePet as a PUT method ?');
75+
return response('How about implementing updatePet as a put method ?');
7676
}
7777
/**
7878
* Operation findPetsByStatus
@@ -96,7 +96,7 @@ public function findPetsByStatus()
9696
$status = $input['status'];
9797

9898

99-
return response('How about implementing findPetsByStatus as a GET method ?');
99+
return response('How about implementing findPetsByStatus as a get method ?');
100100
}
101101
/**
102102
* Operation findPetsByTags
@@ -120,7 +120,7 @@ public function findPetsByTags()
120120
$tags = $input['tags'];
121121

122122

123-
return response('How about implementing findPetsByTags as a GET method ?');
123+
return response('How about implementing findPetsByTags as a get method ?');
124124
}
125125
/**
126126
* Operation deletePet
@@ -140,7 +140,7 @@ public function deletePet($pet_id)
140140

141141
//not path params validation
142142

143-
return response('How about implementing deletePet as a DELETE method ?');
143+
return response('How about implementing deletePet as a delete method ?');
144144
}
145145
/**
146146
* Operation getPetById
@@ -160,7 +160,7 @@ public function getPetById($pet_id)
160160

161161
//not path params validation
162162

163-
return response('How about implementing getPetById as a GET method ?');
163+
return response('How about implementing getPetById as a get method ?');
164164
}
165165
/**
166166
* Operation updatePetWithForm
@@ -180,7 +180,7 @@ public function updatePetWithForm($pet_id)
180180

181181
//not path params validation
182182

183-
return response('How about implementing updatePetWithForm as a POST method ?');
183+
return response('How about implementing updatePetWithForm as a post method ?');
184184
}
185185
/**
186186
* Operation uploadFile
@@ -200,6 +200,6 @@ public function uploadFile($pet_id)
200200

201201
//not path params validation
202202

203-
return response('How about implementing uploadFile as a POST method ?');
203+
return response('How about implementing uploadFile as a post method ?');
204204
}
205205
}

samples/server/petstore/lumen/lib/app/Http/Controllers/StoreApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getInventory()
4343

4444
//not path params validation
4545

46-
return response('How about implementing getInventory as a GET method ?');
46+
return response('How about implementing getInventory as a get method ?');
4747
}
4848
/**
4949
* Operation placeOrder
@@ -67,7 +67,7 @@ public function placeOrder()
6767
$body = $input['body'];
6868

6969

70-
return response('How about implementing placeOrder as a POST method ?');
70+
return response('How about implementing placeOrder as a post method ?');
7171
}
7272
/**
7373
* Operation deleteOrder
@@ -87,7 +87,7 @@ public function deleteOrder($order_id)
8787

8888
//not path params validation
8989

90-
return response('How about implementing deleteOrder as a DELETE method ?');
90+
return response('How about implementing deleteOrder as a delete method ?');
9191
}
9292
/**
9393
* Operation getOrderById
@@ -113,6 +113,6 @@ public function getOrderById($order_id)
113113

114114
//not path params validation
115115

116-
return response('How about implementing getOrderById as a GET method ?');
116+
return response('How about implementing getOrderById as a get method ?');
117117
}
118118
}

0 commit comments

Comments
 (0)