cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
275 stars 38 forks source link

Non-JSON request body causes error #64

Closed rstml closed 1 year ago

rstml commented 1 year ago

It seems that the router tries to parse and validate non-JSON request body and fails.

Example route:

export class ExampleRoute extends OpenAPIRoute {
    static schema = {
        // ...
        requestBody: {
            contentType: 'application/octet-stream'
        },
        // ...
    }
}

Error response:

{
  "errors": {
    "body": "Unexpected token 'R', \"Received: \"... is not valid JSON"
  },
  "success": false,
  "result": {}
}

The only way to avoid this is not to specify requestBody at all. In that case, however, /docs gets broken and doesn't allow to submit file as a request body.

G4brym commented 1 year ago

Hey @rstml i've published a new version (v0.1.10) that fixes this issue