Skip to content

Commit 6a9f56f

Browse files
authored
Allow passing explicit null values for optional input members (#1542)
This makes it easier to define the array literal for input objects as PHP does not have a syntax sugar for conditional keys in an array literal. This is consistent with the generated code for value objects. Even though input objects allow to omit required members in the constructor shape (as they can be set later by using the setter), the phpdoc type still does not allow passing null explicitly (even though the code would deal with it until the validation run) so that static analysis tools can catch mistakes there. Passing a required member explicitly is intended to pass a valid value for it and not a potentially missing one.
1 parent b7c276c commit 6a9f56f

File tree

250 files changed

+2953
-2953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+2953
-2953
lines changed

src/CodeGenerator/src/Generator/CodeGenerator/TypeGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public function generateDocblock(StructureShape $shape, ClassName $shapeClassNam
103103
}
104104
}
105105

106-
if ($allNullable || $nullable) {
107-
if ($isObject) {
108-
$body[] = sprintf(' %s?: %s,', $member->getName(), 'null|' . $param);
109-
} else {
110-
$body[] = sprintf(' %s?: %s,', $member->getName(), $param);
111-
}
106+
if ($nullable) {
107+
$body[] = sprintf(' %s?: %s,', $member->getName(), 'null|' . $param);
108+
} elseif ($allNullable) {
109+
// For input objects, the constructor allows to omit all members to set them later. But when provided,
110+
// they should respect the nullability of the member.
111+
$body[] = sprintf(' %s?: %s,', $member->getName(), $param);
112112
} else {
113113
$body[] = sprintf(' %s: %s,', $member->getName(), $param);
114114
}

src/Core/src/Sts/Input/AssumeRoleRequest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,16 @@ final class AssumeRoleRequest extends Input
240240
* @param array{
241241
* RoleArn?: string,
242242
* RoleSessionName?: string,
243-
* PolicyArns?: array<PolicyDescriptorType|array>,
244-
* Policy?: string,
245-
* DurationSeconds?: int,
246-
* Tags?: array<Tag|array>,
247-
* TransitiveTagKeys?: string[],
248-
* ExternalId?: string,
249-
* SerialNumber?: string,
250-
* TokenCode?: string,
251-
* SourceIdentity?: string,
252-
* ProvidedContexts?: array<ProvidedContext|array>,
243+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
244+
* Policy?: null|string,
245+
* DurationSeconds?: null|int,
246+
* Tags?: null|array<Tag|array>,
247+
* TransitiveTagKeys?: null|string[],
248+
* ExternalId?: null|string,
249+
* SerialNumber?: null|string,
250+
* TokenCode?: null|string,
251+
* SourceIdentity?: null|string,
252+
* ProvidedContexts?: null|array<ProvidedContext|array>,
253253
* '@region'?: string|null,
254254
* } $input
255255
*/
@@ -274,16 +274,16 @@ public function __construct(array $input = [])
274274
* @param array{
275275
* RoleArn?: string,
276276
* RoleSessionName?: string,
277-
* PolicyArns?: array<PolicyDescriptorType|array>,
278-
* Policy?: string,
279-
* DurationSeconds?: int,
280-
* Tags?: array<Tag|array>,
281-
* TransitiveTagKeys?: string[],
282-
* ExternalId?: string,
283-
* SerialNumber?: string,
284-
* TokenCode?: string,
285-
* SourceIdentity?: string,
286-
* ProvidedContexts?: array<ProvidedContext|array>,
277+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
278+
* Policy?: null|string,
279+
* DurationSeconds?: null|int,
280+
* Tags?: null|array<Tag|array>,
281+
* TransitiveTagKeys?: null|string[],
282+
* ExternalId?: null|string,
283+
* SerialNumber?: null|string,
284+
* TokenCode?: null|string,
285+
* SourceIdentity?: null|string,
286+
* ProvidedContexts?: null|array<ProvidedContext|array>,
287287
* '@region'?: string|null,
288288
* }|AssumeRoleRequest $input
289289
*/

src/Core/src/Sts/Input/AssumeRoleWithWebIdentityRequest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ final class AssumeRoleWithWebIdentityRequest extends Input
134134
* RoleArn?: string,
135135
* RoleSessionName?: string,
136136
* WebIdentityToken?: string,
137-
* ProviderId?: string,
138-
* PolicyArns?: array<PolicyDescriptorType|array>,
139-
* Policy?: string,
140-
* DurationSeconds?: int,
137+
* ProviderId?: null|string,
138+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
139+
* Policy?: null|string,
140+
* DurationSeconds?: null|int,
141141
* '@region'?: string|null,
142142
* } $input
143143
*/
@@ -158,10 +158,10 @@ public function __construct(array $input = [])
158158
* RoleArn?: string,
159159
* RoleSessionName?: string,
160160
* WebIdentityToken?: string,
161-
* ProviderId?: string,
162-
* PolicyArns?: array<PolicyDescriptorType|array>,
163-
* Policy?: string,
164-
* DurationSeconds?: int,
161+
* ProviderId?: null|string,
162+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
163+
* Policy?: null|string,
164+
* DurationSeconds?: null|int,
165165
* '@region'?: string|null,
166166
* }|AssumeRoleWithWebIdentityRequest $input
167167
*/

src/Core/src/Sts/StsClient.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ class StsClient extends AbstractApi
113113
* @param array{
114114
* RoleArn: string,
115115
* RoleSessionName: string,
116-
* PolicyArns?: array<PolicyDescriptorType|array>,
117-
* Policy?: string,
118-
* DurationSeconds?: int,
119-
* Tags?: array<Tag|array>,
120-
* TransitiveTagKeys?: string[],
121-
* ExternalId?: string,
122-
* SerialNumber?: string,
123-
* TokenCode?: string,
124-
* SourceIdentity?: string,
125-
* ProvidedContexts?: array<ProvidedContext|array>,
116+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
117+
* Policy?: null|string,
118+
* DurationSeconds?: null|int,
119+
* Tags?: null|array<Tag|array>,
120+
* TransitiveTagKeys?: null|string[],
121+
* ExternalId?: null|string,
122+
* SerialNumber?: null|string,
123+
* TokenCode?: null|string,
124+
* SourceIdentity?: null|string,
125+
* ProvidedContexts?: null|array<ProvidedContext|array>,
126126
* '@region'?: string|null,
127127
* }|AssumeRoleRequest $input
128128
*
@@ -274,10 +274,10 @@ public function assumeRole($input): AssumeRoleResponse
274274
* RoleArn: string,
275275
* RoleSessionName: string,
276276
* WebIdentityToken: string,
277-
* ProviderId?: string,
278-
* PolicyArns?: array<PolicyDescriptorType|array>,
279-
* Policy?: string,
280-
* DurationSeconds?: int,
277+
* ProviderId?: null|string,
278+
* PolicyArns?: null|array<PolicyDescriptorType|array>,
279+
* Policy?: null|string,
280+
* DurationSeconds?: null|int,
281281
* '@region'?: string|null,
282282
* }|AssumeRoleWithWebIdentityRequest $input
283283
*

