private void addWarning(String message, Object... params) { diagCollector.addDiag( Diag.warning(location, "In path template '" + template + "': " + message, params)); }
private void addWarning(String message, Object... params) { diagCollector.addDiag( Diag.warning(location, "In path template '" + template + "': " + message, params)); }
private static void warnOnLegacyExtensions( String[] legacyNamesForExtension, Map<String, Object> vendorExtensions, String extensionName, DiagCollector diagCollector) { for (String legacyNameForExtension : legacyNamesForExtension) { Object extensionValue = vendorExtensions.get(legacyNameForExtension); if (extensionValue != null) { diagCollector.addDiag( Diag.warning( new SimpleLocation(legacyNameForExtension), "Extension name %s has been deprecated, please rename it to %s.", legacyNameForExtension, extensionName)); } } } }
public void warning(Node node, String message, Object... params) { diag.addDiag(Diag.warning(getLocation(node), message, params)); }
private static void warnOnLegacyExtensions( String[] legacyNamesForExtension, Map<String, Object> vendorExtensions, String extensionName, DiagCollector diagCollector) { for (String legacyNameForExtension : legacyNamesForExtension) { Object extensionValue = vendorExtensions.get(legacyNameForExtension); if (extensionValue != null) { diagCollector.addDiag( Diag.warning( new SimpleLocation(legacyNameForExtension), "Extension name %s has been deprecated, please rename it to %s.", legacyNameForExtension, extensionName)); } } } }
public void warning(Node node, String message, Object... params) { diag.addDiag(Diag.warning(getLocation(node), message, params)); }
private static <T extends ResourceNameConfig> ImmutableMap<String, T> mergeResourceNameConfigs( DiagCollector diagCollector, Map<String, T> configsFromGapicConfig, Map<String, T> configsFromProtoFile) { Map<String, T> mergedResourceNameConfigs = new HashMap<>(configsFromProtoFile); // If protofile annotations clash with the configs from configProto, use the configProto. for (T resourceFromGapicConfig : configsFromGapicConfig.values()) { if (configsFromProtoFile.containsKey(resourceFromGapicConfig.getEntityId())) { diagCollector.addDiag( Diag.warning( SimpleLocation.TOPLEVEL, "Resource[Set] entity %s from protofile clashes with a" + " Resource[Set] of the same name from the GAPIC config." + " Using the GAPIC config entity.", resourceFromGapicConfig.getEntityId())); } // Add the protofile resourceNameConfigs to the map of resourceNameConfigs. mergedResourceNameConfigs.put(resourceFromGapicConfig.getEntityId(), resourceFromGapicConfig); } return ImmutableMap.copyOf(mergedResourceNameConfigs); }
@Override public boolean apply(Parameter parameter) { if (parameter instanceof RefParameter) { /* * This is an invalid state. Reference parameters should automatically get * resolved into parameter objects by the swagger core parser, because only * references that are allowed are to parameters that are defined at the * Swagger Object's parameters which are in the same file. If we reach here * it would mean the reference cannot be resolved and nothing this converter * can do. */ diagCollector.addDiag( Diag.warning( location, "Reference %s cannot be resolved", ((RefParameter) parameter).get$ref())); return false; } else { return true; } } })
@Override public boolean apply(Parameter parameter) { if (parameter instanceof RefParameter) { /* * This is an invalid state. Reference parameters should automatically get * resolved into parameter objects by the swagger core parser, because only * references that are allowed are to parameters that are defined at the * Swagger Object's parameters which are in the same file. If we reach here * it would mean the reference cannot be resolved and nothing this converter * can do. */ diagCollector.addDiag( Diag.warning( location, "Reference %s cannot be resolved", ((RefParameter) parameter).get$ref())); return false; } else { return true; } } })
private void warning(String message, Object... args) { model .getDiagReporter() .getDiagCollector() .addDiag(Diag.warning(SimpleLocation.TOPLEVEL, message, args)); } }
/** * Checks if the defined apiKey is valid or not. Only apiKey definition with name as 'key' and * 'in' as 'query' are allowed" */ private boolean isValidApiKeyDefinition(ApiKeyAuthDefinition apiKeydef) { if (apiKeydef.getName().equalsIgnoreCase("key") || apiKeydef.getIn() == In.QUERY) { return true; } else { diagCollector.addDiag( Diag.warning( SimpleLocation.UNKNOWN, "apiKey '%s' is ignored. Only apiKey with 'name' as 'key' and 'in' as 'query' are " + "supported", apiKeydef.getName())); return false; } }
/** * Checks if the defined apiKey is valid or not. Only apiKey definition with name as 'key' and * 'in' as 'query' are allowed" */ private boolean isValidApiKeyDefinition(ApiKeyAuthDefinition apiKeydef) { if (apiKeydef.getName().equalsIgnoreCase("key") || apiKeydef.getIn() == In.QUERY) { return true; } else { diagCollector.addDiag( Diag.warning( SimpleLocation.UNKNOWN, "apiKey '%s' is ignored. Only apiKey with 'name' as 'key' and 'in' as 'query' are " + "supported", apiKeydef.getName())); return false; } }
private void errorSince(int version, Element elem, String message, Object... params) { if (!errorContext.isEmpty()) { message = message + " " + errorContext + "."; } Diag diag = elem.getModel().getConfigVersion() >= version ? Diag.error(elem.getLocation(), message, params) : Diag.warning( elem.getLocation(), message + String.format( " Note: this will be an error for config version %s and later.", version), params); elem.getModel().getDiagReporter().report(diag); }
private void errorSince(int version, Element elem, String message, Object... params) { if (!errorContext.isEmpty()) { message = message + " " + errorContext + "."; } Diag diag = elem.getModel().getConfigVersion() >= version ? Diag.error(elem.getLocation(), message, params) : Diag.warning( elem.getLocation(), message + String.format( " Note: this will be an error for config version %s and later.", version), params); elem.getModel().getDiagReporter().report(diag); }
Diag.warning( elem.getLocation(), "The rule '%s' in aspect '%s' used in warning suppression '%s' is unknown.",
Diag.warning( elem.getLocation(), "The rule '%s' in aspect '%s' used in warning suppression '%s' is unknown.",
private UsageRule createUsageRulePerMethod( Iterable<Map<String, List<String>>> openApiSecurityObject, String operationType, String swaggerPath, String selector) { boolean perMethodApiKeyRequired = isApiKeyRequired(openApiSecurityObject, requiresApiKeyAtTopLevel, apiKeyDefinitions); if (!perMethodApiKeyRequired) { // TODO(): Remove this check once we have warnings suppression implemented. if (!swaggerPath.equals(OpenApiUtils.WILDCARD_URL_PATH)) { diagCollector.addDiag( Diag.warning( OpenApiLocations.createOperationLocation(operationType, swaggerPath), "Operation does not require an API key; callers may invoke the method " + "without specifying an associated API-consuming project. " + "To enable API key all the SecurityRequirement Objects " + "(https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object) " + "inside security definition must reference at least one SecurityDefinition " + "of type : 'apiKey'.")); } } return UsageRule.newBuilder() .setSelector(selector) .setAllowUnregisteredCalls(!perMethodApiKeyRequired) .build(); }
private UsageRule createUsageRulePerMethod( Iterable<Map<String, List<String>>> openApiSecurityObject, String operationType, String swaggerPath, String selector) { boolean perMethodApiKeyRequired = isApiKeyRequired(openApiSecurityObject, requiresApiKeyAtTopLevel, apiKeyDefinitions); if (!perMethodApiKeyRequired) { // TODO(): Remove this check once we have warnings suppression implemented. if (!swaggerPath.equals(OpenApiUtils.WILDCARD_URL_PATH)) { diagCollector.addDiag( Diag.warning( OpenApiLocations.createOperationLocation(operationType, swaggerPath), "Operation does not require an API key; callers may invoke the method " + "without specifying an associated API-consuming project. " + "To enable API key all the SecurityRequirement Objects " + "(https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object) " + "inside security definition must reference at least one SecurityDefinition " + "of type : 'apiKey'.")); } } return UsageRule.newBuilder() .setSelector(selector) .setAllowUnregisteredCalls(!perMethodApiKeyRequired) .build(); }
@Test public void testTooManyWarnings() { // It should stop accumulating warnings after `count` of them. for (int i = 0; i < WARNING_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.warning( new SimpleLocation(String.format("testTooManyWarnings:%d", i)), "%s", "This is a warning message")); } // We should have `count` warnings plus the "too many" warning in the diagnostics. Assert.assertEquals(WARNING_MAX_COUNT + 1, diagCollector.getDiags().size()); Assert.assertEquals(0, diagCollector.getErrorCount()); }
@Test public void testTooManyMixedDiags() { try { for (int i = 0; i < WARNING_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.warning( new SimpleLocation(String.format("testTooManyMixedDiags:%d", i)), "%s", "This is a warning message")); } for (int i = 0; i < ERROR_MAX_COUNT + 5; i++) { diagCollector.addDiag( Diag.error( new SimpleLocation(String.format("testTooManyMixedDiags:%d", i)), "%s", "This is an error message")); } Assert.fail("Expected TooManyDiagsException was not thrown"); } catch (TooManyDiagsException ex) { // fall through to assertions } // We should have `warnCount` warnings plus the "too many" warning in the diagnostics, plus // `errorCount` errors and the "too many" error. Assert.assertEquals( WARNING_MAX_COUNT + 1 + ERROR_MAX_COUNT + 1, diagCollector.getDiags().size()); Assert.assertEquals(ERROR_MAX_COUNT + 1, diagCollector.getErrorCount()); } }