Skip to content

Commit

Permalink
[codegen] Use once(LOGGER) to reduce amount of identical warning mess…
Browse files Browse the repository at this point in the history
…ages (#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
  • Loading branch information
sebastien-rosset authored Apr 3, 2020
1 parent baeb1dd commit 9c8fb9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3537,7 +3538,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> 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();
Expand Down Expand Up @@ -3891,7 +3892,7 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9c8fb9d

Please sign in to comment.