src/Service/AppSync/src/AppSyncClient.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ class AppSyncClient extends AbstractApi
6161
* apiId: string,
6262
* typeName: string,
6363
* fieldName: string,
64-
* dataSourceName?: string,
65-
* requestMappingTemplate?: string,
66-
* responseMappingTemplate?: string,
67-
* kind?: ResolverKind::*,
68-
* pipelineConfig?: PipelineConfig|array,
69-
* syncConfig?: SyncConfig|array,
70-
* cachingConfig?: CachingConfig|array,
71-
* maxBatchSize?: int,
72-
* runtime?: AppSyncRuntime|array,
73-
* code?: string,
64+
* dataSourceName?: null|string,
65+
* requestMappingTemplate?: null|string,
66+
* responseMappingTemplate?: null|string,
67+
* kind?: null|ResolverKind::*,
68+
* pipelineConfig?: null|PipelineConfig|array,
69+
* syncConfig?: null|SyncConfig|array,
70+
* cachingConfig?: null|CachingConfig|array,
71+
* maxBatchSize?: null|int,
72+
* runtime?: null|AppSyncRuntime|array,
73+
* code?: null|string,
7474
* '@region'?: string|null,
7575
* }|CreateResolverRequest $input
7676
*
@@ -168,8 +168,8 @@ public function getSchemaCreationStatus($input): GetSchemaCreationStatusResponse
168168
*
169169
* @param array{
170170
* apiId: string,
171-
* nextToken?: string,
172-
* maxResults?: int,
171+
* nextToken?: null|string,
172+
* maxResults?: null|int,
173173
* '@region'?: string|null,
174174
* }|ListApiKeysRequest $input
175175
*
@@ -200,8 +200,8 @@ public function listApiKeys($input): ListApiKeysResponse
200200
* @param array{
201201
* apiId: string,
202202
* typeName: string,
203-
* nextToken?: string,
204-
* maxResults?: int,
203+
* nextToken?: null|string,
204+
* maxResults?: null|int,
205205
* '@region'?: string|null,
206206
* }|ListResolversRequest $input
207207
*
@@ -266,8 +266,8 @@ public function startSchemaCreation($input): StartSchemaCreationResponse
266266
* @param array{
267267
* apiId: string,
268268
* id: string,
269-
* description?: string,
270-
* expires?: int,
269+
* description?: null|string,
270+
* expires?: null|int,
271271
* '@region'?: string|null,
272272
* }|UpdateApiKeyRequest $input
273273
*
@@ -302,16 +302,16 @@ public function updateApiKey($input): UpdateApiKeyResponse
302302
* @param array{
303303
* apiId: string,
304304
* name: string,
305-
* description?: string,
305+
* description?: null|string,
306306
* type: DataSourceType::*,
307-
* serviceRoleArn?: string,
308-
* dynamodbConfig?: DynamodbDataSourceConfig|array,
309-
* lambdaConfig?: LambdaDataSourceConfig|array,
310-
* elasticsearchConfig?: ElasticsearchDataSourceConfig|array,
311-
* openSearchServiceConfig?: OpenSearchServiceDataSourceConfig|array,
312-
* httpConfig?: HttpDataSourceConfig|array,
313-
* relationalDatabaseConfig?: RelationalDatabaseDataSourceConfig|array,
314-
* eventBridgeConfig?: EventBridgeDataSourceConfig|array,
307+
* serviceRoleArn?: null|string,
308+
* dynamodbConfig?: null|DynamodbDataSourceConfig|array,
309+
* lambdaConfig?: null|LambdaDataSourceConfig|array,
310+
* elasticsearchConfig?: null|ElasticsearchDataSourceConfig|array,
311+
* openSearchServiceConfig?: null|OpenSearchServiceDataSourceConfig|array,
312+
* httpConfig?: null|HttpDataSourceConfig|array,
313+
* relationalDatabaseConfig?: null|RelationalDatabaseDataSourceConfig|array,
314+
* eventBridgeConfig?: null|EventBridgeDataSourceConfig|array,
315315
* '@region'?: string|null,
316316
* }|UpdateDataSourceRequest $input
317317
*
@@ -345,16 +345,16 @@ public function updateDataSource($input): UpdateDataSourceResponse
345345
* apiId: string,
346346
* typeName: string,
347347
* fieldName: string,
348-
* dataSourceName?: string,
349-
* requestMappingTemplate?: string,
350-
* responseMappingTemplate?: string,
351-
* kind?: ResolverKind::*,
352-
* pipelineConfig?: PipelineConfig|array,
353-
* syncConfig?: SyncConfig|array,
354-
* cachingConfig?: CachingConfig|array,
355-
* maxBatchSize?: int,
356-
* runtime?: AppSyncRuntime|array,
357-
* code?: string,
348+
* dataSourceName?: null|string,
349+
* requestMappingTemplate?: null|string,
350+
* responseMappingTemplate?: null|string,
351+
* kind?: null|ResolverKind::*,
352+
* pipelineConfig?: null|PipelineConfig|array,
353+
* syncConfig?: null|SyncConfig|array,
354+
* cachingConfig?: null|CachingConfig|array,
355+
* maxBatchSize?: null|int,
356+
* runtime?: null|AppSyncRuntime|array,
357+
* code?: null|string,
358358
* '@region'?: string|null,
359359
* }|UpdateResolverRequest $input
360360
*

