diff --git a/src/Codegen/Constraints/UntypedBuilder.php b/src/Codegen/Constraints/UntypedBuilder.php index 7b9454c..2c3aead 100644 --- a/src/Codegen/Constraints/UntypedBuilder.php +++ b/src/Codegen/Constraints/UntypedBuilder.php @@ -569,15 +569,22 @@ private function generateGenericAnyOfChecks(vec $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( @@ -596,7 +603,7 @@ private function generateOptimizedAnyOfChecks(TOptimizedAnyOfTypes $any_of_types ->ensureEmptyLine() ->addAssignment( '$types', - $types, + $constraints, HackBuilderValues::dict(HackBuilderKeys::export(), HackBuilderValues::literal()), ) ->ensureEmptyLine(); diff --git a/tests/examples/codegen/CustomCodegenConfigValidator.php b/tests/examples/codegen/CustomCodegenConfigValidator.php index 1c4a83f..37ed465 100644 --- a/tests/examples/codegen/CustomCodegenConfigValidator.php +++ b/tests/examples/codegen/CustomCodegenConfigValidator.php @@ -5,7 +5,7 @@ * To re-generate this file run `make test` * * - * @generated SignedSource<> + * @generated SignedSource<<42a2e629fbe63e9b95076f6cf672801e>> */ namespace Slack\Hack\JsonSchema\Tests\Generated; use namespace Slack\Hack\JsonSchema; @@ -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, diff --git a/tests/examples/codegen/PersonSchemaValidator.php b/tests/examples/codegen/PersonSchemaValidator.php index 688296e..28abaf5 100644 --- a/tests/examples/codegen/PersonSchemaValidator.php +++ b/tests/examples/codegen/PersonSchemaValidator.php @@ -5,7 +5,7 @@ * To re-generate this file run `make test` * * - * @generated SignedSource<> + * @generated SignedSource<> */ namespace Slack\Hack\JsonSchema\Tests\Generated; use namespace Slack\Hack\JsonSchema; @@ -34,7 +34,10 @@ ... ); -type TPersonSchemaValidatorPropertiesDevicesItems = mixed; +type TPersonSchemaValidatorPropertiesDevicesItems = shape( + 'type' => string, + ... +); type TPersonSchemaValidator = shape( 'first_name' => string, diff --git a/tests/examples/codegen/UntypedSchemaValidator.php b/tests/examples/codegen/UntypedSchemaValidator.php index e9dfafd..1d77f66 100644 --- a/tests/examples/codegen/UntypedSchemaValidator.php +++ b/tests/examples/codegen/UntypedSchemaValidator.php @@ -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; @@ -62,7 +62,11 @@ ?'integer' => int, ); -type TUntypedSchemaValidatorPropertiesAnyOfOptimizedEnum = mixed; +type TUntypedSchemaValidatorPropertiesAnyOfOptimizedEnum = shape( + 'type' => string, + ?'string' => string, + ?'integer' => int, +); type TUntypedSchemaValidatorPropertiesOneOfNullableString = ?string;