samchungy / eslint-plugin-zod-openapi

Eslint rules for zod-openapi
MIT License
4 stars 0 forks source link

Error on objects #119

Open zAlweNy26 opened 5 months ago

zAlweNy26 commented 5 months ago

Hi, I don't know if it's the right thing to do or not, but I think this plugin should not throw an error to every key of a zod object if the object itself has the .openapi method declared. For example: image This should not occur in my opinion. Let me know what you think!

samchungy commented 5 months ago

Hey there! Thanks for using the plugin! I wasn't sure anyone was using this apart from my teams internally.

The idea behind this rule is to ensure mostly that all fields have a description, but the easiest way to do that is by enforcing firstly that .openapi is added to all fields. I'm not sure what renderer you normally use but on redoc it can be quite ugly when a description is missing. Eg.

image
zAlweNy26 commented 5 months ago

Hi, thanks for the response. I'm using this plugin in combination with zod-openapi, fastify-zod-openapi, @fastify/swagger and @fastify/swagger-ui. I was just wondering if it would make sense to have the .openapi method both on the object and its properties. In my opinion, the plugin should check and throw an error only if both don't have one. For example:

Tell me what you think, I don't think it would break any current setup you or others have.

samchungy commented 5 months ago

I think it would have to be a configurable option, as we currently use it to ensure every field has an .openapi field. Including objects and their lower fields

zAlweNy26 commented 5 months ago

Yeah I agree