include::{mod-loc}shared/all-attributes.adoc[]

[id="intro-to-registry-rules_{context}"]
= {registry} content rules
//If the assembly covers a task, start the title with a verb in the gerund form, such as Creating or Configuring.

[role="_abstract"]
This chapter introduces the optional rules used to govern {registry} content and provides details on the available rule configuration:

* xref:registry-rules_{context}[]
* xref:registry-rules-apply_{context}[]
* xref:registry-rules-precedence_{context}[]
* xref:registry-rules-work_{context}[]
* xref:registry-rules-config_{context}[]

//INCLUDES


// Metadata created by nebel

[id="registry-rules_{context}"]

== Govern {registry} content using rules

[role="_abstract"]
To govern the evolution of artifact content added to {registry}, you can configure optional rules. All configured global rules, group-specific rules, or artifact-specific rules must pass before a new artifact version can be added to {registry}. Configured artifact-specific rules override any configured group-specific rules, which in turn override any configured global rules.

The goal of these rules is to prevent invalid content from being added to {registry} and to control the evolution of an artifact (by e.g. checking the compatibility of a new artifact version against previous versions). For example, content can be invalid for the following reasons:

* Invalid syntax for a given artifact type, for example, `AVRO` or `PROTOBUF`.
* Valid syntax, but semantics violate a specification.
* Incompatibility, when new content includes breaking changes relative to the current artifact version.
* Artifact reference integrity, for example, a duplicate or non-existent artifact reference mapping.

You can enable optional content rules using the {registry} web console, REST API commands, or by using one of the SDKs.

[id="registry-rules-apply_{context}"]
=== When rules are applied
Rules are applied only when content is added to {registry}. This includes the following REST operations:

* Adding an artifact
* Adding an artifact version

If a rule is violated, {registry} returns an HTTP error. The response body includes the violated rule and a message showing what went wrong.

[id="registry-rules-precedence_{context}"]
=== Order of precedence of rules
The order of precedence for artifact-specific and global rules is as follows:

* Artifact-specific rules have the highest priority
* Group-specific rules have the next highest priority
* Global rules have the lowest priority

NOTE: If a rule is configured at a higher level (e.g. at the global level), but you want that rule to be disabled at a lower level, you must configure the same rule (so that it overrides it) at the lower level and set its rules value to `NONE`.

[id="registry-rules-work_{context}"]
=== How rules work
Each rule has a name and configuration information. {registry} maintains the list of rules for each artifact, each group, and the list of global rules. Each rule in the list consists of a name and configuration for the rule implementation.

When a rule is executed, it is provided with the content of the current version of the artifact (if one exists) and the new version of the artifact being added. The rule implementation returns either passes or fails depending on whether the artifact passes the rule. If not, {registry} reports the reason why in an HTTP error response. Some rules might not use the previous version of the content. For example, compatibility rules use previous versions, but syntax or semantic validity rules do not.

[role="_additional-resources"]
.Additional resources
For more details, see {registry-rule-reference}.

[id="registry-rules-config_{context}"]
=== Content rule configuration
Administrators can configure {registry} global rules, group-specific rules, and artifact-specific rules. Developers can configure group-specific and artifact-specific rules only.

{registry} applies the rules configured for the specific artifact. If no rules are configured at that level, {registry} applies the group-specific rules.  If no rules are configured at the group level, then {registry} applies the globally configured rules. If no global rules are configured, then no rules are applied.

[discrete]
==== Configure group and artifact specific rules
You can configure group-specific and artifact-specific rules using the {registry} web console or REST API. For details, see the following:

* {managing-registry-artifacts-ui}
* link:{attachmentsdir}/registry-rest-api.htm[Apicurio Registry REST API documentation]

[discrete]
==== Configure global rules
Administrators can configure global rules in several ways:

* Use the `admin/rules` operations in the REST API
* Use the {registry} web console
* Set default global rules using {registry} application properties

.Configure default global rules
Administrators can configure {registry} at the application level to enable or disable global rules. You can configure default global rules at installation time without post-install configuration using the following application property format:
----
apicurio.rules.global.<ruleName>
----

The following rule names are currently supported:

* `compatibility`
* `validity`
* `integrity`

The value of the application property must be a valid configuration option that is specific to the rule being
configured.

NOTE: You can configure these application properties as Java system properties or include them in the Quarkus
`application.properties` file. For more details, see the https://quarkus.io/guides/config#overriding-properties-at-runtime[Quarkus documentation].