src/Service/AppSync/src/Input/CreateResolverRequest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ final class CreateResolverRequest extends Input
126126
* apiId?: string,
127127
* typeName?: string,
128128
* fieldName?: string,
129-
* dataSourceName?: string,
130-
* requestMappingTemplate?: string,
131-
* responseMappingTemplate?: string,
132-
* kind?: ResolverKind::*,
133-
* pipelineConfig?: PipelineConfig|array,
134-
* syncConfig?: SyncConfig|array,
135-
* cachingConfig?: CachingConfig|array,
136-
* maxBatchSize?: int,
137-
* runtime?: AppSyncRuntime|array,
138-
* code?: string,
129+
* dataSourceName?: null|string,
130+
* requestMappingTemplate?: null|string,
131+
* responseMappingTemplate?: null|string,
132+
* kind?: null|ResolverKind::*,
133+
* pipelineConfig?: null|PipelineConfig|array,
134+
* syncConfig?: null|SyncConfig|array,
135+
* cachingConfig?: null|CachingConfig|array,
136+
* maxBatchSize?: null|int,
137+
* runtime?: null|AppSyncRuntime|array,
138+
* code?: null|string,
139139
* '@region'?: string|null,
140140
* } $input
141141
*/
@@ -162,16 +162,16 @@ public function __construct(array $input = [])
162162
* apiId?: string,
163163
* typeName?: string,
164164
* fieldName?: string,
165-
* dataSourceName?: string,
166-
* requestMappingTemplate?: string,
167-
* responseMappingTemplate?: string,
168-
* kind?: ResolverKind::*,
169-
* pipelineConfig?: PipelineConfig|array,
170-
* syncConfig?: SyncConfig|array,
171-
* cachingConfig?: CachingConfig|array,
172-
* maxBatchSize?: int,
173-
* runtime?: AppSyncRuntime|array,
174-
* code?: string,
165+
* dataSourceName?: null|string,
166+
* requestMappingTemplate?: null|string,
167+
* responseMappingTemplate?: null|string,
168+
* kind?: null|ResolverKind::*,
169+
* pipelineConfig?: null|PipelineConfig|array,
170+
* syncConfig?: null|SyncConfig|array,
171+
* cachingConfig?: null|CachingConfig|array,
172+
* maxBatchSize?: null|int,
173+
* runtime?: null|AppSyncRuntime|array,
174+
* code?: null|string,
175175
* '@region'?: string|null,
176176
* }|CreateResolverRequest $input
177177
*/

src/Service/AppSync/src/Input/ListApiKeysRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ final class ListApiKeysRequest extends Input
3636
/**
3737
* @param array{
3838
* apiId?: string,
39-
* nextToken?: string,
40-
* maxResults?: int,
39+
* nextToken?: null|string,
40+
* maxResults?: null|int,
4141
* '@region'?: string|null,
4242
* } $input
4343
*/
@@ -52,8 +52,8 @@ public function __construct(array $input = [])
5252
/**
5353
* @param array{
5454
* apiId?: string,
55-
* nextToken?: string,
56-
* maxResults?: int,
55+
* nextToken?: null|string,
56+
* maxResults?: null|int,
5757
* '@region'?: string|null,
5858
* }|ListApiKeysRequest $input
5959
*/

src/Service/AppSync/src/Input/ListResolversRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ final class ListResolversRequest extends Input
4646
* @param array{
4747
* apiId?: string,
4848
* typeName?: string,
49-
* nextToken?: string,
50-
* maxResults?: int,
49+
* nextToken?: null|string,
50+
* maxResults?: null|int,
5151
* '@region'?: string|null,
5252
* } $input
5353
*/
@@ -64,8 +64,8 @@ public function __construct(array $input = [])
6464
* @param array{
6565
* apiId?: string,
6666
* typeName?: string,
67-
* nextToken?: string,
68-
* maxResults?: int,
67+
* nextToken?: null|string,
68+
* maxResults?: null|int,
6969
* '@region'?: string|null,
7070
* }|ListResolversRequest $input
7171
*/

src/Service/AppSync/src/Input/UpdateApiKeyRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ final class UpdateApiKeyRequest extends Input
4646
* @param array{
4747
* apiId?: string,
4848
* id?: string,
49-
* description?: string,
50-
* expires?: int,
49+
* description?: null|string,
50+
* expires?: null|int,
5151
* '@region'?: string|null,
5252
* } $input
5353
*/
@@ -64,8 +64,8 @@ public function __construct(array $input = [])
6464
* @param array{
6565
* apiId?: string,
6666
* id?: string,
67-
* description?: string,
68-
* expires?: int,
67+
* description?: null|string,
68+
* expires?: null|int,
6969
* '@region'?: string|null,
7070
* }|UpdateApiKeyRequest $input
7171
*/

0 commit comments

Comments
 (0)