{"id":19989592,"url":"https://github.com/wavesoft/raml-validator-loader","last_synced_at":"2026-06-09T03:03:22.626Z","repository":{"id":66876157,"uuid":"72664064","full_name":"wavesoft/raml-validator-loader","owner":"wavesoft","description":"A webpack plugin that converts RAML rules into pure javascript-only validation routines","archived":false,"fork":false,"pushed_at":"2017-01-23T15:51:27.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T20:02:12.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wavesoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-02T17:24:42.000Z","updated_at":"2017-01-11T14:21:57.000Z","dependencies_parsed_at":"2023-03-11T00:25:06.179Z","dependency_job_id":null,"html_url":"https://github.com/wavesoft/raml-validator-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wavesoft/raml-validator-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoft%2Framl-validator-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoft%2Framl-validator-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoft%2Framl-validator-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoft%2Framl-validator-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wavesoft","download_url":"https://codeload.github.com/wavesoft/raml-validator-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavesoft%2Framl-validator-loader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34089329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T04:48:34.492Z","updated_at":"2026-06-09T03:03:22.469Z","avatar_url":"https://github.com/wavesoft.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# raml-validator-loader [![Velocity](http://jenkins.mesosphere.com/buildStatus/icon?job=raml-validator-loader-master)](http://jenkins.mesosphere.com/view/DCOS%20UI/job/raml-validator-loader-master/)\n\nA webpack plugin that converts RAML rules into pure javascript-only validation routines\n\n## Usage\n\n```js\nimport TypeValidators from './ramls/myTypes.raml';\n\n// The raml-validator-loader will convert the RAML document into an object with\n// a validation function for every type defined in your RAML.\n\nvar userInput = read_user_input();\nvar validationErrors = TypeValidators.MyType(userInput);\n\n// Display errors\nvalidationErrors.forEach((error) =\u003e {\n  console.log('Error message: /' + error.path.join('/'));\n  console.log('  Error path : ' + error.message);\n});\n\n```\n\n### Customizing validator\n\nIt is possible to customize the validator instance in order for example to provide custom error messages:\n\n```js\nimport TypeValidators from './ramls/myTypes.raml';\n\n/**\n * You can clone the default validator instance and customize it\n */\nconst CustomTypeValidators = TypeValidators.clone({\n\t'errorMessages': {\n\t\t// You can provide a string override\n\t\tTYPE_NOT_OBJECT: 'Expecting an object here',\n\n\t\t// Or a function override if you want more control over\n\t\t// the error message\n\t\tSTRING_PATTERN: (templateVars, path) =\u003e {\n\t\t\tif (path[0] == 'name') {\n\t\t\t\treturn 'Name must only contain letters';\n\t\t\t}\n\n\t\t\treturn `Must match '${templateVars.pattern}'`;\n\t\t}\n\t}\n});\n```\n\n## Installation\n\nFirst install the module\n\n```\nnpm install --save-dev raml-validator-loader\n```\n\nAnd then use it in your `webpack.config.js` like so:\n\n```js\n    module: {\n        loaders: [\n            { test: /\\.raml$/, loader: \"raml-validator-loader\" }\n        ]\n    }\n```\n\n## API Reference\n\nWhen you are importing a `.raml` document you will end-up loading an instance of a `RAMLValidator` class and all the RAML types are exposed as instance property functions.\n\n```js\nimport TypeValidators from './ramls/myTypes.raml';\n```\n\n### `RAMLValidator` Class\n\nA default instance of `RAMLValidator` class is returned when importing a RAML file. You don't have access to it's constructor directly.\n\n#### Function `.clone([config])`\n\nCreates a new instance of `RAMLValidator` allowing further customisations to the configuration. Parameters not overriden through the configuration will be kept intact.\n\n```js\nconst CustomValidator = TypeValidators.clone({\n\terrorMessages: { ... }\n});\n```\n\n##### Parameters\n\n- **config** - [Optional] An object with the new configuration parameters to pass down to the new validator instance. Accepts the following properties:\n\t- `errorMessages` : An object with custom error messages. The value to the error message can either be a string, or a function with the following signature: `(messageVariables, path)` that returns an error string. For the full list of error messages you can refer to the end of this documentation.\n\n##### Returns\n\n- **RAMLValidator** - Returns a new `RAMLValidator` instance\n\n#### Function `.\u003cTypeName\u003e(input)`\n\nFor each type in the RAML document, a validation function will be created with the above signature. You can call this function, passing it the data you want to validate and it will return an array with the errors found in it.\n\n```js\nconst errors = TypeValidators.SomeRAMLType(userData);\nif (errors.length \u003e 0) {\n\tthrow new TypeError('You must provide some valid data');\n}\n```\n\n##### Parameters\n\n- **input** - The data to validate. Can be anything\n\n##### Returns\n\n- **[RAMLError]** - Returns an array of `RAMLError` instances, one for every error encountered in the input data.\n\n\n```js\nmodule.exports = {\n\n  /**\n   * For every type in the RAML document, an equivalent validation function\n   * will be generated by the loader.\n   */\n  RamlTypeName: function( validatorInput ) {\n\n    ...\n\n    // Each validation function will return an array of RAMLError objects\n    // with the information for the validation errors occured.\n    return [ RAMLError() ];\n  },\n\n}\n```\n\n### `RAMLError` Class\n\nThis class is instantiated by the type validator function and it contains the information to locate and describe an error in the type.\n\n```js\nconst errors = TypeValidators.SomeRAMLType(userData);\nif (errors.length \u003e 0) {\n\tconst error = errors[0];\n\tconsole.log('Error path = ', error.path);\n\tconsole.log('Error message = ', error.message);\n}\n```\n\n#### Property `.path`\n\n- **Array** - Returns the path in the object where the validation error ocurred, as an array of path components. For example: `['objects', 0, 'name']`\n\n#### Property `.type`\n\n- **String** - Returns the type of the error as a string. For example `\"PROP_IS_MISSING\"`\n\n#### Property `.variables`\n\n- **Object** - Returns an object with the template variable values for the error message. For example `{value: 2}` for the `ITEMS_MAX` error type, in order to be able to compose the dynamic result of `\"Must contain at most 2 items in the array\"`.\n\n#### Property `.message`\n\n- **String** - Returns the human-readable description of the error. For example: `Missing property 'name'`.\n\n### Error Messages\n\nThe following error messages are used by the RAML validator. You can override them using the `.clone({errorMessages: ...})` function.\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eError Type\u003c/th\u003e\n        \u003cth\u003eDefault Value\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eENUM\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be one of {{values}}\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eITEMS_MAX\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain at most {{value}} items in the array\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eITEMS_MIN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain at least {{value}} items in the array\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eITEMS_UNIQUE\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain only unique items\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eLENGTH_MAX\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be at most {{value}} characters long\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eLENGTH_MIN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be at least {{value}} characters long\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eNUMBER_MAX\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be smaller than or equal to {{value}}\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eNUMBER_MIN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be bigger than or equal to {{value}}\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eNUMBER_MULTIPLEOF\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be multiple of {{value}}\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eNUMBER_TYPE\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be of type `{{type}}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROPS_MAX\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain at most {{value}} properties\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROPS_MIN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain at least {{value}} properties\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROP_ADDITIONAL_PROPS\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eContains extraneous property `{{name}}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROP_IS_MISSING\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be defined\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROP_MISSING\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust define property `{{name}}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003ePROP_MISSING_MATCH\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust contain a property that matches `{{pattern}}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eSTRING_PATTERN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust match the pattern `{{pattern}}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_ARRAY\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be an array\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_BOOLEAN\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be a boolean value\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_DATETIME\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be a date/time string\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_INTEGER\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be an integer number\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_NULL\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be null\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_NUMBER\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be a number\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_OBJECT\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be an object\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003ccode\u003eTYPE_NOT_STRING\u003c/code\u003e\u003c/td\u003e\n        \u003ctd\u003eMust be a string\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Function Overrides\n\nIf you want more control over the error message, you can use a function instead of string for the error message. The parameters passed to the function are the `messageVariables` that provide some contextualization to the error message, and the `path` of the error.\n\nFor example:\n\n```js\nconst CustomTypeValidators = TypeValidators.clone({\n\t'errorMessages': {\n\t\tSTRING_PATTERN: (templateVars, path) =\u003e {\n\t\t\tswitch (path.join('.')) {\n\t\t\t\tcase 'name':\n\t\t\t\t\treturn 'Name must only contain numbers and letters'\n\n\t\t\t\tcase 'file.name':\n\t\t\t\t\treturn 'All file names must only contain numbers and letters'\n\n\t\t\t\tdefault:\n\t\t\t\t\treturn `Must match ${templateVars.pattern}`;\n\t\t\t}\n\t\t}\n\t}\n});\n```\n\n## Work in progress\n\nThe following **facets** are not yet implemented:\n\n- `discriminator` in [Unions](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#using-discriminator)\n- `discriminatorValue` [Unions](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#using-discriminator)\n\nThe following **types** are not yet implemented:\n\n- [`date-only`](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#date)\n- [`time-only `](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#date)\n- [`datetime-only `](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#date)\n- [`file`](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#file)\n\nThe following **concepts** are not yet implemented:\n\n- [Multiple Inheritance](https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#multiple-inheritance)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesoft%2Framl-validator-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwavesoft%2Framl-validator-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavesoft%2Framl-validator-loader/lists"}