Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Support key matching #44

Open
AndersDJohnson opened this issue May 28, 2016 · 2 comments
Open

Support key matching #44

AndersDJohnson opened this issue May 28, 2016 · 2 comments

Comments

@AndersDJohnson
Copy link

AndersDJohnson commented May 28, 2016

It might be useful to support matching on keys, e.g. wildcards, regular expressions, etc., sort of like JSON Schema's patternProperties:

var s = require('strummer');

var person = s({
  '/.*Name/': 'string',
  'posts': {
    '*': 'boolean'
  }
});

console.log(person.match(bob));

would match:

{
  firstName: 'Anders',
  lastName: 'Johnson',
  posts: {
    '123': true,
    '456': true
  }
}

Then I could validate responses from an API like the above which includes dynamically generated IDs as keys of a relationships object in the format of Ember.js.

@kiddkai
Copy link
Contributor

kiddkai commented May 30, 2016

Hi @adjohnson916 , did you try https://github.com/TabDigital/strummer/blob/master/MATCHERS.md#hashmap ?

It looks similar to me (or do the same thing). But it doesn't generating JSONSchema yet. 🙈

@AndersDJohnson
Copy link
Author

@kiddkai I saw that, but I don't want to have to define my entire object as a hashmap, only specific keys within an object that's otherwise validated with other strummer rules.

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

No branches or pull requests

2 participants