Skip to content

Commit c4c5e20

Browse files
authored
Add validate action for SR maven plugin (confluentinc#1474)
1 parent cfe149f commit c4c5e20

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

maven-plugin/src/main/java/io/confluent/kafka/schemaregistry/maven/UploadSchemaRegistryMojo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ private List<SchemaReference> getReferences(String subject, Map<String, Integer>
129129

130130
Integer version = ref.version != null ? ref.version : schemaVersions.get(ref.subject);
131131
if (version == null) {
132-
throw new IllegalArgumentException(
133-
"Could not retrieve version for subject " + ref.subject);
132+
getLog().warn(
133+
String.format("Version not specified for ref with name '%s' and subject '%s', "
134+
+ "using latest version", ref.name, ref.subject));
135+
version = -1;
134136
}
135137
result.add(new SchemaReference(ref.name, ref.subject, version));
136138
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2020 Confluent Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.confluent.kafka.schemaregistry.maven;
18+
19+
import io.confluent.kafka.schemaregistry.ParsedSchema;
20+
import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException;
21+
import java.io.IOException;
22+
import java.util.Map;
23+
import org.apache.maven.plugins.annotations.Mojo;
24+
25+
@Mojo(name = "validate", configurator = "custom-basic")
26+
public class ValidateSchemaRegistryMojo extends UploadSchemaRegistryMojo {
27+
28+
@Override
29+
protected boolean processSchema(String subject,
30+
ParsedSchema schema,
31+
Map<String, Integer> schemaVersions)
32+
throws IOException, RestClientException {
33+
34+
if (getLog().isDebugEnabled()) {
35+
getLog().debug(
36+
String.format("Calling validate('%s', '%s')", subject, schema)
37+
);
38+
}
39+
40+
schema.validate();
41+
return true;
42+
}
43+
}

0 commit comments

Comments
 (0)