apiaryio / mson

Markdown Syntax for Object Notation
MIT License
900 stars 180 forks source link

sets #55

Open LinusU opened 8 years ago

LinusU commented 8 years ago

How about having sets, which is really just arrays that can have predefined values at most one time?

Proposed syntax:

+ privileges (set[string], required)
    + network
    + mailman
    + procmod
    + procview
    + lpadmin
    + lpoperator
zdne commented 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.

zdne commented 8 years ago

fixed is essentially saying the instance of this type should appear exactly as defined below.

zdne commented 8 years ago

oh wait, you want just one value to be there?

zdne commented 8 years ago

or any number of those values? but only the values from the set?

zdne commented 8 years ago

Either way I think it might have a solution with combination of array enum and maybe fixed

LinusU commented 8 years ago

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" ] }
honzajavorek commented 8 years ago

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

LinusU commented 8 years ago

@zdne Does "s1: awaiting input" mean that you are waiting on more information from me? I'm happy to help or provide more info 👍

pksunkara commented 8 years ago

@LinusU I think we are waiting for more feedback from other users here.

I also wonder how JSON Schema handles this.

LinusU commented 8 years ago

JSON Schema:

{
  "type": "array",
  "uniqueItems": true,
  "items": {
    "enum": [ "network", "mailman", "procmod", "procview", "lpadmin", "lpoperator" ]
  }
}
zdne commented 8 years ago

@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?

LinusU commented 8 years ago

@zdne That would work for the happy case, but then this array would also be considered valid:

[ "procmod", "procmod" ]
zdne commented 8 years ago

@LinusU fair point. I think we have a case for set or a new type modifier (unique)?