Skip to content

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

Description

@joseegman-idoneea

Description

A raw binary request/response body — type: string, format: binary not wrapped in a multipart object (e.g. application/octet-stream) — is generated as String instead of a binary type.

Binary → file type was only applied to object properties (MultipartFile, via ModelBuilder) and, after #387, to array items. The top-level content path (MapperPathUtil.getObjectOrType) has no binary detection.

Steps to reproduce

paths:
  /upload:
    post:
      operationId: uploadBinary
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        '200':
          description: OK

Actual result

default ResponseEntity<Void> uploadBinary(@Valid @RequestBody String resource) { ... }

Expected result

A streaming binary type:

default ResponseEntity<Void> uploadBinary(@Valid @RequestBody Resource resource) { ... }

(org.springframework.core.io.Resource; the reactive flavor wraps it as Mono<Resource>.)

Root cause

MapperPathUtil.getObjectOrType switches on the schema type and, for type: string, falls through to the default -> String branch without ever calling ApiTool.isBinary. MapperPathUtil.mapContentObject only builds a wrapping schema object for form-data media types, so a non-multipart binary body is typed purely by getObjectOrType.

Notes

Resource is used (not MultipartFile) because MultipartFile is a multipart-part type; a raw @RequestBody binary payload is idiomatically a streaming Resource.

Environment

  • OpenAPI code generator (multiapi-engine), annotated + reactive server interface templates.
  • Reproduced on main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions