I'm investigating the possibilities of the new Data Structures syntax in API Blueprint, especially MSON. Is it possible to attach or rather specify something like a pattern (regex)? Don't found anything on this topic.
Asked
Active
Viewed 786 times
6
-
Would you be able to elaborate slightly on what you are trying to achieve. Are you looking to specify an attribute with a value that is a regex pattern, or use a regex pattern for validation of a value? – kylef Aug 05 '15 at 11:27
-
I want to validate a value using a regex like + firstname: Mamfred (required, pattern[/regex/]) – loxy Aug 05 '15 at 15:14
-
To be more precise, we use Aglio and since version 2 there is a basic support for Data Structures and Attributes. The library renders also an JSON Schema. And for that an automatic pattern description would be very useful. But if MSON does not support those... – loxy Aug 06 '15 at 09:56
1 Answers
5
To provide regex validation for your data structure you will need to provide a JSON Schema which has this validation rule. For example, like the following:
### View a Questions Detail [GET]
+ Response 200 (application/json)
+ Attributes
+ question: `Favourite programming language?` (string)
+ Schema
{
"properties": {
"question": {
"type": "string",
"pattern": "^Favourite.*$"
}
}
}

kylef
- 1,066
- 1
- 8
- 11
-
I know. I'm asking because Aglio automatically adds a Schema on basis of the attribute / Data Structures... – loxy Aug 12 '15 at 15:04