Skip to content

[BUG] [swift] PUT request with Content-Type image/jpeg crashes #21539

Open
@Jonas1893

Description

@Jonas1893

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request
Description

If a PUT endpoint expects Content-Type: "image/" generator will crash

openapi-generator version

7.14.0 and older

OpenAPI declaration file content or url
swagger: '2.0'
info:
  title: Foobar
  version: '1.0'
paths:
  /v1/user/avatar:
    put:
      summary: Updates the avatar of a user
      description: >
        Creates or update the avatar for jpeg, jpg or png images.
      operationId: putUserAvatar
      consumes:
        - image/jpeg
        - image/jpg
        - image/png
      produces:
        - application/json
        - image/jpeg
        - image/jpg
        - image/png
      parameters:
        - name: image
          in: body
          description: 'the avatar to be set. Allowed formats: jpeg, jpg, png'
          required: true
          schema:
            $ref: '#/definitions/InputStream'
      responses:
        '200':
          description: The avatar was updated.
        '400':
          description: Bad Request. The payload can be empty when the request is invalid
definitions:
  InputStream:
    type: string
    format: binary
Generation Details

I observed this issue with the following configurations but from looking at the code I think this should always be a problem

generator: swift5 and swift6
responseAs: AsyncAwait and Combine
library: urlsession

Steps to reproduce

Use the minimal spec and generate code.
Executing the upload will produce fatalError with "Unsupported Media Type" at runtime in URLSessionRequestBuilder.execute since "image/jpeg" is not handled

Related issues/PRs
Suggest a fix

image content-types could also be handled using OctetStreamEncoding

I could contribute a fix if this is accepted

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions