Skip to content

Add support for REST API v0.7#77

Open
carlspring wants to merge 1 commit intomasterfrom
issue/68/add-support-for-rest-api-v07
Open

Add support for REST API v0.7#77
carlspring wants to merge 1 commit intomasterfrom
issue/68/add-support-for-rest-api-v07

Conversation

@carlspring
Copy link
Copy Markdown
Collaborator

@carlspring carlspring commented Mar 30, 2026

Task Description

Fixes for #68:

  • Applied the required code fixes.
  • Added unit + integration tests.

Summary by CodeRabbit

  • New Features

    • Exposes richer file details: content info, metadata and app-specific appData.
  • Improvements

    • Image/video info now falls back to content info when needed; client header updated for API v0.7 compatibility.
  • Tests

    • Added unit and live integration tests for v0.7 behavior, content_info shapes, metadata and app-data handling, and upload/lookup flow.
  • Chores

    • CI workflow refined: trigger patterns, PR vs master publishing split, build env secrets handling, and automated cleanup of merged PR snapshots.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Updates client to Uploadcare REST API v0.7 (Accept header and Javadoc), extends File/FileData with content_info/metadata/appdata and nullable-fallback accessors, adds unit and live integration tests for v0.7, and revises CI workflow triggers, snapshot publishing, and secret injection.

Changes

Cohort / File(s) Summary
CI / Build workflow
.github/workflows/build.yml
Replaced pull_request_target trigger with pull_request, normalized push branches/tags, use PR head SHA for checkouts on PRs, inject UPLOADCARE_PUBLIC_KEY/UPLOADCARE_SECRET_KEY into build env, split snapshot publishing into publish-pr-snapshot and publish-master-snapshot, and added cleanup-merged-pr-snapshot to delete PR snapshots on PR close/merge.
API Version Header
src/main/java/com/uploadcare/api/RequestHelper.java
Updated class Javadoc and default Accept header from application/vnd.uploadcare-v0.6+jsonapplication/vnd.uploadcare-v0.7+json.
File model & data
src/main/java/com/uploadcare/api/File.java, src/main/java/com/uploadcare/data/FileData.java
Added public fields contentInfo, metadata, appdata to FileData; added getContentInfo(), getMetadata(), getAppData() to File; getImageInfo()/getVideoInfo() now fall back to contentInfo.image/contentInfo.video when primary fields are null; added nested public static classes MimeInfo, ContentInfo, AppData.
Unit & Integration Tests
src/test/java/com/uploadcare/api/FileTest.java, src/test/java/com/uploadcare/api/RestApiVersionITTest.java
Centralized ObjectMapper in FileTest and added deserialization assertions for content_info, metadata, appdata. Added live integration tests (skipped unless secrets present) verifying v0.6 Warning header behavior, v0.7 behavior, and end-to-end upload+retrieve asserting content_info.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client as Java Client
    participant Uploadcare as Uploadcare API
    participant Storage as Cloud Storage

    User->>Client: uploadFile(olympia.jpg)
    Client->>Uploadcare: POST /upload/ (file)
    Uploadcare->>Storage: store file
    Storage-->>Uploadcare: stored
    Uploadcare-->>Client: fileId + metadata

    User->>Client: getFile(fileId)
    Client->>Uploadcare: GET /files/{id} (Accept: application/vnd.uploadcare-v0.7+json)
    Uploadcare-->>Client: file + content_info (mime, image, video)
    Client->>Client: map response -> File, ContentInfo, AppData
    Client-->>User: File object with v0.7 metadata

    Note over Client: getImageInfo()/getVideoInfo() fallback: prefer primary field, else use contentInfo.image/video
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main objective of the changeset: upgrading the Java client library to support Uploadcare REST API v0.7, which is reflected across multiple files including RequestHelper API version update, File class enhancements for new API fields, and comprehensive integration tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue/68/add-support-for-rest-api-v07

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@carlspring carlspring force-pushed the issue/68/add-support-for-rest-api-v07 branch 2 times, most recently from 5605c13 to 8b65218 Compare March 30, 2026 17:32
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/com/uploadcare/api/FileTest.java (1)

35-72: Please add assertions through File, not only FileData.

These tests prove deserialization, but the behavior change is in File#getImageInfo(), getVideoInfo(), getContentInfo(), getMetadata(), and getAppData(). Since this class is already in com.uploadcare.api, a small test around new File(null, fileData) would cover the actual API surface and fallback logic that changed.

