Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@

@SuppressWarnings("rawtypes")
public class DefaultGenerator implements Generator {
private static final String FILE_PATH_COLLISION_LOG = "FILEPATH_COLLISION";
private static final String FILE_PATH_COLLISION_LOG_MESSAGE =
FILE_PATH_COLLISION_LOG + ": File path collision detected. Files may be overwritten by later-processed collisions. " +
"Use 'modelNameMappings' or another name mapping to resolve file name collisions.";
private static final String METADATA_DIR = ".openapi-generator";
protected final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
private final boolean dryRun;
Expand Down Expand Up @@ -1461,7 +1465,9 @@ private File processTemplateToFile(Map<String, Object> templateData, String temp

// O(1) case-insensitive duplicate check via a pre-lowercased shadow set
if (!seenFilesLower.add(absoluteTarget.toString().toLowerCase(Locale.ROOT))) {
LOGGER.warn("Duplicate file path detected. Not all operating systems can handle case sensitive file paths. path={}", absoluteTarget);
once(LOGGER).warn(FILE_PATH_COLLISION_LOG_MESSAGE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Using once() to emit the single primary warning does not reliably produce one warning per run. OnceLogger's cache is JVM-global and expires after 2 seconds (default), so in a generation that runs longer than 2s the primary message is re-emitted whenever a new collision appears, and in a JVM that runs several generators it is suppressed entirely after the first one while every later collision still logs 'see log FILEPATH_COLLISION' pointing at a primary that may not be present. Consider replacing once() with an instance-level flag so the primary is emitted exactly once per DefaultGenerator run.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java, line 1468:

<comment>Using `once()` to emit the single primary warning does not reliably produce one warning per run. OnceLogger's cache is JVM-global and expires after 2 seconds (default), so in a generation that runs longer than 2s the primary message is re-emitted whenever a new collision appears, and in a JVM that runs several generators it is suppressed entirely after the first one while every later collision still logs 'see log FILEPATH_COLLISION' pointing at a primary that may not be present. Consider replacing `once()` with an instance-level flag so the primary is emitted exactly once per DefaultGenerator run.</comment>

<file context>
@@ -1461,7 +1465,9 @@ private File processTemplateToFile(Map<String, Object> templateData, String temp
                 // O(1) case-insensitive duplicate check via a pre-lowercased shadow set
                 if (!seenFilesLower.add(absoluteTarget.toString().toLowerCase(Locale.ROOT))) {
-                    LOGGER.warn("Duplicate file path detected. Not all operating systems can handle case sensitive file paths. path={}", absoluteTarget);
+                    once(LOGGER).warn(FILE_PATH_COLLISION_LOG_MESSAGE);
+                    LOGGER.warn("Duplicate file path detected. Not all operating systems can handle case sensitive file paths, see log '{}' for more information. path={}",
+                            FILE_PATH_COLLISION_LOG, absoluteTarget);
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The once() call is currently the preferred way of forwarding information to the client in a less noisy way. Having it bound to an instance-level flag comes with its own flaws, and leaves us to reason about whether the Generator should become stateful and to what degree processTemplateToFile is to be invoked.

Having it tied to once() is better currently in my opinion, and an accidental omission of FILEPATH_COLLISION in uniquely executed workflows is still a better pointer than nothing.

LOGGER.warn("Duplicate file path detected. Not all operating systems can handle case sensitive file paths, see log '{}' for more information. path={}",
FILE_PATH_COLLISION_LOG, absoluteTarget);
}
return this.templateProcessor.write(templateData, templateName, target);
} else {
Expand Down
Loading