2626 */
2727@ SuppressWarnings ("all" )
2828public class MapperUtil {
29-
3029 /**
3130 * Safely extracts a {@code Set<String>} value from a map for the given key, or returns an empty set.
3231 *
@@ -213,7 +212,7 @@ public static StringBuilder getEnumClassBuilder(String schemaName) {
213212 * }
214213 * </pre>
215214 *
216- * @param schemaName class name
215+ * @param schemaName class name
217216 * @param implementsFrom set of interface simple names
218217 * @return builder with class+implements header
219218 */
@@ -238,7 +237,7 @@ public static StringBuilder getImplementationClassBuilder(String schemaName, Set
238237 * }
239238 * </pre>
240239 *
241- * @param schemaName class name
240+ * @param schemaName class name
242241 * @param extendsClass superclass name
243242 * @return builder with class+extends header
244243 */
@@ -262,8 +261,8 @@ public static StringBuilder getExtendsClassBuilder(String schemaName, String ext
262261 * }
263262 * </pre>
264263 *
265- * @param schemaName class name
266- * @param extendsClass superclass name
264+ * @param schemaName class name
265+ * @param extendsClass superclass name
267266 * @param implementsFrom set of interface names
268267 * @return builder with full inheritance header
269268 */
@@ -435,28 +434,35 @@ private static String fetchAccessors(LombokProperties lombokProperties) {
435434 }
436435
437436 /**
438- * Finalizes Java source by prepending package and imports , and appending closing brace.
437+ * Finalizes Java source by prepending package, imports, and @Generated annotation , and appending closing brace.
439438 *
440439 * @param sb builder with class body
441440 * @param requiredImports set of import strings
442- * @param packageName package name (with semicolon)
441+ * @param packageName package name
442+ * @param javaDoc javaDoc text
443443 * @return complete Java source
444444 */
445- public static String finishBuild (StringBuilder sb , Set <String > requiredImports , String packageName ) {
445+ public static String finishBuild (StringBuilder sb , Set <String > requiredImports , String packageName , String javaDoc ) {
446446 StringBuilder importBuilder = new StringBuilder ();
447+
448+ requiredImports .add (JAVAX_GENERATED_IMPORT );
449+
447450 requiredImports .forEach (imp -> {
448451 importBuilder
449452 .append (IMPORT )
450453 .append (imp )
451454 .append (lineSeparator ());
452455 });
453- sb .insert (0 , importBuilder .append (lineSeparator ()));
454456
457+ sb .insert (0 , GENERATED_ANNOTATION + lineSeparator ());
458+
459+ generateClassJavaDoc (sb , javaDoc );
460+
461+ sb .insert (0 , importBuilder .append (lineSeparator ()));
455462 sb .insert (0 , new StringBuilder ("package " )
456463 .append (packageName )
457464 .append (lineSeparator ())
458465 .append (lineSeparator ()));
459-
460466 return sb
461467 .append (lineSeparator ())
462468 .append ("}" )
@@ -490,7 +496,6 @@ public static StringBuilder prepareStringBuilder(Set<String> requiredImports,
490496 } else {
491497 sb = getClassBuilder (schemaName );
492498 }
493-
494499 requiredImports .addAll (importSet );
495500 sb .append (fillParameters .toWrite ()).append (lineSeparator ());
496501 return sb ;
@@ -511,7 +516,6 @@ public static String capitalize(final String str) {
511516 if (strLen == 0 ) {
512517 return str ;
513518 }
514-
515519 final int firstCodepoint = str .codePointAt (0 );
516520 final int newCodePoint = Character .toTitleCase (firstCodepoint );
517521 return checkPoints (firstCodepoint , newCodePoint , str , new int [strLen ], strLen );
@@ -528,7 +532,6 @@ public static String uncapitalize(final String str) {
528532 if (strLen == 0 ) {
529533 return str ;
530534 }
531-
532535 final int firstCodepoint = str .codePointAt (0 );
533536 final int newCodePoint = Character .toLowerCase (firstCodepoint );
534537 return checkPoints (firstCodepoint , newCodePoint , str , new int [strLen ], strLen );
@@ -538,7 +541,6 @@ private static String checkPoints(int firstCodepoint, int newCodePoint, String s
538541 if (firstCodepoint == newCodePoint ) {
539542 return str ;
540543 }
541-
542544 final int [] newCodePoints = strLen ;
543545 int outOffset = 0 ;
544546 newCodePoints [outOffset ++] = newCodePoint ;
@@ -745,28 +747,21 @@ public static void registerNestedSchemas(
745747 Map <String , Object > properties ,
746748 Map <String , Object > schemas ,
747749 Map <String , Object > innerSchemas ) {
748-
749750 if (properties == null ) return ;
750-
751751 for (Map .Entry <String , Object > entry : properties .entrySet ()) {
752752 String fieldName = entry .getKey ();
753753 Object value = entry .getValue ();
754-
755754 if (value instanceof Map ) {
756755 @ SuppressWarnings ("unchecked" )
757756 Map <String , Object > fieldDef = (Map <String , Object >) value ;
758-
759757 // Проверяем, является ли поле объектом с собственными свойствами
760758 if ("object" .equals (getStringValueIfExistOrElseNull ("type" , fieldDef )) &&
761759 fieldDef .containsKey ("properties" )) {
762-
763760 // Генерируем уникальное имя класса: Parent + CapitalizedFieldName
764761 String nestedClassName = parentClassName + capitalize (fieldName );
765-
766762 // Если такая схема ещё не зарегистрирована — регистрируем
767763 if (!innerSchemas .containsKey (nestedClassName )) {
768764 Map <String , Object > nestedProps = castObjectToMap (fieldDef .get ("properties" ));
769-
770765 // Создаём "виртуальную" схему
771766 Map <String , Object > virtualSchema = new LinkedHashMap <>();
772767 virtualSchema .put ("type" , "object" );
@@ -777,9 +772,7 @@ public static void registerNestedSchemas(
777772 if (fieldDef .containsKey ("description" )) {
778773 virtualSchema .put ("description" , fieldDef .get ("description" ));
779774 }
780-
781775 innerSchemas .put (nestedClassName , virtualSchema );
782-
783776 // 🔁 Рекурсивно обрабатываем вложенные объекты внутри этого объекта
784777 registerNestedSchemas (nestedClassName , nestedProps , schemas , innerSchemas );
785778 }
0 commit comments