astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content type with `charset` not supported

govizlora opened this issue · comments

Hi, thank you for making the tool!

In my first try to convert my OpenAPI spec, it fails to parse the below content

"requestBody": {
  "content": {
    "application/json;charset=UTF-8": {
      "schema": {
        "$ref": "#/components/schemas/Foo"
      }
    }
  },
}

After comparing with your input example, I replaced application/json;charset=UTF-8 to application/json, and now it works perfectly.

Would be nice if it can support the content with charset specified, or at least throw an error to prompt the user to remove the charset part.

hey, that's what the isMediaTypeAllowed option is for

let isMediaTypeAllowed = (mediaType: string) => mediaType === "application/json";
if (options?.isMediaTypeAllowed) {
isMediaTypeAllowed =
typeof options.isMediaTypeAllowed === "string"
? (mediaType: string) => sync(options.isMediaTypeAllowed, { mediaType }, { functions: true })
: options.isMediaTypeAllowed;

also available as a CLI arg
--media-type-expr Pass an expression to determine which response content should be allowed