huma icon indicating copy to clipboard operation
huma copied to clipboard

requestBody.content.multipart/form-data.schema.properties.<file>.contentEncoding (and contentMediaType) is not valid OS3.0

Open NPellet opened this issue 3 months ago • 6 comments

Those two fields (contentEncoding and contentMediaType) are not in the OS 3.0 spec, though they are in the OS 3.1 spec.

Our generator only supports 3.0, so it fails there. I will investigate what a fix would take.

NPellet avatar Nov 18 '25 17:11 NPellet

Content encoding is added here https://github.com/danielgtaylor/huma/blob/main/formdata.go#L241

NPellet avatar Nov 18 '25 17:11 NPellet

contentMediaType is added here https://github.com/danielgtaylor/huma/blob/c7a8a7965d84e4aded17671da32bea8c69e4201e/schema.go#L168

NPellet avatar Nov 18 '25 17:11 NPellet

I see there's downgrade code already

https://github.com/danielgtaylor/huma/blob/c7a8a7965d84e4aded17671da32bea8c69e4201e/openapi.go#L1624-L1639

NPellet avatar Nov 18 '25 17:11 NPellet

Here's our schema

      requestBody:
        content:
          multipart/form-data:
            encoding:
              Data:
                contentType: text/plain
              file:
                contentType: text/plain
            schema:
              properties:
                Data:
                  $ref: "#/components/schemas/CertificateImportData"
                file:
                  contentEncoding: binary
                  contentMediaType: application/octet-stream
                  format: binary
                  type: string
              required:
                - file
              type: object

NPellet avatar Nov 18 '25 17:11 NPellet

Ok this is indeed not 3.0.3 valid, and it's under the SchemaObject specification:

https://spec.openapis.org/oas/v3.0.3#schema-object

In general (not just for requestBody or for multipart encoding), those 2 properties are not allowed in OS 3.0.3

NPellet avatar Nov 18 '25 17:11 NPellet

I would propose something like https://github.com/danielgtaylor/huma/pull/919

NPellet avatar Nov 18 '25 17:11 NPellet