Managing Apicurio Registry content using the Maven plug-in
This chapter explains how to manage schema and API artifacts stored in the registry using the Apicurio Registry Maven plug-in:
-
Apicurio Registry must be installed and running in your environment
-
Maven must be installed and configured in your environment
Adding schema and API artifacts using the Maven plug-in
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.
-
Apicurio Registry is installed and running in your environment
-
Update your Maven
pom.xmlfile to use theapicurio-registry-maven-pluginto register an artifact. The following example shows registering Apache Avro and GraphQL schemas:<plugin> <groupId>io.apicurio</groupId> <artifactId>apicurio-registry-maven-plugin</artifactId> <version>${apicurio.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>register</goal> (1) </goals> <configuration> <registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> (2) <authServerUrl>MY-AUTH-SERVER</authServerUrl> <clientId>MY-CLIENT-ID</clientId> <clientSecret>MY-CLIENT-SECRET</clientSecret> (3) <artifacts> <artifact> <groupId>TestGroup</groupId> (4) <artifactId>FullNameRecord</artifactId> <file>${project.basedir}/src/main/resources/schemas/record.avsc</file> <ifExists>FAIL</ifExists> </artifact> <artifact> <groupId>TestGroup</groupId> <artifactId>ExampleAPI</artifactId> (5) <type>GRAPHQL</type> <file>${project.basedir}/src/main/resources/apis/example.graphql</file> <ifExists>RETURN_OR_UPDATE</ifExists> <canonicalize>true</canonicalize> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>-
Specify
registeras the execution goal to upload the schema artifact to the registry. -
Specify the Apicurio Registry URL with the
../apis/registry/v2endpoint. -
If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Apicurio 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.
-
Downloading schema and API artifacts using the Maven plug-in
You can use the Maven plug-in to download artifacts from Apicurio Registry. This is often useful, for example, when generating code from a registered schema.
-
Apicurio Registry is installed and running in your environment
-
Update your Maven
pom.xmlfile to use theapicurio-registry-maven-pluginto download an artifact. The following example shows downloading Apache Avro and GraphQL schemas.<plugin> <groupId>io.apicurio</groupId> <artifactId>apicurio-registry-maven-plugin</artifactId> <version>${apicurio.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>download</goal> (1) </goals> <configuration> <registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> (2) <authServerUrl>MY-AUTH-SERVER</authServerUrl> <clientId>MY-CLIENT-ID</clientId> <clientSecret>MY-CLIENT-SECRET</clientSecret> (3) <artifacts> <artifact> <groupId>TestGroup</groupId> (4) <artifactId>FullNameRecord</artifactId> (5) <file>${project.build.directory}/classes/record.avsc</file> <overwrite>true</overwrite> </artifact> <artifact> <groupId>TestGroup</groupId> <artifactId>ExampleAPI</artifactId> <version>1</version> <file>${project.build.directory}/classes/example.graphql</file> <overwrite>true</overwrite> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>-
Specify
downloadas the execution goal. -
Specify the Apicurio Registry URL with the
../apis/registry/v2endpoint. -
If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Apicurio 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.
-
Adding artifact references using the Apicurio Registry Maven plug-in
Apicurio 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 Apicurio Registry Maven plug-in to register an artifact reference to a simple Avro schema artifact stored in Apicurio Registry. This example assumes that the following Exchange schema artifact has already been created in Apicurio Registry:
{
"namespace": "com.kubetrade.schema.common",
"type": "enum",
"name": "Exchange",
"symbols" : ["GEMINI"]
}
This example then creates a TradeKey schema artifact, which includes a reference to the nested Exchange schema artifact:
{
"namespace": "com.kubetrade.schema.trade",
"type": "record",
"name": "TradeKey",
"fields": [
{
"name": "exchange",
"type": "com.kubetrade.schema.common.Exchange"
},
{
"name": "key",
"type": "string"
}
]
}
-
Apicurio Registry is installed and running in your environment
-
The
Exchangeschema artifact is already created in Apicurio Registry
-
Update your Maven
pom.xmlfile to use theapicurio-registry-maven-pluginto register theTradeKeyschema, which includes a nested reference to theExchangeschema as follows:<plugin> <groupId>io.apicurio</groupId> <artifactId>apicurio-registry-maven-plugin</artifactId> <version>${apicurio-registry.version}</version> <executions> <execution> <id>register-artifact</id> <goals> <goal>register</goal> (1) </goals> <configuration> <registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> (2) <authServerUrl>MY-AUTH-SERVER</authServerUrl> <clientId>MY-CLIENT-ID</clientId> <clientSecret>MY-CLIENT-SECRET</clientSecret> (3) <artifacts> <artifact> <groupId>test-group</groupId> (4) <artifactId>TradeKey</artifactId> <version>2.0</version> <type>AVRO</type> <file> ${project.basedir}/src/main/resources/schemas/TradeKey.avsc </file> <ifExists>RETURN_OR_UPDATE</ifExists> <canonicalize>true</canonicalize> <references> <reference> (5) <name>com.kubetrade.schema.common.Exchange</name> <groupId>test-group</groupId> <artifactId>Exchange</artifactId> <version>2.0</version> <type>AVRO</type> <file> ${project.basedir}/src/main/resources/schemas/Exchange.avsc </file> <ifExists>RETURN_OR_UPDATE</ifExists> <canonicalize>true</canonicalize> </reference> </references> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>-
Specify
registeras the execution goal to upload the schema artifact to the registry. -
Specify the Apicurio Registry URL with the
../apis/registry/v2endpoint. -
If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Apicurio Registry artifact group ID. You can specify the
defaultgroup if you do not want to use a unique group ID. -
Specify the Apicurio Registry artifact reference using its group ID, artifact ID, version, type, and location. You can register multiple artifact references in this way.
-
Testing schema and API artifacts using the Maven plug-in
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 Apicurio 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 Apicurio Registry. |
-
Apicurio Registry must be installed and running in your environment
-
Update your Maven
pom.xmlfile to use theapicurio-registry-maven-pluginto test an artifact. The following example shows testing an Apache Avro schema:<plugin> <groupId>io.apicurio</groupId> <artifactId>apicurio-registry-maven-plugin</artifactId> <version>${apicurio.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>test-update</goal> (1) </goals> <configuration> <registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> (2) <authServerUrl>MY-AUTH-SERVER</authServerUrl> <clientId>MY-CLIENT-ID</clientId> <clientSecret>MY-CLIENT-SECRET</clientSecret> (3) <artifacts> <artifact> <groupId>TestGroup</groupId> (4) <artifactId>FullNameRecord</artifactId> <file>${project.basedir}/src/main/resources/schemas/record.avsc</file> (5) </artifact> <artifact> <groupId>TestGroup</groupId> <artifactId>ExampleAPI</artifactId> <type>GRAPHQL</type> <file>${project.basedir}/src/main/resources/apis/example.graphql</file> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>-
Specify
test-updateas the execution goal to test the schema artifact. -
Specify the Apicurio Registry URL with the
../apis/registry/v2endpoint. -
If authentication is required, you can specify your authentication server and client credentials.
-
Specify the Apicurio 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.
-
