Skip to content

Commit 81fb7a0

Browse files
authored
[php-nextgen] Allow unsetting api keys / api key prefixes by passing a null value to setApiKey (#25101)
1 parent 2ffb4ee commit 81fb7a0

4 files changed

Lines changed: 64 additions & 32 deletions

File tree

‎modules/openapi-generator/src/main/resources/php-nextgen/Configuration.mustache‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,18 @@ class Configuration
132132
/**
133133
* Sets API key
134134
*
135-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
136-
* @param string $key API key or token
135+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
136+
* @param string|null $key API key or token
137137
*
138138
* @return $this
139139
*/
140-
public function setApiKey(string $apiKeyIdentifier, string $key): static
140+
public function setApiKey(string $apiKeyIdentifier, ?string $key): static
141141
{
142-
$this->apiKeys[$apiKeyIdentifier] = $key;
142+
if ($key === null) {
143+
unset($this->apiKeys[$apiKeyIdentifier]);
144+
} else {
145+
$this->apiKeys[$apiKeyIdentifier] = $key;
146+
}
143147
return $this;
144148
}
145149

@@ -158,14 +162,18 @@ class Configuration
158162
/**
159163
* Sets the prefix for API key (e.g. Bearer)
160164
*
161-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
162-
* @param string $prefix API key prefix, e.g. Bearer
165+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
166+
* @param string|null $prefix API key prefix, e.g. Bearer
163167
*
164168
* @return $this
165169
*/
166-
public function setApiKeyPrefix(string $apiKeyIdentifier, string $prefix): static
170+
public function setApiKeyPrefix(string $apiKeyIdentifier, ?string $prefix): static
167171
{
168-
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
172+
if ($prefix === null) {
173+
unset($this->apiKeyPrefixes[$apiKeyIdentifier]);
174+
} else {
175+
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
176+
}
169177
return $this;
170178
}
171179

‎samples/client/echo_api/php-nextgen-streaming/src/Configuration.php‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,18 @@ public function __construct()
141141
/**
142142
* Sets API key
143143
*
144-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
145-
* @param string $key API key or token
144+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
145+
* @param string|null $key API key or token
146146
*
147147
* @return $this
148148
*/
149-
public function setApiKey(string $apiKeyIdentifier, string $key): static
149+
public function setApiKey(string $apiKeyIdentifier, ?string $key): static
150150
{
151-
$this->apiKeys[$apiKeyIdentifier] = $key;
151+
if ($key === null) {
152+
unset($this->apiKeys[$apiKeyIdentifier]);
153+
} else {
154+
$this->apiKeys[$apiKeyIdentifier] = $key;
155+
}
152156
return $this;
153157
}
154158

@@ -167,14 +171,18 @@ public function getApiKey(string $apiKeyIdentifier): ?string
167171
/**
168172
* Sets the prefix for API key (e.g. Bearer)
169173
*
170-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
171-
* @param string $prefix API key prefix, e.g. Bearer
174+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
175+
* @param string|null $prefix API key prefix, e.g. Bearer
172176
*
173177
* @return $this
174178
*/
175-
public function setApiKeyPrefix(string $apiKeyIdentifier, string $prefix): static
179+
public function setApiKeyPrefix(string $apiKeyIdentifier, ?string $prefix): static
176180
{
177-
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
181+
if ($prefix === null) {
182+
unset($this->apiKeyPrefixes[$apiKeyIdentifier]);
183+
} else {
184+
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
185+
}
178186
return $this;
179187
}
180188

‎samples/client/echo_api/php-nextgen/src/Configuration.php‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,18 @@ public function __construct()
141141
/**
142142
* Sets API key
143143
*
144-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
145-
* @param string $key API key or token
144+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
145+
* @param string|null $key API key or token
146146
*
147147
* @return $this
148148
*/
149-
public function setApiKey(string $apiKeyIdentifier, string $key): static
149+
public function setApiKey(string $apiKeyIdentifier, ?string $key): static
150150
{
151-
$this->apiKeys[$apiKeyIdentifier] = $key;
151+
if ($key === null) {
152+
unset($this->apiKeys[$apiKeyIdentifier]);
153+
} else {
154+
$this->apiKeys[$apiKeyIdentifier] = $key;
155+
}
152156
return $this;
153157
}
154158

@@ -167,14 +171,18 @@ public function getApiKey(string $apiKeyIdentifier): ?string
167171
/**
168172
* Sets the prefix for API key (e.g. Bearer)
169173
*
170-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
171-
* @param string $prefix API key prefix, e.g. Bearer
174+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
175+
* @param string|null $prefix API key prefix, e.g. Bearer
172176
*
173177
* @return $this
174178
*/
175-
public function setApiKeyPrefix(string $apiKeyIdentifier, string $prefix): static
179+
public function setApiKeyPrefix(string $apiKeyIdentifier, ?string $prefix): static
176180
{
177-
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
181+
if ($prefix === null) {
182+
unset($this->apiKeyPrefixes[$apiKeyIdentifier]);
183+
} else {
184+
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
185+
}
178186
return $this;
179187
}
180188

‎samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Configuration.php‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ public function __construct()
140140
/**
141141
* Sets API key
142142
*
143-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
144-
* @param string $key API key or token
143+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
144+
* @param string|null $key API key or token
145145
*
146146
* @return $this
147147
*/
148-
public function setApiKey(string $apiKeyIdentifier, string $key): static
148+
public function setApiKey(string $apiKeyIdentifier, ?string $key): static
149149
{
150-
$this->apiKeys[$apiKeyIdentifier] = $key;
150+
if ($key === null) {
151+
unset($this->apiKeys[$apiKeyIdentifier]);
152+
} else {
153+
$this->apiKeys[$apiKeyIdentifier] = $key;
154+
}
151155
return $this;
152156
}
153157

@@ -166,14 +170,18 @@ public function getApiKey(string $apiKeyIdentifier): ?string
166170
/**
167171
* Sets the prefix for API key (e.g. Bearer)
168172
*
169-
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
170-
* @param string $prefix API key prefix, e.g. Bearer
173+
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
174+
* @param string|null $prefix API key prefix, e.g. Bearer
171175
*
172176
* @return $this
173177
*/
174-
public function setApiKeyPrefix(string $apiKeyIdentifier, string $prefix): static
178+
public function setApiKeyPrefix(string $apiKeyIdentifier, ?string $prefix): static
175179
{
176-
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
180+
if ($prefix === null) {
181+
unset($this->apiKeyPrefixes[$apiKeyIdentifier]);
182+
} else {
183+
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
184+
}
177185
return $this;
178186
}
179187

0 commit comments

Comments
 (0)