Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Codegen/Constraints/UntypedBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,22 @@ private function generateGenericAnyOfChecks(vec<SchemaBuilder> $schema_builders,
}

private function generateOptimizedAnyOfChecks(TOptimizedAnyOfTypes $any_of_types, HackBuilder $hb): void {
$types = dict[];
$types = vec[];
$constraints = dict[];
foreach ($any_of_types['types'] as $type_name => $schema_builder) {
$suffix = $this->generateClassName($this->suffix, 'anyOfTypes', $type_name);
$schema_builder->setSuffix($suffix);
$schema_builder->build();

$types[$type_name] = "{$schema_builder->getClassName()}::check<>";
$constraints[$type_name] = "{$schema_builder->getClassName()}::check<>";
$types[] = $schema_builder->getTypeInfo();
}

$this->type_info = Typing\TypeSystem::union(
$types,
shape('disable_shape_unification' => $this->typed_schema['disableShapeUnification'] ?? false)
);

$hb
->addAssignment('$key', $any_of_types['key'], HackBuilderValues::export())
->addAssignment(
Expand All @@ -596,7 +603,7 @@ private function generateOptimizedAnyOfChecks(TOptimizedAnyOfTypes $any_of_types
->ensureEmptyLine()
->addAssignment(
'$types',
$types,
$constraints,
HackBuilderValues::dict(HackBuilderKeys::export(), HackBuilderValues::literal()),
)
->ensureEmptyLine();
Expand Down
7 changes: 5 additions & 2 deletions tests/examples/codegen/CustomCodegenConfigValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* To re-generate this file run `make test`
*
*
* @generated SignedSource<<a2f9712dad75f484bf20025df1b6e2f8>>
* @generated SignedSource<<42a2e629fbe63e9b95076f6cf672801e>>
*/
namespace Slack\Hack\JsonSchema\Tests\Generated;
use namespace Slack\Hack\JsonSchema;
Expand Down Expand Up @@ -34,7 +34,10 @@
...
);

type custom_codegen_config_validator_properties_devices_items_t = mixed;
type custom_codegen_config_validator_properties_devices_items_t = shape(
'type' => string,
...
);

type custom_codegen_config_validator_t = shape(
'first_name' => string,
Expand Down
7 changes: 5 additions & 2 deletions tests/examples/codegen/PersonSchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* To re-generate this file run `make test`
*
*
* @generated SignedSource<<d9e951b7c4e5dd6d27e2dc5c8d3900bc>>
* @generated SignedSource<<ee778314572dafea42ca53253a97056b>>
*/
namespace Slack\Hack\JsonSchema\Tests\Generated;
use namespace Slack\Hack\JsonSchema;
Expand Down Expand Up @@ -34,7 +34,10 @@
...
);

type TPersonSchemaValidatorPropertiesDevicesItems = mixed;
type TPersonSchemaValidatorPropertiesDevicesItems = shape(
'type' => string,
...
);

type TPersonSchemaValidator = shape(
'first_name' => string,
Expand Down
8 changes: 6 additions & 2 deletions tests/examples/codegen/UntypedSchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* To re-generate this file run `make test`
*
*
* @generated SignedSource<<2c98b928d525db21c6948ef14b310a05>>
* @generated SignedSource<<5d0e74247bc284d369cde4fc754bc67e>>
*/
namespace Slack\Hack\JsonSchema\Tests\Generated;
use namespace Slack\Hack\JsonSchema;
Expand Down Expand Up @@ -62,7 +62,11 @@
?'integer' => int,
);

type TUntypedSchemaValidatorPropertiesAnyOfOptimizedEnum = mixed;
type TUntypedSchemaValidatorPropertiesAnyOfOptimizedEnum = shape(
'type' => string,
?'string' => string,
?'integer' => int,
);

type TUntypedSchemaValidatorPropertiesOneOfNullableString = ?string;

Expand Down