|
3 | 3 | import io.apicurio.registry.auth.Authorized;
|
4 | 4 | import io.apicurio.registry.auth.AuthorizedLevel;
|
5 | 5 | import io.apicurio.registry.auth.AuthorizedStyle;
|
6 |
| - |
7 | 6 | import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
|
8 | 7 | import io.apicurio.registry.ccompat.rest.v7.CompatibilityResource;
|
9 | 8 | import io.apicurio.registry.ccompat.rest.v7.beans.CompatibilityCheckResponse;
|
|
13 | 12 | import io.apicurio.registry.logging.Logged;
|
14 | 13 | import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
|
15 | 14 | import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
|
| 15 | +import io.apicurio.registry.model.BranchId; |
16 | 16 | import io.apicurio.registry.model.GA;
|
17 | 17 | import io.apicurio.registry.rules.RuleViolationException;
|
18 | 18 | import io.apicurio.registry.rules.UnprocessableSchemaException;
|
19 | 19 | import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
|
| 20 | +import io.apicurio.registry.storage.error.VersionNotFoundException; |
20 | 21 | import io.apicurio.registry.types.ArtifactType;
|
21 | 22 | import io.apicurio.registry.types.ContentTypes;
|
22 | 23 | import jakarta.interceptor.Interceptors;
|
@@ -79,41 +80,50 @@ public CompatibilityCheckResponse checkCompatibility(String subject, String vers
|
79 | 80 | final boolean fverbose = verbose == null ? Boolean.FALSE : verbose;
|
80 | 81 | final GA ga = getGA(groupId, subject);
|
81 | 82 |
|
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()); |
109 | 99 | CompatibilityCheckResponse response = new CompatibilityCheckResponse();
|
110 |
| - response.setIsCompatible(false); |
| 100 | + response.setIsCompatible(true); |
111 | 101 | 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()); |
112 | 115 | }
|
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 | + } |
118 | 128 | }
|
119 | 129 | }
|
0 commit comments