codekie / openapi-examples-validator

Validates embedded examples in OpenAPI-files
MIT License
57 stars 11 forks source link

Support example for proper json MIME types #190

Closed bartoszm closed 1 year ago

bartoszm commented 1 year ago

Currently only examples under application/json are supported. However a proper json payload can be indicated by e.g. application/json;charset=utf-8, application/vnd.some.model+json. Both examples provided confirm to MIME grammar (https://en.wikipedia.org/wiki/Media_type).

I thought simple improvement of a pattern could help. Like: $..responses..content[?(@property.match(/[\/+]json/))].example. However, it works only partially due to the how jsonpath-plus parser works internally - in short it uses ; as fragment separator. So I could identify all examples with improved json-path but then identification of elements would not work.

Switching to json pointers could be a way forward.

codekie commented 1 year ago

I'm open to suggestions as long everything else works as well as before. I also rather stick to "works as designed" as to partial solutions. If you manage to find a solid holistic solution, I'm up for it 👍

bartoszm commented 1 year ago

I agree solving it partially is not a solution - will try to propose a holistic solution

bartoszm commented 1 year ago

Please take a look at the PR. I think I found a solution. There is also a question of whether encode / decode example name methods are needed any longer. Please let me know what you think.