Este conteúdo não está disponível no idioma selecionado.
Chapter 5. Managing Service Registry content using the Maven plug-in
This chapter explains how to manage schema and API artifacts stored in the registry using the Service Registry Maven plug-in:
- Section 5.1, “Adding schema and API artifacts using the Maven plug-in”
- Section 5.2, “Downloading schema and API artifacts using the Maven plug-in”
- Section 5.3, “Adding artifact references using the Service Registry Maven plug-in”
- Section 5.4, “Testing schema and API artifacts using the Maven plug-in”
Prerequisites
- See Chapter 1, Introduction to Service Registry
- Service Registry must be installed and running in your environment
- Maven must be installed and configured in your environment
5.1. Adding schema and API artifacts using the Maven plug-in Copiar o linkLink copiado para a área de transferência!
The most common use case for the Maven plug-in is adding artifacts during a build. You can accomplish this by using the register execution goal.
Prerequisites
- Service Registry is installed and running in your environment
Procedure
Update your Maven pom.xml file to use the apicurio-registry-maven-plugin to register an artifact. The following example shows registering Apache Avro and GraphQL schemas:
-
Specify
registeras the execution goal to upload the schema artifact to the registry. -
Specify the Service Registry URL with the
../apis/registry/v2endpoint. - If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Service Registry artifact group ID. You can specify the
defaultgroup if you do not want to use a unique group ID. - You can register multiple artifacts using the specified group ID, artifact ID, and location.
5.2. Downloading schema and API artifacts using the Maven plug-in Copiar o linkLink copiado para a área de transferência!
You can use the Maven plug-in to download artifacts from Service Registry. This is often useful, for example, when generating code from a registered schema.
Prerequisites
- Service Registry is installed and running in your environment
Procedure
Update your Maven pom.xml file to use the apicurio-registry-maven-plugin to download an artifact. The following example shows downloading Apache Avro and GraphQL schemas.
-
Specify
downloadas the execution goal. -
Specify the Service Registry URL with the
../apis/registry/v2endpoint. - If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Service Registry artifact group ID. You can specify the
defaultgroup if you do not want to use a unique group. - You can download multiple artifacts to a specified directory using the artifact ID.
5.3. Adding artifact references using the Service Registry Maven plug-in Copiar o linkLink copiado para a área de transferência!
Service Registry artifact types such as Apache Avro, Protobuf, and JSON Schema can include artifact references from one artifact file to another. You can create efficiencies by defining reusable schema and API artifacts, and then referencing them from multiple locations in artifact references.
This section shows a simple example of using the Service Registry Maven plug-in to register an artifact reference to a simple Avro schema artifact stored in Service Registry. This example assumes that the following Exchange schema artifact has already been created in Service Registry:
Exchange schema
This example then creates a TradeKey schema artifact, which includes a reference to the nested Exchange schema artifact:
TradeKey schema with nested Exchange schema
Prerequisites
- Service Registry is installed and running in your environment
-
The
Exchangeschema artifact is already created in Service Registry
Procedure
Update your Maven pom.xml file to use the apicurio-registry-maven-plugin to register the TradeKey schema, which includes a nested reference to the Exchange schema as follows:
-
Specify
registeras the execution goal to upload the schema artifact to the registry. -
Specify the Service Registry URL with the
../apis/registry/v2endpoint. - If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Service Registry artifact group ID. You can specify the
defaultgroup if you do not want to use a unique group ID. - Specify the Service Registry artifact reference using its group ID, artifact ID, version, type, and location. You can register multiple artifact references in this way.
5.4. Testing schema and API artifacts using the Maven plug-in Copiar o linkLink copiado para a área de transferência!
You might want to verify that an artifact can be registered without actually making any changes. This is often useful when rules are configured in Service Registry. Testing the artifact results in a failure if the artifact content violates any of the configured rules.
When testing artifacts using the Maven plug-in, even if the artifact passes the test, no content is added to Service Registry.
Prerequisites
- Service Registry must be installed and running in your environment
Procedure
Update your Maven pom.xml file to use the apicurio-registry-maven-plugin to test an artifact. The following example shows testing an Apache Avro schema:
-
Specify
test-updateas the execution goal to test the schema artifact. -
Specify the Service Registry URL with the
../apis/registry/v2endpoint. - If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Service Registry artifact group ID. You can specify the
defaultgroup if you do not want to use a unique group. - You can test multiple artifacts from a specified directory using the artifact ID.