Skip to content

Commit 7b2bc82

Browse files
committed
Slight change to the replace-branch-versions operation to work with the go sdk
1 parent 95fde8f commit 7b2bc82

File tree

6 files changed

+129
-12
lines changed

6 files changed

+129
-12
lines changed

app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import io.apicurio.registry.rest.v3.beans.HandleReferencesType;
4242
import io.apicurio.registry.rest.v3.beans.IfArtifactExists;
4343
import io.apicurio.registry.rest.v3.beans.NewComment;
44+
import io.apicurio.registry.rest.v3.beans.ReplaceBranchVersions;
4445
import io.apicurio.registry.rest.v3.beans.Rule;
4546
import io.apicurio.registry.rest.v3.beans.SortOrder;
4647
import io.apicurio.registry.rest.v3.beans.VersionMetaData;
@@ -915,19 +916,20 @@ public VersionSearchResults listBranchVersions(String groupId, String artifactId
915916
@Override
916917
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID})
917918
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
918-
public List<String> replaceBranchVersions(String groupId, String artifactId, String branchId, List<String> data) {
919+
public List<String> replaceBranchVersions(String groupId, String artifactId, String branchId, ReplaceBranchVersions data) {
919920
requireParameter("groupId", groupId);
920921
requireParameter("artifactId", artifactId);
921922
requireParameter("branchId", branchId);
923+
requireParameter("versions", data.getVersions());
922924

923925
GA ga = new GA(groupId, artifactId);
924926
BranchId bid = new BranchId(branchId);
925927

926928
// Throw 404 if the artifact or branch does not exist.
927929
storage.getBranchMetaData(ga, bid);
928930

929-
storage.replaceBranchVersions(ga, bid, data.stream().map(VersionId::new).toList());
930-
return data;
931+
storage.replaceBranchVersions(ga, bid, data.getVersions().stream().map(VersionId::new).toList());
932+
return data.getVersions();
931933
}
932934

933935
@Override

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/BranchesTest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.apicurio.registry.rest.client.models.CreateBranch;
88
import io.apicurio.registry.rest.client.models.CreateVersion;
99
import io.apicurio.registry.rest.client.models.EditableBranchMetaData;
10+
import io.apicurio.registry.rest.client.models.ReplaceBranchVersions;
1011
import io.apicurio.registry.rest.client.models.VersionMetaData;
1112
import io.apicurio.registry.rest.client.models.VersionSearchResults;
1213
import io.apicurio.registry.types.ArtifactType;
@@ -372,7 +373,7 @@ public void testReplaceBranchVersions() throws Exception {
372373
Assertions.assertEquals("v2", results.getVersions().get(2).getName());
373374

374375
// Now replace the versions on the branch
375-
List<String> newVersions = List.of("1", "3", "5");
376+
ReplaceBranchVersions newVersions = replaceVersions("1", "3", "5");
376377
clientV3.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).branches().byBranchId("test-branch").versions().put(newVersions);
377378

378379
// Make sure the branch now has 1,3,5 on it.
@@ -552,4 +553,10 @@ private static AddVersionToBranch addVersion(String version) {
552553
return rval;
553554
}
554555

556+
private static ReplaceBranchVersions replaceVersions(String ... versions) {
557+
ReplaceBranchVersions rval = new ReplaceBranchVersions();
558+
rval.setVersions(List.of(versions));
559+
return rval;
560+
}
561+
555562
}

common/src/main/resources/META-INF/openapi.json

+17-4
Original file line numberDiff line numberDiff line change
@@ -3038,10 +3038,7 @@
30383038
"content": {
30393039
"application/json": {
30403040
"schema": {
3041-
"type": "array",
3042-
"items": {
3043-
"$ref": "#/components/schemas/Version"
3044-
}
3041+
"$ref": "#/components/schemas/ReplaceBranchVersions"
30453042
}
30463043
}
30473044
},
@@ -4865,6 +4862,22 @@
48654862
"type": "string"
48664863
}
48674864
}
4865+
},
4866+
"ReplaceBranchVersions": {
4867+
"description": "",
4868+
"required": [
4869+
"versions"
4870+
],
4871+
"type": "object",
4872+
"properties": {
4873+
"versions": {
4874+
"description": "",
4875+
"type": "array",
4876+
"items": {
4877+
"$ref": "#/components/schemas/Version"
4878+
}
4879+
}
4880+
}
48684881
}
48694882
},
48704883
"responses": {

go-sdk/pkg/registryclient-v3/groups/item_artifacts_item_branches_item_versions_request_builder.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) Post(ctx context.C
9999
}
100100

101101
// Put add a new version to an artifact branch. Branch is created if it does not exist. Returns a list of version identifiers in the artifact branch, ordered from the latest (tip of the branch) to the oldest.This operation can fail for the following reasons:* No artifact with this `groupId` and `artifactId` exists (HTTP error `404`)* No branch with this `branchId` exists (HTTP error `404`)* A server error occurred (HTTP error `500`)
102-
func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) Put(ctx context.Context, body []string, requestConfiguration *ItemArtifactsItemBranchesItemVersionsRequestBuilderPutRequestConfiguration) ([]string, error) {
102+
func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) Put(ctx context.Context, body i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.ReplaceBranchVersionsable, requestConfiguration *ItemArtifactsItemBranchesItemVersionsRequestBuilderPutRequestConfiguration) ([]string, error) {
103103
requestInfo, err := m.ToPutRequestInformation(ctx, body, requestConfiguration)
104104
if err != nil {
105105
return nil, err
@@ -151,14 +151,17 @@ func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) ToPostRequestInfor
151151
}
152152

