Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating examples? #153

Open
liamnichols opened this issue Aug 15, 2023 · 0 comments
Open

Validating examples? #153

liamnichols opened this issue Aug 15, 2023 · 0 comments

Comments

@liamnichols
Copy link

Hello! Firstly, thanks for such a useful tool! We've been using openapi_parser for a long time now via committee and it's helped us significantly 🙌

I was recently looking at our schema document and had been trying to think of solutions to improve the quality of our example values on media types and schemas. I noticed that in some (many) cases, we had forgotten to update them which means that we had been showing invalid examples in generated documentation.

It made me wonder if it would be possible to use this library to validate our example objects since we can already validate other responses. I had an idea that we could maybe introduce methods such as OpenAPIParser::Schemas:Schema#validate_example! to validate the example.

While I didn't test it, I think that it could be implemented like this:

def validate_example(options) do 
  return unless example
  OpenAPIParser::SchemaValidator.validate(example, self, options)
end

The other part to this would also be to have a way to iterate over all media types and schemas in the document, this is where I am a bit stuck.

Before I looked further into it, I wanted to get your opinion on such feature. I'm happy to attempt to implement it, but some general guidance on the approach would be much appreciated.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant