mattpolzin / OpenAPIKit

Codable Swift OpenAPI implementation.
MIT License
276 stars 35 forks source link

Support for binary content - OpenAPI v3.1 #355

Closed tib closed 5 months ago

tib commented 5 months ago

Hello,

based on the OpenAPI 3.1 migration guide, this is how users could describe binaries:

OpenAPI v3.0:

requestBody:
  content:
    application/octet-stream:
      schema:
        type: string
        format: binary

OpenAPI v3.1:

requestBody:
  content:
    application/octet-stream: {}

My question: is it possible te describe the {} somehow using the OpenAPIKit library? I had no luck so far, there is no .binary JSONSchema / content. I'm not sure how to overcome this issue. Is this feature even supported, or am I missing something? 🤔

Many thanks. 🙏 Tib

mattpolzin commented 5 months ago

Yes, this is still possible to represent. For OAS 3.1, use contentType: .binary instead of format: .binary but otherwise the same (still a string schema).

tib commented 5 months ago

Many thanks for the help, actually it is called contentEncoding and the output is:

requestBody:
  description: Upload request body
  content:
    application/pdf:
      schema:
        type: string
        contentEncoding: binary

This is the Swift code I used to generate the yaml snippet:

OpenAPI.Request(
    description: description,
    content: [
        contentType: .init(
            schema: .string(
                contentEncoding: .binary
            )
        )
    ],
    required: true
)

Many thanks for the help, I'll close this issue now. 👍

mattpolzin commented 5 months ago

Woops, I botched the description but you found the answer anyway. Thanks for the correction.