:wave: I'm back with some more multipart question...
# http4k
m
👋 I'm back with some more multipart questions. I'm trying to get something a little easier to work with when I have a bigger DTO which also involves files. I'm trying to do this (which I have no idea if this is right, but it compiles and openapi generator makes the right thing):
Copy code
val inputFilesMultipart = MultipartFormFile.multi.optional("inputFiles")
val proxyTrackingMultipart = MultipartFormField.auto<PostPutProxyTrackingRequestDTO>(CustomJackson).required("proxyTracking")

data class PostPutProxyTrackingRequestDTO(
    val title: String,
    val description: String,
    val isin: String,
    val date: LocalDate,
    val existingDocumentIds: List<TenantDocumentId>,
    val options: List<PostPutProxyTrackingOptionRequestDTO>
)

data class PostPutProxyTrackingOptionRequestDTO(
    val option: String,
    val voted: Boolean,
)
val proxyTrackingFormBody = Body.multipartForm(Validator.Strict, inputFilesMultipart, proxyTrackingMultipart).toLens()
I'm then sending this request (no files in this one):
Copy code
curl '<http://localhost:9000/tenants/48a295c5-da55-45b7-8b95-78818dc38cc2/proxy-tracking>' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryEsUJBnHCya0lYGPx' \
  -H 'Origin: <http://localhost:3000>' \
  -H 'Referer: <http://localhost:3000/>' \
  --data-raw $'------WebKitFormBoundaryEsUJBnHCya0lYGPx\r\nContent-Disposition: form-data; name="body"; filename="blob"\r\nContent-Type: application/json\r\n\r\n{"title":"dsad","description":"adsadsa","isin":"ecf66d3a-f67c-451b-86ad-47d72c271c73","date":"2024-01-04","existingDocumentIds":[],"options":[]}\r\n------WebKitFormBoundaryEsUJBnHCya0lYGPx--\r\n' \
  --compressed
but just get the below error when i run
Copy code
proxyTrackingFormBody(request)
Copy code
{
  "message": "Missing/invalid parameters",
  "params": [
    {
      "name": "proxyTracking",
      "type": "form",
      "datatype": "object",
      "required": true,
      "reason": "Missing"
    }
  ]
}
The multipart all looks fine, content disposition etc all looks fine so I'm at a bit of a loss.
d
Have you set the prerequest validation mode? If you don't set it to IgnoreBody then the binary will be consumed in the validation process. https://www.http4k.org/faq/#openapi_contracts
m
Yup that is set. I was already using the end point for multiparts before (but just had lots of strings etc. rather than using the
.auto
) so it should be setup correctly. I'll see if I can put together a little project to replicate it
Did some digging and apparently by having the
filename="blob"
that breaks it, if I remove it then it works. Feels like that should be ignored either way considering it's a
MultipartFormField
?
Managed to hack my way around it on the client for now! A side question, there's currently no way to expose the
PostPutProxyTrackingRequestDTO
to the swagger is there? I can't see a place to put an example which would allow it to generate. As a workaround I have an empty endpoint, but feels like there must be better?