Skip to content

Commit faedbec

Browse files
authored
Added an option to the /ids/globalIds endpoint to return the artifact type as a response header (#5471)
1 parent d454133 commit faedbec

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public Response getContentById(long contentId) {
6363
*/
6464
@Override
6565
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
66-
public Response getContentByGlobalId(long globalId, HandleReferencesType references) {
66+
public Response getContentByGlobalId(long globalId, HandleReferencesType references,
67+
Boolean returnArtifactType) {
6768
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(globalId);
6869
if (VersionState.DISABLED.equals(metaData.getState())
6970
|| VersionState.DRAFT.equals(metaData.getState())) {
@@ -82,6 +83,9 @@ public Response getContentByGlobalId(long globalId, HandleReferencesType referen
8283

8384
Response.ResponseBuilder builder = Response.ok(contentToReturn.getContent(),
8485
contentToReturn.getContentType());
86+
if (returnArtifactType != null && returnArtifactType) {
87+
builder.header("X-Registry-ArtifactType", metaData.getArtifactType());
88+
}
8589
checkIfDeprecated(metaData::getState, metaData.getArtifactId(), metaData.getVersion(), builder);
8690
return builder.build();
8791
}

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.apicurio.registry.utils.tests.TestUtils;
99
import io.quarkus.test.junit.QuarkusTest;
1010
import org.apache.commons.codec.digest.DigestUtils;
11+
import org.hamcrest.Matchers;
1112
import org.junit.jupiter.api.Assertions;
1213
import org.junit.jupiter.api.Test;
1314

@@ -110,8 +111,14 @@ public void testGetByGlobalId() throws Exception {
110111
// Get by globalId
111112
given().when().contentType(CT_JSON).pathParam("globalId", globalId)
112113
.get("/registry/v3/ids/globalIds/{globalId}").then().statusCode(200)
113-
.body("openapi", equalTo("3.0.2")).body("info.title", equalTo(title));
114+
.header("X-Registry-ArtifactType", Matchers.nullValue()).body("openapi", equalTo("3.0.2"))
115+
.body("info.title", equalTo(title));
114116

117+
// Get by globalId with artifactType
118+
given().when().contentType(CT_JSON).pathParam("globalId", globalId)
119+
.queryParam("returnArtifactType", true).get("/registry/v3/ids/globalIds/{globalId}").then()
120+
.statusCode(200).header("X-Registry-ArtifactType", "OPENAPI")
121+
.body("openapi", equalTo("3.0.2")).body("info.title", equalTo(title));
115122
}
116123

117124
@Test
@@ -134,7 +141,6 @@ public void testGetByGlobalIdIssue1501() throws Exception {
134141
// Get by globalId should not fail
135142
clientV3.ids().globalIds().byGlobalId(globalId1).get();
136143
clientV3.ids().globalIds().byGlobalId(globalId2).get();
137-
138144
}
139145

140146
@Test

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

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
"$ref": "#/components/schemas/HandleReferencesType"
3030
},
3131
"in": "query"
32+
},
33+
{
34+
"name": "returnArtifactType",
35+
"description": "When set to `true`, the HTTP response will include a header named `X-Registry-ArtifactType`\nthat contains the type of the artifact being returned.",
36+
"schema": {
37+
"type": "boolean"
38+
},
39+
"in": "query"
3240
}
3341
],
3442
"responses": {
@@ -5439,6 +5447,13 @@
54395447
"description": "Common response used when an input conflicts with existing data."
54405448
},
54415449
"ArtifactContent": {
5450+
"headers": {
5451+
"X-Registry-ArtifactType": {
5452+
"schema": {
5453+
"$ref": "#/components/schemas/ArtifactType"
5454+
}
5455+
}
5456+
},
54425457
"content": {
54435458
"*/*": {
54445459
"schema": {

go-sdk/pkg/registryclient-v3/ids/global_ids_with_global_item_request_builder.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type GlobalIdsWithGlobalItemRequestBuilderGetQueryParameters struct {
1818
References *string `uriparametername:"references"`
1919
// Allows the user to specify how references in the content should be treated.
2020
ReferencesAsHandleReferencesType *i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.HandleReferencesType `uriparametername:"references"`
21+
// When set to `true`, the HTTP response will include a header named `X-Registry-ArtifactType`that contains the type of the artifact being returned.
22+
ReturnArtifactType *bool `uriparametername:"returnArtifactType"`
2123
}
2224

2325
// GlobalIdsWithGlobalItemRequestBuilderGetRequestConfiguration configuration for the request such as headers, query parameters, and middleware options.
@@ -33,7 +35,7 @@ type GlobalIdsWithGlobalItemRequestBuilderGetRequestConfiguration struct {
3335
// NewGlobalIdsWithGlobalItemRequestBuilderInternal instantiates a new GlobalIdsWithGlobalItemRequestBuilder and sets the default values.
3436
func NewGlobalIdsWithGlobalItemRequestBuilderInternal(pathParameters map[string]string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *GlobalIdsWithGlobalItemRequestBuilder {
3537
m := &GlobalIdsWithGlobalItemRequestBuilder{
36-
BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/ids/globalIds/{globalId}{?references*}", pathParameters),
38+
BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/ids/globalIds/{globalId}{?references*,returnArtifactType*}", pathParameters),
3739
}
3840
return m
3941
}

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": "760E2C412DC1229895C64DE9E5C64E93739B4734CB2A4444323019D1A22B4C081479F739A9C7372E3E87D335E577DDE222B8DF9D48DF05ED285DEA1D2C7F2729",
2+
"descriptionHash": "1494AA12BB8D5D92915A230B88E70766D0D39CD6DFFF99D36D62AED1CAE34F87673F1CB46CB5CB48DB3BC4A45C3B84CBE26F2EEEBC4FB567BD6F2E564B225FF4",
33
"descriptionLocation": "../../v3.json",
44
"lockFileVersion": "1.0.0",
55
"kiotaVersion": "1.19.1",

0 commit comments

Comments
 (0)