[codegen] Use once(LOGGER) to reduce amount of identical warning messages (#5808)

* Warn once instead of many times when the log statement does not have contextual information

* Warn once instead of many times when the log statement does not have contextual information
This commit is contained in:
Sebastien Rosset
2020-04-03 08:10:12 -07:00
committed by GitHub
parent baeb1dd385
commit 9c8fb9db46
2 changed files with 5 additions and 4 deletions

View File

@@ -66,6 +66,7 @@ import org.openapitools.codegen.utils.ModelUtils;
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 class DefaultCodegen implements CodegenConfig {
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();
@@ -3537,7 +3538,7 @@ public class DefaultCodegen implements CodegenConfig {
} 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();
@@ -3891,7 +3892,7 @@ public class DefaultCodegen implements CodegenConfig {
// 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;

View File

@@ -985,7 +985,7 @@ public class ModelUtils {
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();