Also applies to: 75-124, 127-170

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/FileTest.java` around lines 35 - 72, Update
the test to assert through the public File API rather than only on FileData:
create a File instance with new File(null, fileData) and call
File#getContentInfo(), getImageInfo(), getVideoInfo(), getMetadata(), and
getAppData() and assert the same fields (mime.mime/type/subtype,
image.format/width/height/colorMode) are exposed and mapped correctly (e.g.,
File.ColorMode.RGB). Replace or add assertions that reference
fileData.contentInfo/... with equivalent assertions that use
file.getContentInfo() and file.getImageInfo() to validate the API surface and
fallback logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/build.yml:
- Around line 49-53: The workflow exposes secrets to PR head code: the build job
injects UPLOADCARE_PUBLIC_KEY and UPLOADCARE_SECRET_KEY into the environment and
the publish-snapshot job uses GITHUB_TOKEN/packages:write while checking out and
running the PR head, allowing secrets exfiltration on forked PRs; to fix, gate
any steps that set these env vars or perform publishing (refer to the build job,
the env keys UPLOADCARE_PUBLIC_KEY/UPLOADCARE_SECRET_KEY, the publish-snapshot
job and GITHUB_TOKEN permission) behind a trusted-ref conditional such as if:
github.event_name == 'push' or if: github.ref == 'refs/heads/main', or
alternatively change the flow to use pull_request_target only for steps that
need secrets and fetch untrusted code via artifacts from a trusted runner (pass
build artifacts instead of running PR head with secrets); apply the conditional
to the steps that set env or run ./gradlew build --stacktrace and to any publish
steps with packages:write.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java`:
- Around line 77-87: The tests currently use response.getFirstHeader("Warning")
which misses cases with multiple Warning headers; update both
test_v06AcceptHeader_triggersDeprecationWarning() and
test_v07AcceptHeader_noDeprecationWarning() to call
response.getHeaders("Warning") and scan the returned Header[]: for the v06 test
assert that at least one header's getValue() contains "0.6" (replace the single
warningHeader/assertTrue logic), and for the v07 test assert that none of the
headers' getValue() contain "0.6" (replace the single
warningHeader/assertNull/assertTrue logic), keeping the existing failure
messages but iterating over the Header[] to avoid ordering-dependent false
failures/passes.

---

Nitpick comments:
In `@src/test/java/com/uploadcare/api/FileTest.java`:
- Around line 35-72: Update the test to assert through the public File API
rather than only on FileData: create a File instance with new File(null,
fileData) and call File#getContentInfo(), getImageInfo(), getVideoInfo(),
getMetadata(), and getAppData() and assert the same fields
(mime.mime/type/subtype, image.format/width/height/colorMode) are exposed and
mapped correctly (e.g., File.ColorMode.RGB). Replace or add assertions that
reference fileData.contentInfo/... with equivalent assertions that use
file.getContentInfo() and file.getImageInfo() to validate the API surface and
fallback logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6523c8d4-a723-452e-8475-3c5894eae185

📥 Commits

Reviewing files that changed from the base of the PR and between cebfa08 and 8b65218.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/main/java/com/uploadcare/data/FileData.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java

@carlspring carlspring force-pushed the issue/68/add-support-for-rest-api-v07 branch from 8b65218 to d3bbb10 Compare March 30, 2026 18:13
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/java/com/uploadcare/api/FileTest.java (1)

143-170: Consider adding date format configuration or assertions for datetime fields.

The JSON includes datetime_created and datetime_updated fields that map to java.util.Date in AppData, but:

  1. The ObjectMapper has no date format configuration (e.g., JavaTimeModule or date format pattern)
  2. The test doesn't assert on datetimeCreated/datetimeUpdated

Jackson's handling of ISO-8601 date strings for java.util.Date can be inconsistent. Either:

  • Configure date handling on the mapper to ensure reliable parsing
  • Remove the datetime fields from the test JSON if not under test
  • Add assertions for the datetime fields to verify they're parsed correctly
Option 1: Remove datetime fields if not testing them
         String json = "{"
                 + "\"uuid\": \"22240276-2f06-41f8-9411-755c8ce926ed\","
                 + "\"appdata\": {"
                 + "  \"uc_clamav_virus_scan\": {"
                 + "    \"data\": {"
                 + "      \"infected\": false,"
                 + "      \"infected_with\": null"
                 + "    },"
-                + "    \"version\": \"0.104.2\","
-                + "    \"datetime_created\": \"2021-09-21T11:24:33\","
-                + "    \"datetime_updated\": \"2021-09-21T11:24:33\""
+                + "    \"version\": \"0.104.2\""
                 + "  }"
                 + "}"
                 + "}";
Option 2: Add assertions for datetime fields
         assertEquals("0.104.2", appData.version);
         assertNotNull("appdata.data should not be null", appData.data);
+        assertNotNull("datetimeCreated should not be null", appData.datetimeCreated);
+        assertNotNull("datetimeUpdated should not be null", appData.datetimeUpdated);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/FileTest.java` around lines 143 - 170, The
test includes ISO-8601 datetime strings but the test ObjectMapper has no date
handling configuration and the test doesn't assert the parsed dates; update the
test to configure the mapper for ISO-8601 Date parsing (e.g., register
JavaTimeModule or setDateFormat(new StdDateFormat()) on the mapper used in this
test) and then add assertions on the File.AppData datetime fields (e.g., check
appData.datetimeCreated and appData.datetimeUpdated are non-null and equal to
expected instants) so the datetime_created/datetime_updated values are parsed
and verified; alternatively, if datetimes are out of scope, remove
datetime_created/datetime_updated from the test JSON instead of changing mapper
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/com/uploadcare/api/FileTest.java`:
- Around line 143-170: The test includes ISO-8601 datetime strings but the test
ObjectMapper has no date handling configuration and the test doesn't assert the
parsed dates; update the test to configure the mapper for ISO-8601 Date parsing
(e.g., register JavaTimeModule or setDateFormat(new StdDateFormat()) on the
mapper used in this test) and then add assertions on the File.AppData datetime
fields (e.g., check appData.datetimeCreated and appData.datetimeUpdated are
non-null and equal to expected instants) so the
datetime_created/datetime_updated values are parsed and verified; alternatively,
if datetimes are out of scope, remove datetime_created/datetime_updated from the
test JSON instead of changing mapper behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 378a78a8-7c8a-4ac2-bc14-1cae06f1bc14

📥 Commits

Reviewing files that changed from the base of the PR and between 8b65218 and d3bbb10.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/main/java/com/uploadcare/data/FileData.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java
✅ Files skipped from review due to trivial changes (2)
  • src/main/java/com/uploadcare/data/FileData.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java

@carlspring carlspring force-pushed the issue/68/add-support-for-rest-api-v07 branch from d3bbb10 to 55ad1e5 Compare March 30, 2026 19:27
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/test/java/com/uploadcare/api/RestApiVersionITTest.java (1)

77-87: ⚠️ Potential issue | 🟡 Minor

Scan all Warning headers, not only the first one.

Current assertions are order-dependent (getFirstHeader("Warning")) and can false-pass/false-fail when multiple Warning headers are present.

Suggested fix
-                Header warningHeader = response.getFirstHeader("Warning");
-                assertNotNull(
+                boolean hasV06Warning = Arrays.stream(response.getHeaders("Warning"))
+                        .map(Header::getValue)
+                        .anyMatch(value -> value.contains("0.6"));
+                assertTrue(
                         "BUG REPRODUCTION: Expected a Warning response header when using the "
                                 + "deprecated v0.6 Accept header, but none was found.\n"
                                 + "All response headers received: "
                                 + Arrays.toString(response.getAllHeaders()),
-                        warningHeader);
-                assertTrue(
-                        "BUG REPRODUCTION: The Warning header should mention API version deprecation "
-                                + "(e.g. 'not 0.6'), but was: " + warningHeader.getValue(),
-                        warningHeader.getValue().contains("0.6"));
+                        hasV06Warning);
-                Header warningHeader = response.getFirstHeader("Warning");
-                // A Warning header is acceptable as long as it is NOT an API-version deprecation
-                // warning (e.g. demo-project notices are fine, but "not 0.6" / "API version"
-                // upgrade messages must not appear when the client already uses v0.7).
-                if (warningHeader != null) {
-                    assertFalse("FIX VERIFICATION: No API-version deprecation Warning should be returned " +
-                                "when using the v0.7 Accept header, but one was found: " +
-                                warningHeader.getValue() + "\n" +
-                                "All response headers: " + Arrays.toString(response.getAllHeaders()),
-                                warningHeader.getValue().contains("0.6"));
-                }
+                boolean hasV06Warning = Arrays.stream(response.getHeaders("Warning"))
+                        .map(Header::getValue)
+                        .anyMatch(value -> value.contains("0.6"));
+                assertFalse("FIX VERIFICATION: No API-version deprecation Warning should be returned " +
+                                "when using the v0.7 Accept header.\n" +
+                                "All response headers: " + Arrays.toString(response.getAllHeaders()),
+                        hasV06Warning);
#!/bin/bash
# Verify all Warning-header assertions in this IT class and ensure getHeaders("Warning") is used.
rg -n -C2 'getFirstHeader\("Warning"\)|getHeaders\("Warning"\)' src/test/java/com/uploadcare/api/RestApiVersionITTest.java

