Skip to content

Commit cdcdc1e

Browse files
committed
Fix for #6089
1 parent d541928 commit cdcdc1e

File tree

2 files changed

+85
-34
lines changed

2 files changed

+85
-34
lines changed

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/CompatibilityResourceImpl.java

+44-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.apicurio.registry.auth.Authorized;
44
import io.apicurio.registry.auth.AuthorizedLevel;
55
import io.apicurio.registry.auth.AuthorizedStyle;
6-
76
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
87
import io.apicurio.registry.ccompat.rest.v7.CompatibilityResource;
98
import io.apicurio.registry.ccompat.rest.v7.beans.CompatibilityCheckResponse;
@@ -13,10 +12,12 @@
1312
import io.apicurio.registry.logging.Logged;
1413
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
1514
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
15+
import io.apicurio.registry.model.BranchId;
1616
import io.apicurio.registry.model.GA;
1717
import io.apicurio.registry.rules.RuleViolationException;
1818
import io.apicurio.registry.rules.UnprocessableSchemaException;
1919
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
20+
import io.apicurio.registry.storage.error.VersionNotFoundException;
2021
import io.apicurio.registry.types.ArtifactType;
2122
import io.apicurio.registry.types.ContentTypes;
2223
import jakarta.interceptor.Interceptors;
@@ -79,41 +80,50 @@ public CompatibilityCheckResponse checkCompatibility(String subject, String vers
7980
final boolean fverbose = verbose == null ? Boolean.FALSE : verbose;
8081
final GA ga = getGA(groupId, subject);
8182

82-
return parseVersionString(ga.getRawArtifactId(), versionString, ga.getRawGroupIdWithNull(),
83-
version -> {
84-
try {
85-
final ArtifactVersionMetaDataDto artifact = storage.getArtifactVersionMetaData(
86-
ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), version);
87-
// Assume the content type of the SchemaContent is correct based on the artifact type.
88-
String contentType = ContentTypes.APPLICATION_JSON;
89-
if (artifact.getArtifactType().equals(ArtifactType.PROTOBUF)) {
90-
contentType = ContentTypes.APPLICATION_PROTOBUF;
91-
}
92-
TypedContent typedContent = TypedContent
93-
.create(ContentHandle.create(request.getSchema()), contentType);
94-
rulesService.applyRules(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), version,
95-
artifact.getArtifactType(), typedContent, Collections.emptyList(),
96-
Collections.emptyMap());
97-
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
98-
response.setIsCompatible(true);
99-
return response;
100-
}
101-
catch (RuleViolationException ex) {
102-
if (fverbose) {
103-
//FIXME:carnalca handle verbose parameter
104-
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
105-
response.setIsCompatible(false);
106-
return response;
107-
}
108-
else {
83+
try {
84+
return parseVersionString(ga.getRawArtifactId(), versionString, ga.getRawGroupIdWithNull(),
85+
version -> {
86+
try {
87+
final ArtifactVersionMetaDataDto artifact = storage.getArtifactVersionMetaData(
88+
ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), version);
89+
// Assume the content type of the SchemaContent is correct based on the artifact type.
90+
String contentType = ContentTypes.APPLICATION_JSON;
91+
if (artifact.getArtifactType().equals(ArtifactType.PROTOBUF)) {
92+
contentType = ContentTypes.APPLICATION_PROTOBUF;
93+
}
94+
TypedContent typedContent = TypedContent
95+
.create(ContentHandle.create(request.getSchema()), contentType);
96+
rulesService.applyRules(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), version,
97+
artifact.getArtifactType(), typedContent, Collections.emptyList(),
98+
Collections.emptyMap());
10999
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
110-
response.setIsCompatible(false);
100+
response.setIsCompatible(true);
111101
return response;
102+
} catch (RuleViolationException ex) {
103+
if (fverbose) {
104+
//FIXME:carnalca handle verbose parameter
105+
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
106+
response.setIsCompatible(false);
107+
return response;
108+
} else {
109+
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
110+
response.setIsCompatible(false);
111+
return response;
112+
}
113+
} catch (UnprocessableSchemaException ex) {
114+
throw new UnprocessableEntityException(ex.getMessage());
112115
}
113-
}
114-
catch (UnprocessableSchemaException ex) {
115-
throw new UnprocessableEntityException(ex.getMessage());
116-
}
117-
});
116+
});
117+
} catch (VersionNotFoundException vnfe) {
118+
// Fix for Issue 6089: https://github.com/Apicurio/apicurio-registry/issues/6089
119+
// Click and read and be amazed.
120+
if (BranchId.LATEST.getRawBranchId().equals(versionString)) {
121+
CompatibilityCheckResponse response = new CompatibilityCheckResponse();
122+
response.setIsCompatible(true);
123+
return response;
124+
} else {
125+
throw vnfe;
126+
}
127+
}
118128
}
119129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.apicurio.registry.noprofile.ccompat.rest.v7;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.node.ObjectNode;
5+
import io.apicurio.registry.AbstractResourceTestBase;
6+
import io.quarkus.test.junit.QuarkusTest;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static io.restassured.RestAssured.given;
10+
import static org.hamcrest.CoreMatchers.anything;
11+
12+
@QuarkusTest
13+
public class CompatibilityResourceTest extends AbstractResourceTestBase {
14+
@Test
15+
public void testUnknownLatestSchemaForSubject() {
16+
ObjectMapper mapper = new ObjectMapper();
17+
ObjectNode requestBody = mapper.createObjectNode();
18+
requestBody.put("schema", "{}");
19+
requestBody.put("schemaType", "AVRO");
20+
21+
String subject = "unknown";
22+
String version = "1";
23+
given().when()
24+
.contentType(CT_JSON)
25+
.body(requestBody)
26+
.post("/ccompat/v7/compatibility/subjects/{subject}/versions/{version}", subject, version)
27+
.then()
28+
.statusCode(404)
29+
.body(anything());
30+
31+
subject = "unknown";
32+
version = "latest";
33+
given().when()
34+
.contentType(CT_JSON)
35+
.body(requestBody)
36+
.post("/ccompat/v7/compatibility/subjects/{subject}/versions/{version}", subject, version)
37+
.then()
38+
.statusCode(200)
39+
.body(anything());
40+
}
41+
}

0 commit comments

Comments
 (0)