GithubHelp home page GithubHelp logo

loissotolopez / ndto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nomasystems/ndto

0.0 0.0 0.0 753 KB

:white_check_mark: An Erlang library for DTOs validation.

Home Page: https://nomasystems.github.io/ndto/

License: Apache License 2.0

Python 0.08% Erlang 99.92%

ndto's Introduction

ndto

CI Docs

ndto is an Erlang library for generating DTO (Data Transfer Object) validation modules from schemas.

Motivation

Validating incoming data is a critical step to ensure the integrity, consistency, and security of your application's data flow. However, writing custom validation logic for each DTO can quickly become a time-consuming and error-prone task.

With ndto, you can define validation schemas that describe the structure and constraints of your data. These schemas are then used to automatically generate validation modules, reducing development time and avoiding human-induced errors in the validation step.

Quickstart

  1. Add ndto as a dependency in your rebar.config file:
{deps, [
    {ndto, {git, "https://github.com/nomasystems/ndto.git", {branch, "main"}}}
]}.
  1. Define an ndto schema.
Schema = #{
    type => string,
    min_length => 8,
    pattern => <<"^hello">>
}.
  1. Generate a module using the ndto:generate/2 function.
DTO = ndto:generate(string_schema, Schema).
  1. Load the generated module on the fly.
ok = ndto:load(DTO).
  1. Call the is_valid/1 function from the generated module to validate your data.
true = string_schema:is_valid(<<"hello world">>).
{false, _MinLengthError} = string_schema:is_valid(<<"hello">>).
{false, _PatternError} = string_schema:is_valid(<<"hi world">>).

ndto schema language

Schemas are built according to the ndto:schema() type.

%%% ndto.erl
-type schema() ::
    empty_schema()
    | universal_schema()
    | ref_schema()
    | enum_schema()
    | boolean_schema()
    | integer_schema()
    | float_schema()
    | string_schema()
    | array_schema()
    | object_schema()
    | union_schema()
    | intersection_schema()
    | complement_schema()
    | symmetric_difference_schema().

Check the docs for an up-to-date version of the type specifications.

Contributing

We โค๏ธ contributions! Please feel free to submit issues, create pull requests or just spread the word about ndto in the open-source community. Don't forget to check out our contribution guidelines to ensure smooth collaboration! ๐Ÿš€

Support

If you need help or have any questions, please don't hesitate to open an issue or contact the maintainers directly.

License

ndto is released under the Apache 2.0 License. For more information, please see the LICENSE file.

This project uses OpenAPI specification (OAS) schemas and examples, which are licensed under the Apache 2.0 license. See the associated LICENSE file for more information.

ndto's People

Contributors

javiergarea avatar loissotolopez avatar

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.