Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to the /ids/globalIds endpoint to return the artifacttype as a response header #5471

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public Response getContentById(long contentId) {
*/
@Override
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
public Response getContentByGlobalId(long globalId, HandleReferencesType references) {
public Response getContentByGlobalId(long globalId, HandleReferencesType references,
Boolean returnArtifactType) {
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(globalId);
if (VersionState.DISABLED.equals(metaData.getState())
|| VersionState.DRAFT.equals(metaData.getState())) {
Expand All @@ -82,6 +83,9 @@ public Response getContentByGlobalId(long globalId, HandleReferencesType referen

Response.ResponseBuilder builder = Response.ok(contentToReturn.getContent(),
contentToReturn.getContentType());
if (returnArtifactType != null && returnArtifactType) {
builder.header("X-Registry-ArtifactType", metaData.getArtifactType());
}
checkIfDeprecated(metaData::getState, metaData.getArtifactId(), metaData.getVersion(), builder);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.apicurio.registry.utils.tests.TestUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.apache.commons.codec.digest.DigestUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

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

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

@Test
Expand All @@ -134,7 +141,6 @@ public void testGetByGlobalIdIssue1501() throws Exception {
// Get by globalId should not fail
clientV3.ids().globalIds().byGlobalId(globalId1).get();
clientV3.ids().globalIds().byGlobalId(globalId2).get();

}

@Test
Expand Down
15 changes: 15 additions & 0 deletions common/src/main/resources/META-INF/openapi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-api-servers

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

rhoas-servers-config
"openapi": "3.0.3",
"info": {
"title": "Apicurio Registry API [v3]",
Expand All @@ -14,7 +14,7 @@
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"paths": {

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-media-example "value" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-media-example "value" property must have required property "title"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "version" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must match pattern "^[a-zA-Z0-9._\-+]{1,256}$"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must be equal to one of the allowed values: "OUTBOUND", "INBOUND". Did you mean "INBOUND"?

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "content" property must have required property "contentType"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must have required property "title"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "createdOn" property must match format "date-time"
"/ids/globalIds/{globalId}": {
"summary": "Access artifact content utilizing an artifact version's globally unique identifier.",
"get": {
Expand All @@ -29,6 +29,14 @@
"$ref": "#/components/schemas/HandleReferencesType"
},
"in": "query"
},
{
"name": "returnArtifactType",
"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.",
"schema": {
"type": "boolean"
},
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -5439,6 +5447,13 @@
"description": "Common response used when an input conflicts with existing data."
},
"ArtifactContent": {
"headers": {
"X-Registry-ArtifactType": {
"schema": {
"$ref": "#/components/schemas/ArtifactType"
}
}
},
"content": {
"*/*": {
"schema": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type GlobalIdsWithGlobalItemRequestBuilderGetQueryParameters struct {
References *string `uriparametername:"references"`
// Allows the user to specify how references in the content should be treated.
ReferencesAsHandleReferencesType *i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.HandleReferencesType `uriparametername:"references"`
// When set to `true`, the HTTP response will include a header named `X-Registry-ArtifactType`that contains the type of the artifact being returned.
ReturnArtifactType *bool `uriparametername:"returnArtifactType"`
}

// GlobalIdsWithGlobalItemRequestBuilderGetRequestConfiguration configuration for the request such as headers, query parameters, and middleware options.
Expand All @@ -33,7 +35,7 @@ type GlobalIdsWithGlobalItemRequestBuilderGetRequestConfiguration struct {
// NewGlobalIdsWithGlobalItemRequestBuilderInternal instantiates a new GlobalIdsWithGlobalItemRequestBuilder and sets the default values.
func NewGlobalIdsWithGlobalItemRequestBuilderInternal(pathParameters map[string]string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *GlobalIdsWithGlobalItemRequestBuilder {
m := &GlobalIdsWithGlobalItemRequestBuilder{
BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/ids/globalIds/{globalId}{?references*}", pathParameters),
BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/ids/globalIds/{globalId}{?references*,returnArtifactType*}", pathParameters),
}
return m
}
Expand Down
2 changes: 1 addition & 1 deletion go-sdk/pkg/registryclient-v3/kiota-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"descriptionHash": "760E2C412DC1229895C64DE9E5C64E93739B4734CB2A4444323019D1A22B4C081479F739A9C7372E3E87D335E577DDE222B8DF9D48DF05ED285DEA1D2C7F2729",
"descriptionHash": "1494AA12BB8D5D92915A230B88E70766D0D39CD6DFFF99D36D62AED1CAE34F87673F1CB46CB5CB48DB3BC4A45C3B84CBE26F2EEEBC4FB567BD6F2E564B225FF4",
"descriptionLocation": "../../v3.json",
"lockFileVersion": "1.0.0",
"kiotaVersion": "1.19.1",
Expand Down
Loading