Skip to content

Validating examples? #153

@liamnichols

Description

@liamnichols

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions