Forum Discussion

mhiggins's avatar
3 years ago

Conditional json path for custom rule - help please

I need some help creating a SwaggerHub Custom Standardization Rule. 

I am looking to do the following: For every path/method that has a 200 response, I want to make sure it has a content tag in the response. 

This does not apply to any other responses and if the path/method has no 200 - then no errors should be raised. 

So something like:

  • path: $.paths.*.*.responses  <-- (only if = 200)
  • regex: /content/

Many thanks !!

1 Reply

  • Hi mhiggins!

     

    Here's a rule I wrote that does this. Instead of using a regex-based rule, I was able to implement this functionality using the "Path Exists" check box in the custom rule creation.

     

    name: 200 Resp Code must have content tag

    openapi version: all

    path exists: yes

    path: $.paths.[*].responses.[200].content

     

     

    Hope this helps!