Skip to content

Commit 184970a

Browse files
mikalaisytymhowlett
authored andcommitted
Adds GET subject versions in the registry client (#771)
* Fixes return type of get subject versions in schema registry client * Adds get subject versions method to schema registry client
1 parent 9ca4d12 commit 184970a

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

src/Confluent.SchemaRegistry/CachedSchemaRegistryClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ public Task<List<string>> GetAllSubjectsAsync()
310310
=> restService.GetSubjectsAsync();
311311

312312

313+
/// <summary>
314+
/// Refer to <see cref="Confluent.SchemaRegistry.ISchemaRegistryClient.GetSubjectVersionsAsync(string)" />
315+
/// </summary>
316+
public async Task<List<int>> GetSubjectVersionsAsync(string subject)
317+
=> await restService.GetSubjectVersionsAsync(subject).ConfigureAwait(continueOnCapturedContext: false);
318+
319+
313320
/// <summary>
314321
/// Refer to <see cref="Confluent.SchemaRegistry.ISchemaRegistryClient.IsCompatibleAsync(string, string)" />
315322
/// </summary>

src/Confluent.SchemaRegistry/ISchemaRegistryClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ public interface ISchemaRegistryClient : IDisposable
115115
Task<List<string>> GetAllSubjectsAsync();
116116

117117

118+
/// <summary>
119+
/// Gets a list of versions registered under the specified <paramref name="subject" />.
120+
/// </summary>
121+
/// <param name="subject">
122+
/// The subject to get versions registered under.
123+
/// </param>
124+
/// <returns>
125+
/// A list of versions registered under the specified <paramref name="subject" />.
126+
/// </returns>
127+
Task<List<int>> GetSubjectVersionsAsync(string subject);
128+
129+
118130
/// <summary>
119131
/// Check if a schema is compatible with latest version registered against a
120132
/// specified subject.

src/Confluent.SchemaRegistry/Rest/IRestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal interface IRestService : IDisposable
3636
Task<string> GetSchemaAsync(int id);
3737
Task<Schema> GetSchemaAsync(string subject, int version);
3838
Task<List<string>> GetSubjectsAsync();
39-
Task<List<string>> GetSubjectVersionsAsync(string subject);
39+
Task<List<int>> GetSubjectVersionsAsync(string subject);
4040
Task<int> RegisterSchemaAsync(string subject, string schema);
4141
Task<Config> SetCompatibilityAsync(string subject, Compatibility compatibility);
4242
Task<Config> SetGlobalCompatibilityAsync(Compatibility compatibility);

src/Confluent.SchemaRegistry/Rest/RestService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public async Task<List<string>> GetSubjectsAsync()
230230
=> await RequestListOfAsync<string>("/subjects", HttpMethod.Get)
231231
.ConfigureAwait(continueOnCapturedContext: false);
232232

233-
public async Task<List<string>> GetSubjectVersionsAsync(string subject)
234-
=> await RequestListOfAsync<string>($"/subjects/{subject}/versions", HttpMethod.Get)
233+
public async Task<List<int>> GetSubjectVersionsAsync(string subject)
234+
=> await RequestListOfAsync<int>($"/subjects/{subject}/versions", HttpMethod.Get)
235235
.ConfigureAwait(continueOnCapturedContext: false);
236236

237237
public async Task<Schema> GetSchemaAsync(string subject, int version)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 20 Confluent Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// Refer to LICENSE for more information.
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using Xunit;
20+
21+
22+
namespace Confluent.SchemaRegistry.IntegrationTests
23+
{
24+
public static partial class Tests
25+
{
26+
[Theory, MemberData(nameof(SchemaRegistryParameters))]
27+
public static void GetSubjectVersions(Config config)
28+
{
29+
var topicName = Guid.NewGuid().ToString();
30+
31+
var testSchema1 =
32+
"{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"Confluent.Kafka.Examples.AvroSpecific" +
33+
"\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\":[\"i" +
34+
"nt\",\"null\"]},{\"name\":\"favorite_color\",\"type\":[\"string\",\"null\"]}]}";
35+
36+
var testSchema2 = // compatible with testSchema1
37+
"{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"Confluent.Kafka.Examples.AvroSpecific" +
38+
"\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\":[\"i" +
39+
"nt\",\"null\"]},{\"name\":\"favorite_color\",\"type\":[\"string\",\"null\"]}," +
40+
"{\"name\":\"favorite_shape\",\"type\":[\"string\",\"null\"], \"default\": \"square\"}]}";
41+
42+
var sr = new CachedSchemaRegistryClient(new SchemaRegistryConfig { SchemaRegistryUrl = config.Server });
43+
44+
var subject = sr.ConstructValueSubjectName(topicName);
45+
var id1 = sr.RegisterSchemaAsync(subject, testSchema1).Result;
46+
var id2 = sr.RegisterSchemaAsync(subject, testSchema2).Result;
47+
48+
var versions = sr.GetSubjectVersionsAsync(subject).Result;
49+
50+
Assert.Equal(versions.Count, 2);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)