Open LinusU opened 8 years ago
+ privileges (array[string], fixed)
+ network
+ mailman
+ procmod
+ procview
+ lpadmin
+ lpoperator
Is what you looking at. Do not forget that the required
there makes privileges
key mandatory in its parent object.
fixed
is essentially saying the instance of this type should appear exactly as defined below.
oh wait, you want just one value to be there?
or any number of those values? but only the values from the set?
Either way I think it might have a solution with combination of array
enum
and maybe fixed
I want the following objects to be considered valid:
{ "privileges": [] }
{ "privileges": [ "procmod" ] }
{ "privileges": [ "procmod", "lpoperator", "network" ] }
And the following to be considered invalid:
{}
{ "privileges": [ "somethingelse" ] }
{ "privileges": [ "procmod", "procmod", "network" ] }
I personally understand "set" as something like array, but with unique members and unsorted.
The uniqueness could be theoretically achieved by a validation rule. The fact it's unsorted... not sure how much that's important in web API contracts. On 17 Mar 2016 10:14 p.m., "Linus Unnebäck" notifications@github.com wrote:
I want the following objects to be considered valid:
{ "privileges": [] } { "privileges": [ "procmod" ] } { "privileges": [ "procmod", "lpoperator", "network" ] }
And the following to be considered invalid:
{} { "privileges": [ "somethingelse" ] } { "privileges": [ "procmod", "procmod", "network" ] }
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/apiaryio/mson/issues/55#issuecomment-198085019
@zdne Does "s1: awaiting input" mean that you are waiting on more information from me? I'm happy to help or provide more info 👍
@LinusU I think we are waiting for more feedback from other users here.
I also wonder how JSON Schema handles this.
JSON Schema:
{
"type": "array",
"uniqueItems": true,
"items": {
"enum": [ "network", "mailman", "procmod", "procview", "lpadmin", "lpoperator" ]
}
}
@LinusU
I want the following objects to be considered valid
{ "privileges": [] } { "privileges": [ "procmod" ] } { "privileges": [ "procmod", "lpoperator", "network" ] }
@LinusU in that case, this should be the solution:
# Permitted Values (enum[string))
- procmod
- lpoperator
- network
# My Object
- set (array[Permitted Values])
Does it work?
@zdne That would work for the happy case, but then this array would also be considered valid:
[ "procmod", "procmod" ]
@LinusU fair point. I think we have a case for set
or a new type modifier (unique
)?
How about having sets, which is really just arrays that can have predefined values at most one time?
Proposed syntax: