Skip to content

Map raw binary request/response bodies to Resource - #394

Merged
jemacineiras merged 2 commits into
sngular:mainfrom
joseegman-idoneea:feat/binary-body-resource
Jul 31, 2026
Merged

Map raw binary request/response bodies to Resource#394
jemacineiras merged 2 commits into
sngular:mainfrom
joseegman-idoneea:feat/binary-body-resource

Conversation

@joseegman-idoneea

Copy link
Copy Markdown
Contributor

What

Maps a raw binary request/response body (type: string, format: binary not wrapped in a multipart object, e.g. application/octet-stream) to Resource instead of String. Closes #393.

Why

Binary → file type was only applied to object properties and (since #387) array items. The top-level content path MapperPathUtil.getObjectOrType had no binary detection, so a raw binary body fell through to String.

Change

  • New TypeConstants.RESOURCE type mapped to org.springframework.core.io.Resource (type / import / impl mappings).
  • getObjectOrType: return Resource when ApiTool.isBinary(schema).
  • Server templates (template.ftlh, templateReactive.ftlh): import org.springframework.core.io.Resource on demand when a body/response uses it.

Resource is used rather than MultipartFile, since a raw @RequestBody binary payload is a streaming resource, not a multipart part. The annotated flavor emits @RequestBody Resource, the reactive flavor @RequestBody Mono<Resource>.

Generated output

// annotated
default ResponseEntity<Void> uploadBinary(@Valid @RequestBody Resource resource) { ... }
// reactive
default ResponseEntity<Void> uploadBinary(@Valid @RequestBody Mono<Resource> resource,
    @ApiIgnore final ServerWebExchange exchange) { ... }

Test

  • New testBinaryBodyResource and testReactiveBinaryBodyResource fixtures + goldens.
  • Full engine suite green: Tests run: 121, Failures: 0, Errors: 0.

Version

Bumps 6.6.36.6.4 across engine, Maven plugin and Gradle plugin.

🤖 Generated with Claude Code

joseegarcia and others added 2 commits July 31, 2026 11:11
MapperPathUtil.getObjectOrType typed a top-level `type: string, format: binary`
body (e.g. application/octet-stream, not wrapped in a multipart object) as
String, because it never checked ApiTool.isBinary. Binary -> file type was
only applied to object properties and array items.

Add a RESOURCE type (org.springframework.core.io.Resource) and return it from
getObjectOrType for binary schemas. Resource (not MultipartFile) is used
because a raw @RequestBody binary payload is a streaming resource, not a
multipart part; the reactive template wraps it as Mono<Resource>. Both server
templates import Resource on demand.

Adds testBinaryBodyResource and testReactiveBinaryBodyResource fixtures.

Fixes sngular#393

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jemacineiras
jemacineiras merged commit f24c14e into sngular:main Jul 31, 2026
6 of 8 checks passed
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.

Raw binary request/response body (application/octet-stream) generates String instead of Resource

2 participants