@@ -790,16 +790,37 @@ public String toEnumValue(String value, String datatype) {
790790 * <p>
791791 * Execution: {@code datatype} is produced upstream (e.g. {@link DefaultCodegen#updateCodegenPropertyEnum}) via
792792 * {@link #getTypeDeclaration(Schema)} for the referenced enum schema; {@code value} is the sanitized case name
793- * from {@link #toEnumVarName}. We concatenate with {@code ::} so templates emit valid PHP (e.g.
794- * {@code \Vendor\Model\Status::AVAILABLE}).
793+ * from {@link #toEnumVarName}. When the enum class sits under {@link #modelPackage}, we emit only the short class
794+ * name plus {@code ::} so it matches sibling model references in generated files ({@code namespace} is
795+ * {@code modelPackage}; unqualified names resolve correctly). A fully qualified body without a leading
796+ * {@code \} would be resolved relative to the file namespace and is invalid PHP for defaults.
795797 *
796798 * @param value enum case name (e.g. {@code AVAILABLE})
797- * @param datatype enum class as in generated PHP (often leading {@code \} + FQCN )
798- * @return PHP default expression for that case
799+ * @param datatype enum class as produced by {@link #getTypeDeclaration(Schema)} (may include {@code modelPackage} )
800+ * @return PHP default expression for that case (e.g. {@code PetStatus::AVAILABLE})
799801 */
800802 @ Override
801803 public String toEnumDefaultValue (String value , String datatype ) {
802- return datatype + "::" + value ;
804+ return unqualifiedEnumClassForModelDefault (datatype ) + "::" + value ;
805+ }
806+
807+ /**
808+ * Strips {@link #modelPackage} from a declared enum class name so defaults use the same unqualified form as
809+ * property type hints in model templates.
810+ *
811+ * @param datatype enum class string from codegen (optional leading {@code \})
812+ * @return short class name if under {@code modelPackage}, otherwise the original {@code datatype}
813+ */
814+ private String unqualifiedEnumClassForModelDefault (String datatype ) {
815+ if (StringUtils .isBlank (datatype ) || StringUtils .isBlank (modelPackage )) {
816+ return datatype ;
817+ }
818+ String normalized = datatype .charAt (0 ) == '\\' ? datatype .substring (1 ) : datatype ;
819+ String prefix = modelPackage + "\\ " ;
820+ if (normalized .startsWith (prefix )) {
821+ return normalized .substring (prefix .length ());
822+ }
823+ return datatype ;
803824 }
804825
805826 @ Override
0 commit comments