Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json schema dereferencing in the server #4590

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-context-propagation</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.apicurio.registry.ccompat.rest.v7.impl;


import io.apicurio.registry.ccompat.dto.SchemaReference;
import io.apicurio.registry.ccompat.rest.error.ConflictException;
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
Expand All @@ -25,28 +24,27 @@
import io.apicurio.registry.rules.RuleApplicationType;
import io.apicurio.registry.rules.RuleViolationException;
import io.apicurio.registry.rules.RulesService;
import io.apicurio.registry.storage.ArtifactNotFoundException;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.RuleNotFoundException;
import io.apicurio.registry.storage.VersionNotFoundException;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.StoredArtifactDto;
import io.apicurio.registry.storage.ArtifactNotFoundException;
import io.apicurio.registry.storage.RuleNotFoundException;
import io.apicurio.registry.storage.VersionNotFoundException;
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
import jakarta.inject.Inject;
import org.apache.avro.AvroTypeException;
import org.apache.avro.SchemaParseException;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import jakarta.inject.Inject;

import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import io.apicurio.registry.storage.dto.VersionSearchResultsDto;
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.ReferenceType;
import io.apicurio.registry.types.RuleType;
Expand Down Expand Up @@ -185,8 +186,17 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der

ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty() && artifactTypeProvider.getContentDereferencer() != null) {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
if (dereference && !artifact.getReferences().isEmpty()) {
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
Expand Down Expand Up @@ -574,7 +584,16 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty()) {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactMediaTypes;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.ReferenceType;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
Expand All @@ -53,7 +54,7 @@
* @author [email protected]
*/
@ApplicationScoped
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
@Interceptors({ ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class })
@Logged
public class IdsResourceImpl implements IdsResource {

Expand Down Expand Up @@ -106,7 +107,16 @@ public Response getContentByGlobalId(long globalId, Boolean dereference) {
ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty()) {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
Expand Down Expand Up @@ -154,7 +164,8 @@ public List<ArtifactReference> referencesByGlobalId(long globalId, ReferenceType
return artifact.getReferences().stream()
.map(V2ApiUtil::referenceDtoToReference)
.collect(Collectors.toList());
} else {
}
else {
ArtifactMetaDataDto amd = storage.getArtifactMetaData(globalId);
return storage.getInboundArtifactReferences(amd.getGroupId(), amd.getId(), amd.getVersion()).stream()
.map(V2ApiUtil::referenceDtoToReference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public class ContentAndReferencesDto {
private ContentHandle content;

private List<ArtifactReferenceDto> references;

private String artifactType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,9 @@ public GroupSearchResultsDto searchGroups(Set<SearchFilter> filters, OrderBy ord
public ContentAndReferencesDto getContentByReference(ArtifactReferenceDto reference) {
try {
var meta = getArtifactVersionMetaDataInternal(reference.getGroupId(), reference.getArtifactId(), reference.getVersion());
return getArtifactByContentId(meta.getContentId());
ContentAndReferencesDto artifactByContentId = getArtifactByContentId(meta.getContentId());
artifactByContentId.setArtifactType(meta.getType());
return artifactByContentId;
} catch (VersionNotFoundException e) {
return null;
}
Expand Down
Loading
Loading