Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Ignore exception for specific instance #146

Closed MattIPv4 closed 1 year ago

MattIPv4 commented 1 year ago

👋 I'm wondering if it'd be possible to specify an exception code to be skipped in one specific instance?

For my specific case, I'm defining requestBody on a DELETE endpoint (which the HTTP spec does permit, but OAS does not), and as such, I'd like to skip EDEV001 for this one specific instance but I don't want to ignore all invalid properties throughout the entire spec.

Gi60s commented 1 year ago

This is something I've been working into version 2 and I can look into what it would take to add it to the current version.

I think the best way to do this for a specific instance would be to include an extension property that defines the error to skip. So if you added a property like x-enforcer-skip-codes: EDEV001 to the OpenAPI document itself next to where the error occurs. What do you think, does it make sense to do it that way or do you maybe have another idea of how it could work?

MattIPv4 commented 1 year ago

Yah, adding a custom property at the right point makes sense to me (similar to linting disable comments for a lot of other linters).

The only other alternative I had thought about was providing a string path to the property in the config (similar to how the error gets output), but that seems fragile for you to process.

Gi60s commented 1 year ago

I've added this functionality to version 1.22.0 and I've published it to npm.

To use it, find the component that the error is part of (in your case the path item object) and add the extension x-enforcer-exception-skip-codes: EDEV001. You can specify multiple codes by separating them with a space.

Enjoy!

MattIPv4 commented 1 year ago

Thank you very much, working perfectly 💙