Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing start boundary for multipart body #8181

Open
naraesk opened this issue Sep 15, 2022 · 3 comments
Open

Missing start boundary for multipart body #8181

naraesk opened this issue Sep 15, 2022 · 3 comments

Comments

@naraesk
Copy link

naraesk commented Sep 15, 2022

Q&A (please complete the following information)

  • OS: Linux
  • Browser: Chrome / Firefox
  • Version: 105/104
  • Method of installation: npm
  • Swagger-UI version: using swagger-jaxrs2-jakarta/2.2.2
  • OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: FormData MultiPart Example
  version: 1.0.0
paths:
  /foo:
    post:
      operationId: updatePet
      parameters:
        - name: id
          in: query
          required: true
          schema:
            pattern: ^(?!aliases$)(?!ids$)[-_.a-zA-Z0-9]+$
            type: string
        - name: additionalMetadata
          in: query
          description: Additional Metadata
          required: false
          schema:
            type: string
      requestBody:
        content: 
          multipart/form-data: # Media type
            schema:   
              type: string
              format: binary
      responses:
        '200':
          description: Successful operation

Describe the bug you're encountering

It seems that there is no start boundary set. Chrome Dev Tools also only show the end boundary but no start boundary. This leads to the following exception on the server:

Caused by: org.jvnet.mimepull.MIMEParsingException: Missing start boundary
at org.jvnet.mimepull.MIMEParser.skipPreamble(MIMEParser.java:288)
at org.jvnet.mimepull.MIMEParser.access$300(MIMEParser.java:38)
at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:124)
at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:102)
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:199)
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:160)
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:86)

To reproduce...

Steps to reproduce the behavior:
Just fill out the form and have a look at the request header

Expected behavior

There should be a start boundary set, but there isn't any.

Screenshots

image

Additional context or thoughts

The curl command produced by swagger-ui works as expected, there the start boundary is set.

@LouCastaldo
Copy link

Having same issue, has this been resolved ?

@hkosova
Copy link
Contributor

hkosova commented Nov 29, 2022

@naraesk change the requestBody as follows:

      requestBody:
        content: 
          multipart/form-data:
            schema:
              type: object
              properties:
                myFile:  # The name of the form field that contains the file
                  type: string
                  format: binary

As explained in Multipart Requests, the request body schema must be type: object whose properties represent individual parts (form fields) of a multipart request.

@LouCastaldo
Copy link

My request looks like below. I get a 200 back but it only passes the pdf file as an attachement but does not pass the Json part at all. Any ideas ? The "encoding" keyword does not seem to do anything at all.

  requestBody:
    content:
      multipart/form-data:
          schema:
            description: The main schema representing the multipart body.
            type: object
            properties:
              json:
                $ref: '#/components/schemas/request-wrapper'
              files:
                type: array
                items:
                  type: string
                  format: binary
          encoding:
            json: 
              contentType: application/json
            files:
              contentType: application/pdf

components:
schemas:
request-wrapper:
type: object
properties:
SomeID:
type: string

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

No branches or pull requests

3 participants