153153
// ToPutRequestInformation add a new version to an artifact branch. Branch is created if it does not exist. Returns a list of version identifiers in the artifact branch, ordered from the latest (tip of the branch) to the oldest.This operation can fail for the following reasons:* No artifact with this `groupId` and `artifactId` exists (HTTP error `404`)* No branch with this `branchId` exists (HTTP error `404`)* A server error occurred (HTTP error `500`)
154-
func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) ToPutRequestInformation(ctx context.Context, body []string, requestConfiguration *ItemArtifactsItemBranchesItemVersionsRequestBuilderPutRequestConfiguration) (*i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestInformation, error) {
154+
func (m *ItemArtifactsItemBranchesItemVersionsRequestBuilder) ToPutRequestInformation(ctx context.Context, body i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.ReplaceBranchVersionsable, requestConfiguration *ItemArtifactsItemBranchesItemVersionsRequestBuilderPutRequestConfiguration) (*i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestInformation, error) {
155155
requestInfo := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewRequestInformationWithMethodAndUrlTemplateAndPathParameters(i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.PUT, m.BaseRequestBuilder.UrlTemplate, m.BaseRequestBuilder.PathParameters)
156156
if requestConfiguration != nil {
157157
requestInfo.Headers.AddAll(requestConfiguration.Headers)
158158
requestInfo.AddRequestOptions(requestConfiguration.Options)
159159
}
160160
requestInfo.Headers.TryAdd("Accept", "application/json")
161-
requestInfo.SetContentFromScalarCollection(ctx, m.BaseRequestBuilder.RequestAdapter, "application/json", body)
161+
err := requestInfo.SetContentFromParsable(ctx, m.BaseRequestBuilder.RequestAdapter, "application/json", body)
162+
if err != nil {
163+
return nil, err
164+
}
162165
return requestInfo, nil
163166
}
164167

go-sdk/pkg/registryclient-v3/kiota-lock.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"descriptionHash": "42439AFF83C21EDECF676DFDD248144EF5307FE92011DD89799DDA4BF2880592398FC34275D0990B3D9DEED38D6A6872549DED2FDBC42C1BF4A0F154D7C82AE3",
2+
"descriptionHash": "344F39276758E3CA8971963C90DE0ABFE6B0AFCA167B697352C6D2ADB8169B7B9074D1131C064A29C40DA6929275DFBD069D9349C9886E90AD5A62AD2538A18B",
33
"descriptionLocation": "../../v3.json",
44
"lockFileVersion": "1.0.0",
55
"kiotaVersion": "1.10.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package models
2+
3+
import (
4+
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
5+
)
6+
7+
// ReplaceBranchVersions
8+
type ReplaceBranchVersions struct {
9+
// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
10+
additionalData map[string]any
11+
// The versions property
12+
versions []string
13+
}
14+
15+
// NewReplaceBranchVersions instantiates a new ReplaceBranchVersions and sets the default values.
16+
func NewReplaceBranchVersions() *ReplaceBranchVersions {
17+
m := &ReplaceBranchVersions{}
18+
m.SetAdditionalData(make(map[string]any))
19+
return m
20+
}
21+
22+
// CreateReplaceBranchVersionsFromDiscriminatorValue creates a new instance of the appropriate class based on discriminator value
23+
func CreateReplaceBranchVersionsFromDiscriminatorValue(parseNode i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) (i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, error) {
24+
return NewReplaceBranchVersions(), nil
25+
}
26+
27+
// GetAdditionalData gets the AdditionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
28+
func (m *ReplaceBranchVersions) GetAdditionalData() map[string]any {
29+
return m.additionalData
30+
}
31+
32+
// GetFieldDeserializers the deserialization information for the current model
33+
func (m *ReplaceBranchVersions) GetFieldDeserializers() map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
34+
res := make(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error)
35+
res["versions"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
36+
val, err := n.GetCollectionOfPrimitiveValues("string")
37+
if err != nil {
38+
return err
39+
}
40+
if val != nil {
41+
res := make([]string, len(val))
42+
for i, v := range val {
43+
if v != nil {
44+
res[i] = *(v.(*string))
45+
}
46+
}
47+
m.SetVersions(res)
48+
}
49+
return nil
50+
}
51+
return res
52+
}
53+
54+
// GetVersions gets the versions property value. The versions property
55+
func (m *ReplaceBranchVersions) GetVersions() []string {
56+
return m.versions
57+
}
58+
59+
// Serialize serializes information the current object
60+
func (m *ReplaceBranchVersions) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.SerializationWriter) error {
61+
if m.GetVersions() != nil {
62+
err := writer.WriteCollectionOfStringValues("versions", m.GetVersions())
63+
if err != nil {
64+
return err
65+
}
66+
}
67+
{
68+
err := writer.WriteAdditionalData(m.GetAdditionalData())
69+
if err != nil {
70+
return err
71+
}
72+
}
73+
return nil
74+
}
75+
76+
// SetAdditionalData sets the AdditionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
77+
func (m *ReplaceBranchVersions) SetAdditionalData(value map[string]any) {
78+
m.additionalData = value
79+
}
80+
81+
// SetVersions sets the versions property value. The versions property
82+
func (m *ReplaceBranchVersions) SetVersions(value []string) {
83+
m.versions = value
84+
}
85+
86+
// ReplaceBranchVersionsable
87+
type ReplaceBranchVersionsable interface {
88+
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.AdditionalDataHolder
89+
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable
90+
GetVersions() []string
91+
SetVersions(value []string)
92+
}

0 commit comments

Comments
 (0)