ozonep / openapi-fastify-codegen

Server Generator based on OpenAPIv3 spec file
MIT License
7 stars 1 forks source link

TypeError: Cannot read property 'put' of undefined #12

Open simenfossnes opened 4 years ago

simenfossnes commented 4 years ago

Getting the following error: TypeError: Cannot read property 'put' of undefined from one of the route files.

Put is the first endpoint of that route file, but deactivating this one and attempting to run again now throws an error on the second endpoint (the post endpoint). For some reason, it seems like "fastify" for some reason is undefined. Not quite sure why.

simenfossnes commented 4 years ago

Hmm, it seems like the type error is caused by the schema.json file not including the resource used in that particular route. This indicates that there's an issue with generating the schema.json file. I note that this particular data model was the most extensive and nested one.

simenfossnes commented 4 years ago

Another relevant finding is that the OAS file contains circular references.

This was discovered by running it through the online demo of the npm package swagger-parser, resulting in this meesage: This API is valid, but it cannot be shown because it contains circular references.

simenfossnes commented 4 years ago

Yep, seems like the circular reference is the issue. After removing it, the code generator generated the schema.json file perfectly. So finding a way to deal with circular references would resolve future issues like this one.