diff --git a/src/WordPress/Blueprints/bin/autogenerate_models.php b/src/WordPress/Blueprints/bin/autogenerate_models.php index ba1f5605..c03ca0da 100644 --- a/src/WordPress/Blueprints/bin/autogenerate_models.php +++ b/src/WordPress/Blueprints/bin/autogenerate_models.php @@ -196,11 +196,6 @@ function fixTypeHint( string $typeHint, array $replacements ): string { $schema = $janeProperty->getObject(); if ( $schema instanceof JsonSchema ) { - // Don't set "null" as the default value since it's already a default - // value of all class properties. - if ( $schema->getDefault() !== null ) { - $property->setValue( $schema->getDefault() ); - } if ( $schema->getConst() ) { $property->setValue( $schema->getConst() ); // Assume that a class with an interface uses a const property @@ -214,6 +209,10 @@ function fixTypeHint( string $typeHint, array $replacements ): string { // So, we have to manually set it back to null. $class->getConstants()['DISCRIMINATOR']->setVisibility( null ); } + } elseif ( $schema->getDefault() !== null ) { + // Don't set "null" as the default value since it's already a default + // value of all class properties. + $property->setValue( $schema->getDefault() ); } elseif ( $schema->getType() === 'array' ) { $property->setValue( [] ); }