Giter VIP home page Giter VIP logo

azutoolkit / schema Goto Github PK

View Code? Open in Web Editor NEW
32.0 3.0 4.0 143 KB

Schemas come to solve a simple problem. Sometimes we would like to have type-safe guarantee params when parsing HTTP parameters or Hash(String, String) for a request moreover; Schemas is to resolve precisely this problem with the added benefit of performing business rules validation to have the params adhere to a "business schema."

License: MIT License

Crystal 100.00%
schema-validations validation json predicates parsing http-params parameters typesafe

schema's People

Contributors

actions-user avatar alex-lairan avatar codacy-badger avatar cyangle avatar eliasjpr avatar github-actions[bot] avatar jackturnbull avatar m-o-e avatar westonganger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

schema's Issues

Multi-word PascalCase naming does not seem to work

Source:

class User::Controller < ApplicationController
  def create
    CreateForm.new(params.raw_params.to_h)
  end

  schema CreateForm do
    param email : String, match: /\w+@\w+\.\w{2,3}/, message: "Email must be valid!"
  end
end

Compiler:

instantiating 'User::Controller#create()'
in src/modules/user/controller.cr:3: undefined constant CreateForm (did you mean 'Createform')

    CreateForm.new(params.raw_params.to_h)
    ^~~~~~~~~~

make: *** [build] Error 1

Schema::Validator is not flexible

I don't think Schema::Validator is flexible because you can not pass data to it before validating records.

Most other validation libraries store instances of validator classes in the model so that you can pass additional data to it during initialization to customize it's behavior.

Comparison to Amber Params

Apologies if I've missed the point of this module but I really like the format - I'd been toying with writing my own JSON Schema validator and then stumbled upon this. It may be a bit of a direct question but as a new user checking out this library, what advantages does this have over using the Amber Params module directly?

Some of the higher level ones I can see:

  • Less coupled to the Amber controller
  • Predicates without patching base types
  • Ability to inspect whole record on each validation

The hope would be to be able to create a set of schemas for each Amber controller and have the schema manage it's own validations without having to rely on the in-built param predicate runner. Is this a valid use case in your eyes?

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.