5
5
import io .apicurio .registry .ccompat .rest .error .ConflictException ;
6
6
import io .apicurio .registry .ccompat .rest .error .UnprocessableEntityException ;
7
7
import io .apicurio .registry .content .ContentHandle ;
8
+ import io .apicurio .registry .content .TypedContent ;
8
9
import io .apicurio .registry .model .BranchId ;
9
10
import io .apicurio .registry .model .GA ;
10
11
import io .apicurio .registry .model .GAV ;
30
31
import io .apicurio .registry .types .VersionState ;
31
32
import io .apicurio .registry .types .provider .ArtifactTypeUtilProvider ;
32
33
import io .apicurio .registry .types .provider .ArtifactTypeUtilProviderFactory ;
33
- import io .apicurio .registry .util .ContentTypeUtil ;
34
34
import jakarta .inject .Inject ;
35
35
import org .apache .avro .AvroTypeException ;
36
36
import org .apache .avro .SchemaParseException ;
@@ -68,19 +68,18 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String subject, Stri
68
68
ArtifactVersionMetaDataDto res ;
69
69
final List <ArtifactReferenceDto > parsedReferences = parseReferences (references , groupId );
70
70
final List <ArtifactReference > artifactReferences = parsedReferences .stream ().map (dto -> ArtifactReference .builder ().name (dto .getName ()).groupId (dto .getGroupId ()).artifactId (dto .getArtifactId ()).version (dto .getVersion ()).build ()).collect (Collectors .toList ());
71
- final Map <String , ContentHandle > resolvedReferences = storage .resolveReferences (parsedReferences );
71
+ final Map <String , TypedContent > resolvedReferences = storage .resolveReferences (parsedReferences );
72
72
try {
73
73
ContentHandle schemaContent ;
74
74
schemaContent = ContentHandle .create (schema );
75
75
String contentType = ContentTypes .APPLICATION_JSON ;
76
76
if (artifactType .equals (ArtifactType .PROTOBUF )) {
77
77
contentType = ContentTypes .APPLICATION_PROTOBUF ;
78
- } else if (ContentTypeUtil .isParsableYaml (schemaContent )) {
79
- contentType = ContentTypes .APPLICATION_YAML ;
80
78
}
81
79
82
80
if (!doesArtifactExist (subject , groupId )) {
83
- rulesService .applyRules (groupId , subject , artifactType , schemaContent , RuleApplicationType .CREATE , artifactReferences , resolvedReferences );
81
+ TypedContent typedSchemaContent = TypedContent .create (schemaContent , contentType );
82
+ rulesService .applyRules (groupId , subject , artifactType , typedSchemaContent , RuleApplicationType .CREATE , artifactReferences , resolvedReferences );
84
83
85
84
EditableArtifactMetaDataDto artifactMetaData = EditableArtifactMetaDataDto .builder ().build ();
86
85
EditableVersionMetaDataDto firstVersionMetaData = EditableVersionMetaDataDto .builder ().build ();
@@ -93,7 +92,8 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String subject, Stri
93
92
res = storage .createArtifact (groupId , subject , artifactType , artifactMetaData , null ,
94
93
firstVersionContent , firstVersionMetaData , null ).getValue ();
95
94
} else {
96
- rulesService .applyRules (groupId , subject , artifactType , schemaContent , RuleApplicationType .UPDATE , artifactReferences , resolvedReferences );
95
+ TypedContent typedSchemaContent = TypedContent .create (schemaContent , contentType );
96
+ rulesService .applyRules (groupId , subject , artifactType , typedSchemaContent , RuleApplicationType .UPDATE , artifactReferences , resolvedReferences );
97
97
ContentWrapperDto versionContent = ContentWrapperDto .builder ()
98
98
.content (schemaContent )
99
99
.contentType (contentType )
@@ -116,13 +116,15 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
116
116
//FIXME simplify logic
117
117
try {
118
118
final String type = schemaType == null ? ArtifactType .AVRO : schemaType ;
119
+ final String contentType = type .equals (ArtifactType .PROTOBUF ) ? ContentTypes .APPLICATION_PROTOBUF : ContentTypes .APPLICATION_JSON ;
120
+ TypedContent typedSchemaContent = TypedContent .create (ContentHandle .create (schema ), contentType );
119
121
final List <ArtifactReferenceDto > artifactReferences = parseReferences (schemaReferences , groupId );
120
122
ArtifactTypeUtilProvider artifactTypeProvider = factory .getArtifactTypeProvider (type );
121
123
ArtifactVersionMetaDataDto amd ;
122
124
123
125
if (cconfig .canonicalHashModeEnabled .get () || normalize ) {
124
126
try {
125
- amd = storage .getArtifactVersionMetaDataByContent (groupId , subject , true , ContentHandle . create ( schema ) , artifactReferences );
127
+ amd = storage .getArtifactVersionMetaDataByContent (groupId , subject , true , typedSchemaContent , artifactReferences );
126
128
} catch (ArtifactNotFoundException ex ) {
127
129
if (type .equals (ArtifactType .AVRO )) {
128
130
//When comparing using content, sometimes the references might be inlined into the content, try to dereference the existing content and compare as a fallback. See https://github.com/Apicurio/apicurio-registry/issues/3588 for more information.
@@ -131,8 +133,13 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
131
133
amd = storage .getArtifactVersions (groupId , subject )
132
134
.stream ().filter (version -> {
133
135
StoredArtifactVersionDto artifactVersion = storage .getArtifactVersionContent (groupId , subject , version );
134
- Map <String , ContentHandle > artifactVersionReferences = storage .resolveReferences (artifactVersion .getReferences ());
135
- String dereferencedExistingContentSha = DigestUtils .sha256Hex (artifactTypeProvider .getContentDereferencer ().dereference (artifactVersion .getContent (), artifactVersionReferences ).content ());
136
+ TypedContent typedArtifactVersion = TypedContent .create (artifactVersion .getContent (), artifactVersion .getContentType ());
137
+ Map <String , TypedContent > artifactVersionReferences = storage .resolveReferences (artifactVersion .getReferences ());
138
+ String dereferencedExistingContentSha = DigestUtils .sha256Hex (
139
+ artifactTypeProvider .getContentDereferencer ().dereference (
140
+ typedArtifactVersion , artifactVersionReferences
141
+ ).getContent ().content ()
142
+ );
136
143
return dereferencedExistingContentSha .equals (DigestUtils .sha256Hex (schema ));
137
144
})
138
145
.findAny ()
@@ -144,7 +151,7 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
144
151
}
145
152
146
153
} else {
147
- amd = storage .getArtifactVersionMetaDataByContent (groupId , subject , false , ContentHandle . create ( schema ) , artifactReferences );
154
+ amd = storage .getArtifactVersionMetaDataByContent (groupId , subject , false , typedSchemaContent , artifactReferences );
148
155
}
149
156
150
157
return amd ;
@@ -153,8 +160,8 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
153
160
}
154
161
}
155
162
156
- protected Map <String , ContentHandle > resolveReferences (List <SchemaReference > references ) {
157
- Map <String , ContentHandle > resolvedReferences = Collections .emptyMap ();
163
+ protected Map <String , TypedContent > resolveReferences (List <SchemaReference > references ) {
164
+ Map <String , TypedContent > resolvedReferences = Collections .emptyMap ();
158
165
if (references != null && !references .isEmpty ()) {
159
166
//Transform the given references into dtos and set the contentId, this will also detect if any of the passed references does not exist.
160
167
final List <ArtifactReferenceDto > referencesAsDtos = references .stream ().map (schemaReference -> {
0 commit comments