Skip to content

fix(OpenAPI): Fix Stream response being treated as File response in OpenAPI schema#4371

Merged
provinzkraut merged 1 commit intomainfrom
fix-stream-response-implicit-file
Oct 2, 2025
Merged

fix(OpenAPI): Fix Stream response being treated as File response in OpenAPI schema#4371
provinzkraut merged 1 commit intomainfrom
fix-stream-response-implicit-file

Conversation

@provinzkraut
Copy link
Copy Markdown
Member

Fix handler returning a Stream falsely indicating a file response in the OpenAPI schema:

{
"description": "Stream Response",
"headers": {
  "content-length": {
    "schema": {
      "type": "string"
    },
    "description": "File size in bytes",
    "required": false,
    "deprecated": false
  },
  "last-modified": {
    "schema": {
      "type": "string",
      "format": "date-time"
    },
    "description": "Last modified data-time in RFC 2822 format",
    "required": false,
    "deprecated": false
  },
  "etag": {
    "schema": {
      "type": "string"
    },
    "description": "Entity tag",
    "required": false,
    "deprecated": false
  }
}

@provinzkraut provinzkraut requested review from a team as code owners September 30, 2025 17:58
@github-actions github-actions bot added area/openapi This PR involves changes to the OpenAPI schema area/private-api This PR involves changes to the privatized API size: small type/bug pr/internal labels Sep 30, 2025
@provinzkraut provinzkraut force-pushed the fix-stream-response-implicit-file branch from 94f2615 to 85f4529 Compare September 30, 2025 17:59
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.93%. Comparing base (9f83ef0) to head (bcd7409).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4371   +/-   ##
=======================================
  Coverage   97.93%   97.93%           
=======================================
  Files         319      319           
  Lines       15569    15569           
  Branches     1721     1721           
=======================================
  Hits        15247    15247           
  Misses        184      184           
  Partials      138      138           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@provinzkraut provinzkraut force-pushed the fix-stream-response-implicit-file branch from 85f4529 to bcd7409 Compare October 2, 2025 14:04
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 2, 2025

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4371

@provinzkraut provinzkraut merged commit acef4e2 into main Oct 2, 2025
28 checks passed
@provinzkraut provinzkraut deleted the fix-stream-response-implicit-file branch October 2, 2025 14:21
provinzkraut added a commit that referenced this pull request Oct 5, 2025
…in OpenAPI schema (#4371)

(cherry picked from commit acef4e2)
@robertlagrant
Copy link
Copy Markdown

How does this interact with the fact that (I believe) we can't return a File object, only an OctetStream, if the file is in memory? I've just updated and it's changed the response type of my application/octet-stream:
image

(Context is this is causing various typescript things to fail in the frontend code that uses the openapi spec, so it's not a non-breaking change in our case.)

@provinzkraut
Copy link
Copy Markdown
Member Author

How does this interact with the fact that (I believe) we can't return a File object, only an OctetStream, if the file is in memory? I've just updated and it's changed the response type of my application/octet-stream

You can set the content media type manually:

@get("/", content_media_type="application/octet-stream")
async def handler() -> Stream:
 ...

This should have the same result.

But now that I think about it, application/octet-stream is probably a more sensible default for Stream.

Feel free to open a new issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/openapi This PR involves changes to the OpenAPI schema area/private-api This PR involves changes to the privatized API pr/internal size: small type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants