kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
895 stars 237 forks source link

openapi framework throws uncaught error if an operation for api is not present #722

Closed mhamann closed 2 years ago

mhamann commented 3 years ago

When an operation is defined in the OpenAPI spec, but doesn't have a matching function identified in the openapi-framework, the server crashes on startup because it tries to access an undefined property on the route item. Specifically here https://github.com/kogosoftwarellc/open-api/blob/master/packages/openapi-framework/index.ts#L358

image

It would be preferable to simply ignore the error and either just not process requests to that operation or return a 501 Not Implemented.

jsdevel commented 3 years ago

@mhamann please submit a PR to fix this.

ncodernet commented 2 years ago

Hello @jsdevel : I also suffer from this problem and try to probide a fix: It would be nice to be able to use openapi-framework without an implementation, e.g. to implement generic request validation. Looking a the code it seem to have worked in the past, as "routeItem.operations" rather looks like a typo. However I'm not sure with the role of "operationDoc" - which would become undefined in this case. Is this intended? It would be great if you could have a closer look and my PR and see it if makes sense at all. When I have execute the tests, one was failing that explicitly expected an exception in case of a missing operation. Maybe this test could become obsolete?

Thanks, Reiner.

ncodernet commented 2 years ago

I have jsut seem that also in case of operationDoc would be correctly filled with pathDoc[methodName] which seems to be correct. However I'm not sure if there are some corner cases that should be considered. I have also removed the "throws" check in the tests - now all tests are succeeding for me.