3939import java .util .Map .Entry ;
4040import java .util .stream .Collectors ;
4141
42+ import static org .openapitools .codegen .utils .OnceLogger .once ;
43+
4244public class ModelUtils {
4345 private static final Logger LOGGER = LoggerFactory .getLogger (ModelUtils .class );
4446
@@ -248,7 +250,7 @@ private static void visitParameters(OpenAPI openAPI, List<Parameter> parameters,
248250 }
249251 visitContent (openAPI , parameter .getContent (), visitor , visitedSchemas );
250252 } else {
251- LOGGER .warn ("Unreferenced parameter found." );
253+ once ( LOGGER ) .warn ("Unreferenced parameter(s) found." );
252254 }
253255 }
254256 }
@@ -329,7 +331,7 @@ public static String getSimpleRef(String ref) {
329331 } else if (ref .startsWith ("#/definitions/" )) {
330332 ref = ref .substring (ref .lastIndexOf ("/" ) + 1 );
331333 } else {
332- LOGGER .warn ("Failed to get the schema name: {}" , ref );
334+ once ( LOGGER ) .warn ("Failed to get the schema name: {}" , ref );
333335 //throw new RuntimeException("Failed to get the schema: " + ref);
334336 return null ;
335337
@@ -561,7 +563,8 @@ public static boolean isEmailSchema(Schema schema) {
561563 */
562564 public static boolean isModel (Schema schema ) {
563565 if (schema == null ) {
564- LOGGER .error ("Schema cannot be null in isModel check" );
566+ // TODO: Is this message necessary? A null schema is not a model, so the result is correct.
567+ once (LOGGER ).error ("Schema cannot be null in isModel check" );
565568 return false ;
566569 }
567570
@@ -571,11 +574,7 @@ public static boolean isModel(Schema schema) {
571574 }
572575
573576 // composed schema is a model
574- if (schema instanceof ComposedSchema ) {
575- return true ;
576- }
577-
578- return false ;
577+ return schema instanceof ComposedSchema ;
579578 }
580579
581580 /**
@@ -586,7 +585,8 @@ public static boolean isModel(Schema schema) {
586585 */
587586 public static boolean isFreeFormObject (Schema schema ) {
588587 if (schema == null ) {
589- LOGGER .error ("Schema cannot be null in isFreeFormObject check" );
588+ // TODO: Is this message necessary? A null schema is not a free-form object, so the result is correct.
589+ once (LOGGER ).error ("Schema cannot be null in isFreeFormObject check" );
590590 return false ;
591591 }
592592
@@ -841,7 +841,7 @@ public static Schema unaliasSchema(OpenAPI openAPI, Schema schema) {
841841 if (schema != null && StringUtils .isNotEmpty (schema .get$ref ())) {
842842 Schema ref = allSchemas .get (ModelUtils .getSimpleRef (schema .get$ref ()));
843843 if (ref == null ) {
844- LOGGER .warn ("{} is not defined" , schema .get$ref ());
844+ once ( LOGGER ) .warn ("{} is not defined" , schema .get$ref ());
845845 return schema ;
846846 } else if (ref .getEnum () != null && !ref .getEnum ().isEmpty ()) {
847847 // top-level enum class
0 commit comments