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

Response without schema #71

Open juliangehring opened 1 year ago

juliangehring commented 1 year ago

Is it possible to define a response that has no schema, e.g. for return an error?

Currently, the schema needs to be set, for example like

responses: {
    '415': {
        description: 'Not supported',
        schema: {}
    }
}

which renders an empty json object in the schema on the documentation page.

Omitting the schema or setting it to null fails with

Uncaught TypeError: Cannot read properties of undefined (reading 'generated') at worker.js:268:20 in getType at worker.js:265:126 in x at worker.js:327:5 in j at worker.js:442:20 in getParsedSchema at worker.js:393:21 at worker.js:709:8

It would be nice if one could represent that nothing gets returned.

ghost commented 1 year ago

I tried exactly the example you've given without seeing the error you have.

Using current release 0.1.10.

juliangehring commented 1 year ago

The code with an empty schema (schema: {}) does not throw an error - however, it renders an empty json object in the schema on the documentation page. This is what I would like to avoid, for responses that don't return an object.

The error occurs when trying to omit schema, either by a) setting schema to null: schema: null or b) omitting schema completely:

responses: {
    '415': {
        description: 'Not supported'
    }
}

which yields the Uncaught TypeError: Cannot read properties of undefined (reading 'generated')

ghost commented 1 year ago

Yes I did observe that error when schema is missing.

A curious thing given everything in ResponseSchema is supposedly optional.

The same issue would apply when returning 204 No Content for a delete action which cannot contain content.

juliangehring commented 1 year ago

Thanks for confirming. I agree that it would be good to avoid the error when schema is missing.

If there are other ways to skip the schema, I would be open to ideas.