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

fix(gen): set Explode:false for multipart arrays #1323

Closed
wants to merge 1 commit into from

Conversation

Liooo
Copy link
Contributor

@Liooo Liooo commented Oct 6, 2024

problem

  • currently the gen code from the schema below raises invalid length uuid error, when receiving multiple array items

    requestBody:
      content:
        multipart/form-data:
          schema:
          	type: object
               properties:
                 ids:
                   type: array
                   items:
                     type: string
                     format: uuid
  • here, there seems to be multiple possible ways to describe array in multipart/form-data as I looked shallowly on the internet (no canonical information like RFC kind), for example:

    • 1. single key comma separated

      ------WebKitFormBoundaryBrahBrah
      Content-Disposition: form-data; name="ids"
      <uuid1>,<uuid2>
      
    • 2. multiple keys

      ------WebKitFormBoundaryBrahBrah
      Content-Disposition: form-data; name="ids"
      <uuid1>
      
      ------WebKitFormBoundaryBrahBrah
      Content-Disposition: form-data; name="ids"
      <uuid2>
      
    • 3. multiple bracketed keys

      ------WebKitFormBoundaryBrahBrah
      Content-Disposition: form-data; name="ids[]"
      <uuid1>
      
      ------WebKitFormBoundaryBrahBrah
      Content-Disposition: form-data; name="ids[]"
      <uuid2>
      
  • the error above occurs when format 1. is specified, because ogen uses hardcoded Explode:true for the array decoding, and then parse comma separated values as a single uuid

solution

set Explode to false for multipart array

others

  • seems like there's encoding field that can be used to specify the style and explode of multipart data, which was introduced from OpenAPI3.1 , ideally we might wanna see this field someday
    • though ogen generated code uses ParseMultipartForm() from standard http package before its own parsing logic, and seems like this one accepts the format 1. only (for format 2. and 3. only first item is picked and the rest is ignored this might not be true), and might need more investigation to thoroughly support things

@Liooo
Copy link
Contributor Author

Liooo commented Oct 6, 2024

this part might have been my misunderstanding, seems like ParseMultipartForm does render format 2.

though ogen generated code uses ParseMultipartForm() from standard http package before its own parsing logic, and seems like this one accepts the format 1. only

The solution may be just about supporting encoding field and allowing explode: false.

@Liooo Liooo closed this Oct 6, 2024
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.

1 participant