Skip to content
Open
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
15 changes: 15 additions & 0 deletions doc/release-notes/12096-fix-ok-message-nested-object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### API Response Format Fix for `message` Field

The `message` field in API responses from certain endpoints was incorrectly returned as a nested object (`{"message": {"message": "..."}}`) instead of a plain string (`{"message": "..."}`).

This has been fixed. The following endpoints now return the `message` field as a string, consistent with all other API responses:

- `POST /api/datasets/{id}/add` (when uploading duplicate files)
- `PUT /api/admin/settings`
- `PUT /api/dataverses/{id}`
- `PUT /api/dataverses/{id}/inputLevels`
- `POST /api/admin/savedsearches`
- `PUT /api/harvest/clients/{nickName}`
- `PUT /api/harvest/server/oaisets/{specname}`

**Note:** If you implemented a workaround to handle the nested `message` object, you may need to update your code to expect a plain string instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErykKul please also put this information in doc/sphinx-guides/source/api/changelog.rst

5 changes: 5 additions & 0 deletions doc/sphinx-guides/source/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ This API changelog is experimental and we would love feedback on its usefulness.
:local:
:depth: 1

v6.10
-----

- Several API endpoints that return both a ``message`` and ``data`` field were incorrectly returning the message as a nested object (``{"message":{"message":"..."}}``). This has been fixed so that the message is now a plain string (``{"message":"..."}``). Affected endpoints: ``POST /api/datasets/{id}/add`` (duplicate file warning), ``PUT /api/admin/settings``, ``PUT /api/dataverses/{id}``, ``PUT /api/dataverses/{id}/inputLevels``, ``POST /api/admin/savedsearches``, ``PUT /api/harvest/clients/{nickName}``, ``PUT /api/harvest/server/oaisets/{specname}``. See `#12096 <https://github.com/IQSS/dataverse/issues/12096>`_.

v6.9
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ protected Response ok( String msg ) {
protected Response ok( String msg, JsonObjectBuilder bld ) {
return Response.ok().entity(Json.createObjectBuilder()
.add("status", ApiConstants.STATUS_OK)
.add("message", Json.createObjectBuilder().add("message",msg))
.add("message", msg)
.add("data", bld).build())
.type(MediaType.APPLICATION_JSON)
.build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just note here that Jenkins tests are failing due to this change. Please fix them. Thanks!

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void testSettingsRoundTrip() {
.assertThat()
.statusCode(OK.getStatusCode())
.body("status", equalTo("OK"))
.body("message.message", containsString("successfully updated"));
.body("message", containsString("successfully updated"));

// Step 5: Verify the harmless setting is gone (restored to original state)
Response verifyRestoredResponse = UtilIT.getSetting(harmlessSetting);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1120,23 +1120,23 @@ public void testAttributesApi() {
Response changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "name", newCollectionName, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));
.body("message", equalTo("Update successful"));

// Change the description of the collection:

String newDescription = "Renamed Description";
changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "description", newDescription, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));
.body("message", equalTo("Update successful"));

// Change the affiliation of the collection:

String newAffiliation = "Renamed Affiliation";
changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "affiliation", newAffiliation, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));
.body("message", equalTo("Update successful"));

// Cannot update filePIDsEnabled from a regular user:

Expand All @@ -1149,7 +1149,7 @@ public void testAttributesApi() {
changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "alias", newCollectionAlias, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));
.body("message", equalTo("Update successful"));

// Check on the collection, under the new alias:

Expand Down