Giter Club home page Giter Club logo

Comments (4)

llfbandit avatar llfbandit commented on June 16, 2024

Hi,

There is no way to access core validators.
I suggest to declare a new keyword (x-date for example) in your Document Description for your specific needs then format keyword can be processed normally.

from openapi4j.

smhc avatar smhc commented on June 16, 2024

Unfortunately I have no control over the spec files. Although I could iterate the parsed schema and modify it in memory to add the extensions.

I think supporting custom formats without spec modification is desirable. The spec supports custom formats - so validating the added custom formats in addition to the standard ones will be a common use case. Validating keywords other than 'format' will also likely want to fall back to the 'stock' validator after performing the overloaded operation. (e.g I will want to trap all 'type' keywords, but I would prefer to not re-implement the typevalidator).

Can the 'validate' function of the custom validator simply return a boolean which indicates whether openapi4j should proceed onto the core validator after processing?

I can imagine you may want a 'preValidate' and 'postValidate' hook as well(?). The validation hooks are what differentiate openapi4j from other validators so it would be good to make them powerful. But at the least - a boolean which controls the chaining to the core validator would be sufficient.

from openapi4j.

llfbandit avatar llfbandit commented on June 16, 2024

I implemented a chaining behaviour for validators.
Now validate method returns a boolean to break or continue the chain.
You can have a look at the updated README.md for further info.

Are you able to validate this in latest 0.8-SNAPSHOT?
Thanks

from openapi4j.

smhc avatar smhc commented on June 16, 2024

Thanks for the changes. I gave them a quick test and it appears to be working.

Another approach could be to pass the next validator in the chain to the validation function as a parameter. The custom validation function can then choose to call the next one or not. It would allow it to post process the validation results, e.g strip out certain errors from core validators. It does put the onus on the custom function to chain correctly however.

But the boolean return approach is likely to be adequate 90% of the time.

from openapi4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.