10000 Are 'Multipart Requests' supported? · Issue #309 · cjbooms/fabrikt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Are 'Multipart Requests' supported? #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its mainta 8000 iners 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

Open
b0m123 opened this issue Aug 23, 2024 · 4 comments
Open

Are 'Multipart Requests' supported? #309

b0m123 opened this issue Aug 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@b0m123
Copy link
b0m123 commented Aug 23, 2024

Hi, I have a question whether Multipart requests are supported? (see https://swagger.io/docs/specification/describing-request-body/multipart-requests/)
I'm trying to generate simple OkHttp client with model (here is my endpoint in openapi.yaml as example)

  /api/import
    post:
      operationId: importMedia
      summary: Import Media
      description: >
        TEST Import media file
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - interaction
              properties:
                metadata:
                  $ref: '#/components/schemas/MediaFileDto'
                mediaFile:
                  type: array
                  items:
                    type: string
                    format: binary

but I'm facing an error Unresolved reference 'MultipartFormData'.

To be clear I'm using fabrikt-gradle-plugin with this config

fabrikt {
	generate("Client") {
		apiFile = file("openapi.yaml")
		externalReferenceResolution = aggressive
		basePackage = "com.example"
		outputDirectory = file("${project.layout.buildDirectory.get().asFile}/generated")
		typeOverrides {
			datetime = OffsetDateTime
		}
		client {
			generate = enabled
			target = OkHttp
		}
		model {
			generate = enabled
			sealedInterfacesForOneOf = enabled
			ignoreUnknownProperties = enabled
			includeCompanionObject = enabled
		}
	}
}

Thanks in advance for any support

@ulrikandersen ulrikandersen added the enhancement New feature or request label Sep 19, 2024
@ulrikandersen
Copy link
Collaborator
ulrikandersen commented Sep 19, 2024

Hi @b0m123,

I can confirm that requests with multipart/form-data does not currently lead to working code being generated.

This applies to the OkHttp client as well as the controller interfaces for Micronaut, Spring and Ktor

For OkHttp we will need to generate specific code for multipart requests. This recipe from OkHttp describes how to do it.

@ulrikandersen ulrikandersen added the bug Something isn't working label Sep 19, 2024
@ulrikandersen
Copy link
Collaborator
ulrikandersen commented Sep 19, 2024

One possible cause of action would be to add a special case to the request statement builder for operation.requestBody.getPrimaryContentMediaType()?.key == "multipart/form-data", which would construct the requestBody using OkHttp's MultipartBody.Builder().

@ulrikandersen ulrikandersen removed the bug Something isn't working label Oct 18, 2024
@mfhellh
Copy link
mfhellh commented Dec 3, 2024

Any idea how to work around this in the case of Controller (Spring) interfaces?
Thanks in advance!

@ulrikandersen
Copy link
Collaborator

Any idea how to work around this in the case of Controller (Spring) interfaces? Thanks in advance!

Since invalid code is generated in this case, the best you can do for now is probably to omit the specific endpoint from the spec before generating and implement it yourself. For sure not ideal, but there's unfortunately no support for multipart/form-data just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
0