aaronpowell / azure-functions-nodejs-openapi

MIT License
24 stars 4 forks source link

CORS headers for swagger endpoint #14

Open VonLatvala opened 1 year ago

VonLatvala commented 1 year ago

In https://github.com/aaronpowell/azure-functions-nodejs-openapi/blob/main/src/openAPIv3.ts#L29 (generateOpenApiSpec), the whole context.res is getting overwritten with an object containing only the response body. This makes it impossible to prepare custom response headers (for example CORS) by wrapping the function in another higher level function.

I propose that generateOpenApiSpec surgically inserts the response body instead of nuking the whole response object.

Another solution could be to accept an option which sets CORS headers as requested, but this is less flexible.

aaronpowell commented 1 year ago

It'd probably be better if the line was context.res = { ...context.res, body }, so it added the body to the existing one.

Feel free to submit a PR, otherwise I'll get to it when I have some time.