flipstone / json-fleece

Extensible JSON Schemas for Haskell
MIT License
2 stars 1 forks source link

Support for schemas with OpenAPI 3 validators #40

Closed jlavelle closed 2 months ago

jlavelle commented 2 months ago

The new Validator associated type and FleeceValidator superclass constraint on the Fleece class allow extensions to validation beyond lifting Haskell functions.

I added a class called OpenApi3Validator to the json-fleece-openapi3 package that captures most of the OpenAPI 3 validations. Fleece instances can implement the OpenApi3Validator class on their associated Validator type to gain access to static information associated with the validations.

The intent is that downstream users will leverage the additional information to generate richer OpenAPI schemas based on their Fleece schemas.

There is a new constraint called FleeceOpenApi3 that includes the OpenApi3Validator constraint on the Fleece instance's Validator. It is exported by the json-fleece-openapi3 package, along with associated schemas that use the constraint.

The schemas serve as a drop-in replacement for those in Fleece.Core.Schemas. They use the methods on OpenApi3Validator to implement their validations.

I didn't add support for the pattern validation because I don't have good sense of what regex library to use.

jlavelle commented 2 months ago

I'm going to close this and make a new PR with just the changes to json-fleece-core for now.