Also applies to: 114-124

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java` around lines 77 -
87, The test in RestApiVersionITTest currently uses
response.getFirstHeader("Warning") (see the assertion block that references
warningHeader) which is order-dependent; change it to
response.getHeaders("Warning") and assert that the returned array is non-empty,
then scan (loop or stream) the headers to check at least one header's getValue()
contains "0.6" (update the assertion messages to include all headers via
Arrays.toString(headers)); apply the same change to the other occurrence in this
class (the block around the second assertion group currently using
getFirstHeader).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java`:
- Around line 149-153: The test in RestApiVersionITTest opens an InputStream via
getClass().getClassLoader().getResourceAsStream("olympia.jpg") and never closes
it; wrap the resource acquisition and the call to
IOUtils.toByteArray(imageStream) in a try-with-resources so imageStream is
automatically closed (replace the standalone imageStream variable usage with a
try (InputStream imageStream =
getClass().getClassLoader().getResourceAsStream("olympia.jpg")) { byte[]
imageBytes = IOUtils.toByteArray(imageStream); ... } ensuring the assertNotNull
check remains meaningful inside or immediately after resource acquisition).

---

Duplicate comments:
In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java`:
- Around line 77-87: The test in RestApiVersionITTest currently uses
response.getFirstHeader("Warning") (see the assertion block that references
warningHeader) which is order-dependent; change it to
response.getHeaders("Warning") and assert that the returned array is non-empty,
then scan (loop or stream) the headers to check at least one header's getValue()
contains "0.6" (update the assertion messages to include all headers via
Arrays.toString(headers)); apply the same change to the other occurrence in this
class (the block around the second assertion group currently using
getFirstHeader).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f19536be-3309-4404-9d4a-74530edad6bf

📥 Commits

Reviewing files that changed from the base of the PR and between d3bbb10 and 55ad1e5.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/main/java/com/uploadcare/data/FileData.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java
✅ Files skipped from review due to trivial changes (1)
  • src/main/java/com/uploadcare/data/FileData.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • .github/workflows/build.yml

Comment on lines +149 to +153
InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg");

assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);

byte[] imageBytes = IOUtils.toByteArray(imageStream);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Close the test resource stream with try-with-resources.

imageStream is not closed after IOUtils.toByteArray(...).

Suggested fix
-        InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg");
-
-        assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
-
-        byte[] imageBytes = IOUtils.toByteArray(imageStream);
+        byte[] imageBytes;
+        try (InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg")) {
+            assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
+            imageBytes = IOUtils.toByteArray(imageStream);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg");
assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
byte[] imageBytes = IOUtils.toByteArray(imageStream);
byte[] imageBytes;
try (InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg")) {
assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
imageBytes = IOUtils.toByteArray(imageStream);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java` around lines 149
- 153, The test in RestApiVersionITTest opens an InputStream via
getClass().getClassLoader().getResourceAsStream("olympia.jpg") and never closes
it; wrap the resource acquisition and the call to
IOUtils.toByteArray(imageStream) in a try-with-resources so imageStream is
automatically closed (replace the standalone imageStream variable usage with a
try (InputStream imageStream =
getClass().getClassLoader().getResourceAsStream("olympia.jpg")) { byte[]
imageBytes = IOUtils.toByteArray(imageStream); ... } ensuring the assertNotNull
check remains meaningful inside or immediately after resource acquisition).

@carlspring carlspring force-pushed the issue/68/add-support-for-rest-api-v07 branch from 55ad1e5 to b8b1620 Compare March 30, 2026 21:13
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/test/java/com/uploadcare/api/RestApiVersionITTest.java (2)

77-87: ⚠️ Potential issue | 🟡 Minor

Scan all Warning headers, not just the first one.

Using getFirstHeader("Warning") makes both tests order-dependent and can false-pass/false-fail when multiple warning headers are present.

Suggested fix
-                Header warningHeader = response.getFirstHeader("Warning");
-                assertNotNull(
+                boolean hasV06Warning = Arrays.stream(response.getHeaders("Warning"))
+                        .map(Header::getValue)
+                        .anyMatch(value -> value.contains("0.6"));
+                assertTrue(
                         "BUG REPRODUCTION: Expected a Warning response header when using the "
                                 + "deprecated v0.6 Accept header, but none was found.\n"
                                 + "All response headers received: "
                                 + Arrays.toString(response.getAllHeaders()),
-                        warningHeader);
-                assertTrue(
-                        "BUG REPRODUCTION: The Warning header should mention API version deprecation "
-                                + "(e.g. 'not 0.6'), but was: " + warningHeader.getValue(),
-                        warningHeader.getValue().contains("0.6"));
+                        hasV06Warning);
@@
-                Header warningHeader = response.getFirstHeader("Warning");
-                // A Warning header is acceptable as long as it is NOT an API-version deprecation
-                // warning (e.g. demo-project notices are fine, but "not 0.6" / "API version"
-                // upgrade messages must not appear when the client already uses v0.7).
-                if (warningHeader != null) {
-                    assertFalse("FIX VERIFICATION: No API-version deprecation Warning should be returned " +
-                                "when using the v0.7 Accept header, but one was found: " +
-                                warningHeader.getValue() + "\n" +
-                                "All response headers: " + Arrays.toString(response.getAllHeaders()),
-                                warningHeader.getValue().contains("0.6"));
-                }
+                boolean hasV06Warning = Arrays.stream(response.getHeaders("Warning"))
+                        .map(Header::getValue)
+                        .anyMatch(value -> value.contains("0.6"));
+                assertFalse("FIX VERIFICATION: No API-version deprecation Warning should be returned " +
+                                "when using the v0.7 Accept header.\n" +
+                                "All response headers: " + Arrays.toString(response.getAllHeaders()),
+                        hasV06Warning);
#!/bin/bash
# Verify warning-header access pattern in this test
rg -n 'getFirstHeader\("Warning"\)|getHeaders\("Warning"\)' src/test/java/com/uploadcare/api/RestApiVersionITTest.java

Also applies to: 114-124

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java` around lines 77 -
87, The test currently uses response.getFirstHeader("Warning") (variable
warningHeader) which is order-dependent; change to use
response.getHeaders("Warning") and scan the returned Header[] for presence and
for at least one header value containing "0.6". Update both assertion blocks in
RestApiVersionITTest (the presence check and the contains check) to iterate the
headers array, assert it's non-empty, and assert that any
header.getValue().contains("0.6") is true instead of relying on getFirstHeader.

149-153: ⚠️ Potential issue | 🟡 Minor

Close imageStream with try-with-resources.

imageStream is currently left open after reading bytes.

Suggested fix
-        InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg");
-
-        assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
-
-        byte[] imageBytes = IOUtils.toByteArray(imageStream);
+        byte[] imageBytes;
+        try (InputStream imageStream = getClass().getClassLoader().getResourceAsStream("olympia.jpg")) {
+            assertNotNull("Test resource olympia.jpg must be on the classpath", imageStream);
+            imageBytes = IOUtils.toByteArray(imageStream);
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java` around lines 149
- 153, In RestApiVersionITTest, the InputStream imageStream created for the
"olympia.jpg" resource is not closed; wrap the getResourceAsStream call and the
IOUtils.toByteArray(imageStream) usage in a try-with-resources block (using the
imageStream variable) so the stream is automatically closed after reading,
preserving the assertNotNull check before or inside the block as appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/build.yml:
- Around line 4-7: Re-enable the pull_request_target workflow trigger or remove
the PR-only logic: restore the commented block that defines pull_request_target
(so the workflow triggers on pull_request_target events) and keep the existing
external-contributors environment guard, or alternatively remove/update the
publish-snapshot job's PR-specific checks (the condition github.event_name ==
'pull_request_target' in the publish-snapshot job and any references to
github.event.pull_request used in steps) so the job no longer expects
pull_request properties when running on push. Target the pull_request_target
trigger and the publish-snapshot job/steps to ensure PR snapshots can run
safely.

---

Duplicate comments:
In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java`:
- Around line 77-87: The test currently uses response.getFirstHeader("Warning")
(variable warningHeader) which is order-dependent; change to use
response.getHeaders("Warning") and scan the returned Header[] for presence and
for at least one header value containing "0.6". Update both assertion blocks in
RestApiVersionITTest (the presence check and the contains check) to iterate the
headers array, assert it's non-empty, and assert that any
header.getValue().contains("0.6") is true instead of relying on getFirstHeader.
- Around line 149-153: In RestApiVersionITTest, the InputStream imageStream
created for the "olympia.jpg" resource is not closed; wrap the
getResourceAsStream call and the IOUtils.toByteArray(imageStream) usage in a
try-with-resources block (using the imageStream variable) so the stream is
automatically closed after reading, preserving the assertNotNull check before or
inside the block as appropriate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 86fe486c-221f-46bb-98e5-d110860a7135

📥 Commits

Reviewing files that changed from the base of the PR and between 55ad1e5 and b8b1620.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/main/java/com/uploadcare/data/FileData.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java
✅ Files skipped from review due to trivial changes (3)
  • src/main/java/com/uploadcare/data/FileData.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/test/java/com/uploadcare/api/FileTest.java

Fixes for #68:
* Applied the required code fixes.
* Added unit + integration tests.
@carlspring carlspring force-pushed the issue/68/add-support-for-rest-api-v07 branch from b8b1620 to 0f58913 Compare March 30, 2026 22:05
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/java/com/uploadcare/api/RestApiVersionITTest.java (1)

72-91: Consider simplifying with try-with-resources for httpClient.

The outer httpClient can be managed with try-with-resources, matching the pattern already used for the inner CloseableHttpResponse.

♻️ Suggested simplification
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        try {
+        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
             HttpGet request = buildRequest(Urls.apiFiles(), "application/vnd.uploadcare-v0.6+json");

             try (CloseableHttpResponse response = httpClient.execute(request)) {
                 // ... assertions ...
             }
-        } finally {
-            httpClient.close();
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java` around lines 72 -
91, The test currently creates CloseableHttpClient httpClient and closes it in a
finally block; change it to use try-with-resources so the client is auto-closed
and matches the existing try-with-resources for CloseableHttpResponse.
Specifically, replace the manual creation of httpClient and the surrounding
try/finally with a try (CloseableHttpClient httpClient =
HttpClients.createDefault()) { ... } block in RestApiVersionITTest so
buildRequest(...), the inner try (CloseableHttpResponse response =
httpClient.execute(request)), and the assertions remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/com/uploadcare/api/RestApiVersionITTest.java`:
- Around line 72-91: The test currently creates CloseableHttpClient httpClient
and closes it in a finally block; change it to use try-with-resources so the
client is auto-closed and matches the existing try-with-resources for
CloseableHttpResponse. Specifically, replace the manual creation of httpClient
and the surrounding try/finally with a try (CloseableHttpClient httpClient =
HttpClients.createDefault()) { ... } block in RestApiVersionITTest so
buildRequest(...), the inner try (CloseableHttpResponse response =
httpClient.execute(request)), and the assertions remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 929e0c7b-7a28-496e-b9dc-fbe606afed1c

📥 Commits

Reviewing files that changed from the base of the PR and between b8b1620 and 0f58913.

📒 Files selected for processing (6)
  • .github/workflows/build.yml
  • src/main/java/com/uploadcare/api/File.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/main/java/com/uploadcare/data/FileData.java
  • src/test/java/com/uploadcare/api/FileTest.java
  • src/test/java/com/uploadcare/api/RestApiVersionITTest.java
✅ Files skipped from review due to trivial changes (3)
  • src/main/java/com/uploadcare/data/FileData.java
  • src/main/java/com/uploadcare/api/RequestHelper.java
  • src/test/java/com/uploadcare/api/FileTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

@alxgsv alxgsv self-requested a review March 31, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants