All Projects → mulesoft-labs → node-raml-validate

mulesoft-labs / node-raml-validate

Licence: other
Strict validation of RAML parameters in JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-raml-validate

api-console-cli
A CLI tools for the API console.
Stars: ✭ 14 (-22.22%)
Mutual labels:  raml, raml-tooling
raml-sublime-plugin
Syntax highlighter for the RESTful API Modeling Language
Stars: ✭ 49 (+172.22%)
Mutual labels:  raml, raml-tooling
raml-typesystem
(deprecated) Typescript implementation of RAML type system
Stars: ✭ 15 (-16.67%)
Mutual labels:  raml, raml-tooling
raml-javascript-generator
Generate a JavaScript API client from RAML
Stars: ✭ 30 (+66.67%)
Mutual labels:  raml, raml-tooling
raml-java-client-generator
Raml Java Client Generator
Stars: ✭ 32 (+77.78%)
Mutual labels:  raml, raml-tooling
raml-dotnet-parser-2
No description or website provided.
Stars: ✭ 17 (-5.56%)
Mutual labels:  raml, raml-tooling
oas-raml-converter
(DEPRECATED) Converts between OAS and RAML API specifications
Stars: ✭ 75 (+316.67%)
Mutual labels:  raml, raml-tooling
raml2obj
RAML to object.
Stars: ✭ 23 (+27.78%)
Mutual labels:  raml, raml-tooling
osprey-method-handler
Middleware for validating requests and responses based on a RAML method object
Stars: ✭ 14 (-22.22%)
Mutual labels:  raml, raml-tooling
Ramlfications
Python parser for RAML
Stars: ✭ 234 (+1200%)
Mutual labels:  raml
Api Workbench
The API Workbench for RAML (deprecated)
Stars: ✭ 222 (+1133.33%)
Mutual labels:  raml
Raml Js Parser
(deprecated) A RAML parser based on PyYAML written in CoffeScript and available for use as NodeJs module or in-browser.
Stars: ✭ 197 (+994.44%)
Mutual labels:  raml
symfony-skeleton
Skeleton rest-api based on symfony
Stars: ✭ 15 (-16.67%)
Mutual labels:  raml
core
This repo contains the core module of the OCF API's.
Stars: ✭ 20 (+11.11%)
Mutual labels:  raml
Raml Dotnet Tools
Visual Studio extension to work with RAML and OAS (OpenAPI) specifications. You can consume REST APIs, scaffold ASP.NET implementations and extract RAML specifications from existing ASP.Net apps.
Stars: ✭ 171 (+850%)
Mutual labels:  raml
Raml Java Parser
(deprecated) A RAML parser based on SnakeYAML written in Java
Stars: ✭ 169 (+838.89%)
Mutual labels:  raml
generaptr
Generaptr is a node package that helps when starting up a project by generating boilerplate code for Express api.
Stars: ✭ 16 (-11.11%)
Mutual labels:  raml
home
This is the home page for the API specification toolbox.
Stars: ✭ 16 (-11.11%)
Mutual labels:  raml
raml-clj-parser
A RAML parser implemented in clojure
Stars: ✭ 21 (+16.67%)
Mutual labels:  raml
ramlev
Validate/Verify examples in RAML
Stars: ✭ 30 (+66.67%)
Mutual labels:  raml

RAML Validate

NPM version Build status Test coverage Greenkeeper badge

Strict and pluginable validation of RAML 0.8 named parameters and RAML 1.0 built-in types.

Installation

npm install raml-validate --save

Usage

You must require the module and call it as a function to get a validation instance back.

var validate = require('raml-validate')();

// RAML version to use, either 'RAML10' or 'RAML08' (default)
var RAMLVersion = 'RAML10'

// Create a user model schema.
var user = validate({
  username: {
    type: 'string',
    minLength: 5,
    maxLength: 50,
    required: true
  },
  password: {
    type: 'string',
    minLength: 5,
    maxLength: 50,
    required: true
  }
}, RAMLVersion);

// Validate a user model.
user({
  username: 'blakeembrey',
  password: 'super secret password'
}); //=> { valid: true, errors: [] }

Module does not currently support wild-card parameters (RAML 0.8) and regular expression patterns in property declaration (RAML 1.0)

Getting validation errors

All validation errors can be retrieved from the errors property on the returned object. If valid === false, the errors will be set to an array. This can be useful for generating error messages for the client.

[
  {
    valid: false,
    key: 'password',
    value: 'test',
    rule: 'minLength',
    attr: 5
  }
]

Required validation

If the validation does not set required to be true, a null or undefined value will be valid.

Union types (RAML 1.0 only)

The module supports the 'union' type as defined in datatype-expansion's algorithm.

validate({
  userId: {
    type: 'union',
    anyOf: [
      { type: 'string' },
      {
        type: 'integer',
        maximum: 100
      }
    ]
  }
});

Repeated validation (RAML 0.8 only)

The module has core support for repeated properties in the form of an array. If the validation is set to repeat, but does not receive an array - validation will fail with a repeat error.

Multiple types (RAML 0.8 only)

The module supports multiple types according to the RAML spec (see RAML 0.8 named parameters with multiple types. When multiple types are specified, it'll run the validation against the matching type.

validate({
  file: [{
    type: 'string'
  }, {
    type: 'file'
  }]
});

If any of the types are set to repeat, it'll only run that validation object when every value in the array is of the correct type - otherwise you will receive a type error.

Adding new types (RAML 0.8 only)

New type validations can be added by setting the corresponding property on the validate.TYPES object. For example, adding file validation to support buffers can be added by doing:

validate.TYPES.file = function (value) {
  return Buffer.isBuffer(value);
};

The function must accept the value as the first parameter and return a boolean depending on success or failure.

Adding new rules (RAML 0.8 only)

New rules can be added by setting the corresponding property on the validate.RULES object. For example, to add file size support we can do the following:

validate.RULES.minFileSize = function (size) {
  return function (value) {
    return value.length <= size;
  };
};

The function must accept the validation value as its only parameter and is expected to return another function that implements the validation logic. The returned function must accept the value as the first argument, and can optionally accept the key and model as the second and third arguments. This is useful for implementing a rule such as requires, where both parameters may be optional; however, when set, depend on eachother being set.

validate.RULES.requires = function (property) {
  return function (value, key, object) {
    return value != null && object[property] != null;
  };
};

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].