Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command validation in .js instead of .json? #77

Open
hilkeheremans opened this issue Apr 20, 2016 · 1 comment
Open

Command validation in .js instead of .json? #77

hilkeheremans opened this issue Apr 20, 2016 · 1 comment

Comments

@hilkeheremans
Copy link

hilkeheremans commented Apr 20, 2016

Currently command validation is done only in .json files. I strongly feel pure json notation is rather heavy ( "), which makes it more difficult to read and maintain.

What if we also allow these validations to be written as .js files? Ie, we do

// some_validation.js
module.exports = {
  title: 'command/hr/person',
  allOf: [
    {
      '$ref': '/command/hr'
    },
    {
      properties: {
        aggregate: {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              pattern: 'person' // I can also add comments now
            }
          }
        }
      }
    }
  ]
}

instead of

// some_validation.json (which can't contain this comment or the json is invalid ;-))
 {
  "title": "command/hr/person",
  "allOf": [
    {
      "$ref": "/command/hr"
    },
    {
      "properties": {
        "aggregate": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "pattern": "person"
            }
          }
        }
      }
    }
  ]
}

Pro's:

  • much easier to define and maintain your tv4 files (in my opinion anyway, not sure if you agree)
  • more flexibility: allows for other js features (comments, even function calls for whatever reason, ...)

Cons:

  • the files themselves are more difficult to distinguish from the other definitions (right now the validation files stand out because they are json)
  • you need to use module.exports
  • validation (isSchema()) becomes slightly weaker, but this validation was rather weak in the first place

The changes needed to the lib code are minimal (exactly one line).

What do you think?

@adrai
Copy link
Contributor

adrai commented Apr 21, 2016

If we're able to write json and js files I would accept a PR ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants