Skip to content

Commit 16456fd

Browse files
authored
Set skipKnownTypes default to be consistent with other clients (#2376)
* Change skipKnownTypes to be consistent with other clients * Enhance test
1 parent 3067153 commit 16456fd

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/Confluent.SchemaRegistry.Serdes.Protobuf/ProtobufSerializer.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Confluent.SchemaRegistry.Serdes
5454
/// </remarks>
5555
public class ProtobufSerializer<T> : AsyncSerializer<T, FileDescriptorSet> where T : IMessage<T>, new()
5656
{
57-
private bool skipKnownTypes;
57+
private bool skipKnownTypes = true;
5858
private bool useDeprecatedFormat;
5959
private ReferenceSubjectNameStrategyDelegate referenceSubjectNameStrategy;
6060

@@ -190,7 +190,7 @@ private async Task<List<SchemaReference>> RegisterOrGetReferences(FileDescriptor
190190
for (int i=0; i<fd.Dependencies.Count; ++i)
191191
{
192192
FileDescriptor fileDescriptor = fd.Dependencies[i];
193-
if (skipKnownTypes && fileDescriptor.Name.StartsWith("google/protobuf/"))
193+
if (skipKnownTypes && IgnoreReference(fileDescriptor.Name))
194194
{
195195
continue;
196196
}
@@ -328,5 +328,12 @@ protected override async Task<FileDescriptorSet> ParseSchema(Schema schema)
328328
.ConfigureAwait(continueOnCapturedContext: false);
329329
return ProtobufUtils.Parse(schema.SchemaString, references);
330330
}
331+
332+
protected override bool IgnoreReference(string name)
333+
{
334+
return name.StartsWith("confluent/") ||
335+
name.StartsWith("google/protobuf/") ||
336+
name.StartsWith("google/type/");
337+
}
331338
}
332339
}

src/Confluent.SchemaRegistry.Serdes.Protobuf/ProtobufSerializerConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public IDictionary<string, string> UseLatestWithMetadata
195195
/// Specifies whether or not the Protobuf serializer should skip known types
196196
/// when resolving dependencies.
197197
///
198-
/// default: false
198+
/// default: true
199199
/// </summary>
200200
public bool? SkipKnownTypes
201201
{

src/Confluent.SchemaRegistry/AsyncSerde.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,19 @@ protected async Task<IDictionary<string, string>> ResolveReferences(Schema schem
142142
.ConfigureAwait(continueOnCapturedContext: false);
143143
return result;
144144
}
145+
146+
protected virtual bool IgnoreReference(string name)
147+
{
148+
return false;
149+
}
145150

146151
private async Task<IDictionary<string, string>> ResolveReferences(
147152
Schema schema, IDictionary<string, string> schemas, ISet<string> visited)
148153
{
149154
IList<SchemaReference> references = schema.References;
150155
foreach (SchemaReference reference in references)
151156
{
152-
if (visited.Contains(reference.Name))
157+
if (IgnoreReference(reference.Name) || visited.Contains(reference.Name))
153158
{
154159
continue;
155160
}

test/Confluent.SchemaRegistry.Serdes.IntegrationTests/Tests_Protobuf/ProduceConsumeGoogleRef.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ public static void ProduceConsumeGoogleRefProtobuf(string bootstrapServers, stri
3333
{
3434
var producerConfig = new ProducerConfig { BootstrapServers = bootstrapServers };
3535
var schemaRegistryConfig = new SchemaRegistryConfig { Url = schemaRegistryServers };
36+
var serializerConfig = new ProtobufSerializerConfig() { SkipKnownTypes = false };
3637

3738
using (var topic = new TemporaryTopic(bootstrapServers, 1))
3839
using (var schemaRegistry = new CachedSchemaRegistryClient(schemaRegistryConfig))
3940
using (var producer =
4041
new ProducerBuilder<string, WithGoogleRefs.TheRecord>(producerConfig)
41-
.SetValueSerializer(new ProtobufSerializer<WithGoogleRefs.TheRecord>(schemaRegistry))
42+
.SetValueSerializer(new ProtobufSerializer<WithGoogleRefs.TheRecord>(schemaRegistry, serializerConfig))
4243
.Build())
4344
{
4445
var u = new WithGoogleRefs.TheRecord();

0 commit comments

Comments
 (0)