Policy Validation

Policy validation is split into two calls, one to perform syntax validation and one to perform semantics validation.

Syntax validation ensures that the data that is provided is syntactically correct. If the data is not syntactically valid, API creation or update to API fails

Semantic validation ensures that the data is semantically valid and runtime layer can execute it. You can create or update an API with semantically invalid configuration, but semantic validation failure results in deployment or execution errors.

The following is an example of syntax and semantic validation. validateSyntax() is used to catch JSON syntax errors and values of wrong types. validateSemantics() validates if the values are the ones that are allowed.

package oracle.apiplatform.policies.%%policyname%%;

import java.util.List;

import org.json.JSONObject;

import oracle.apiplatform.common.l10n.NonLocalizedText;
import oracle.apiplatform.common.l10n.Text;
import oracle.apiplatform.policies.sdk.validation.AbstractPolicyValidator;
import oracle.apiplatform.policies.sdk.validation.Diagnostic;
import oracle.apiplatform.policies.sdk.validation.Diagnostic.Severity;

public class %%POLICYNAME%%Validator extends AbstractPolicyValidator implements %%POLICYNAME%%Constants {
	
	@Override
	public void validateSyntax(JSONObject config, Context context) {
	}

	@Override
	public void validateSemantics(JSONObject policyConfig, Context context,
			List<Diagnostic> diagnostics) {
		/**
		String script = policyConfig.getString(SCRIPT);
		
		if (script == null || script.length() == 0) {
			
			Text validationMsg = new NonLocalizedText("The script field cannot be empty.");
			Diagnostic diagnostic = new Diagnostic(Severity.Error, validationMsg.id());
			diagnostics.add(diagnostic);
			
		}
		*/
	}

}