Skip to content

Commit aba05d4

Browse files
committed
Hotfix: addParametersFromSecurity on assertHttpResponseForOperation
1 parent 348561f commit aba05d4

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

src/SwaggerWrapper.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,47 @@ protected function prepareOperation(Operation $operation)
7777
$operation = clone $operation;
7878
$operation->path = $this->swagger->basePath . $operation->path;
7979

80-
/**
81-
* I don't known How will be better
82-
* But I am going to add a new required Parameter to check this in Request Scheme
83-
*/
8480
if ($operation->security) {
85-
foreach ($operation->security as $security) {
86-
parent::assertInternalType(
87-
'array',
88-
$security,
89-
'Operation->security must be array of objects'
90-
);
81+
$this->addParametersFromSecurity($operation);
82+
}
9183

92-
$name = key($security);
84+
return $operation;
85+
}
9386

94-
$securityDefinition = $this->getSecurityByName($name);
95-
parent::assertInternalType(
96-
'object',
97-
$securityDefinition,
98-
"Unknown security definition {$name}"
99-
);
10087

101-
$operation->parameters[] = new Parameter(
102-
[
103-
'name' => $securityDefinition->name,
104-
'in' => $securityDefinition->in,
105-
'description' => $securityDefinition->description,
106-
'required' => true
107-
]
108-
);
109-
}
110-
}
88+
/**
89+
* I don't known How will be better
90+
* But I am going to add a new required Parameter to check this in Request Scheme
91+
*
92+
* @param Operation $operation
93+
*/
94+
protected function addParametersFromSecurity(Operation $operation)
95+
{
96+
foreach ($operation->security as $security) {
97+
parent::assertInternalType(
98+
'array',
99+
$security,
100+
'Operation->security must be array of objects'
101+
);
111102

112-
return $operation;
103+
$name = key($security);
104+
105+
$securityDefinition = $this->getSecurityByName($name);
106+
parent::assertInternalType(
107+
'object',
108+
$securityDefinition,
109+
"Unknown security definition {$name}"
110+
);
111+
112+
$operation->parameters[] = new Parameter(
113+
[
114+
'name' => $securityDefinition->name,
115+
'in' => $securityDefinition->in,
116+
'description' => $securityDefinition->description,
117+
'required' => true
118+
]
119+
);
120+
}
113121
}
114122

115123
/**
@@ -208,6 +216,11 @@ public function findResponseByStatusCode(Operation $path, $statusCode = 200)
208216
*/
209217
public function assertHttpResponseForOperation(Response $httpResponse, Operation $path, $statusCode = 200)
210218
{
219+
// User can mutate Operation->security, and we should re-enable it
220+
if ($path->security) {
221+
$this->addParametersFromSecurity($path);
222+
}
223+
211224
$response = $this->findResponseByStatusCode($path, $statusCode);
212225
if ($response) {
213226
return $this->assertHttpResponseForOperationResponse(

0 commit comments

Comments
 (0)