From 54fedec630192864722d8a4ff809321f2b74d4e0 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 31 Mar 2020 13:01:29 -0700 Subject: [PATCH 1/2] Warn once instead of many times when the log statement does not have contextual information --- .../main/java/org/openapitools/codegen/DefaultCodegen.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index bade86348d6d..731115881f00 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -66,6 +66,7 @@ import org.openapitools.codegen.utils.OneOfImplementorAdditionalData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.openapitools.codegen.utils.OnceLogger.once; import java.io.File; import java.util.*; @@ -1654,7 +1655,7 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, RequestB if (content.size() > 1) { // @see ModelUtils.getSchemaFromContent() - LOGGER.warn("Multiple MediaTypes found, using only the first one"); + once(LOGGER).warn("Multiple MediaTypes found, using only the first one"); } MediaType mediaType = content.values().iterator().next(); @@ -3530,7 +3531,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) } else if (parameter.getContent() != null) { Content content = parameter.getContent(); if (content.size() > 1) { - LOGGER.warn("Multiple schemas found in content, returning only the first one"); + once(LOGGER).warn("Multiple schemas found in content, returning only the first one"); } MediaType mediaType = content.values().iterator().next(); s = mediaType.getSchema(); @@ -3884,7 +3885,7 @@ public List fromSecurity(Map securitySc // As of January 2020, the "signature" scheme has not been registered with IANA yet. // This scheme may have to be changed when it is officially registered with IANA. cs.isHttpSignature = true; - LOGGER.warn("Security scheme 'HTTP signature' is a draft IETF RFC and subject to change."); + once(LOGGER).warn("Security scheme 'HTTP signature' is a draft IETF RFC and subject to change."); } } else if (SecurityScheme.Type.OAUTH2.equals(securityScheme.getType())) { cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isBasic = false; From a643816825436d9204a4eb952e838268bb5b0844 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 31 Mar 2020 13:01:45 -0700 Subject: [PATCH 2/2] Warn once instead of many times when the log statement does not have contextual information --- .../main/java/org/openapitools/codegen/utils/ModelUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 44373cd8c3bd..e55479e4a31f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -985,7 +985,7 @@ private static Schema getSchemaFromContent(Content content) { if (content.size() > 1) { // Other content types are currently ignored by codegen. If you see this warning, // reorder the OAS spec to put the desired content type first. - LOGGER.warn("Multiple schemas found in the OAS 'content' section, returning only the first one ({})", + once(LOGGER).warn("Multiple schemas found in the OAS 'content' section, returning only the first one ({})", entry.getKey()); } return entry.getValue().getSchema();