apiaryio / mson

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

How to express an object whose keys are ids? #68

Closed anentropic closed 8 years ago

anentropic commented 8 years ago

I can't see how to specify:

I want to describe a response that looks like

{
    1: (UserObject),
    2: (UserObject),
}

etc, where the keys are ids

anentropic commented 8 years ago

ok, I found this syntax:

    + Attributes (object)
        + *123* (UserObject, optional) - example user, id=123
        + *456* (UserObject, optional) - example user, id=456

this seems to express what I want. The only issue I have is that drafter parses this as:

  -
    element: "member"
    meta:
      description: "example user, id=123"
    attributes:
      typeAttributes:
        - "optional"
    content:
      key:
        element: "string"
        attributes:
          variable: true
        content: "123"
      value:
        element: "UserObject"

How do I tell it that *123* represents a number variable rather than string ?

zdne commented 8 years ago

@anentropic it would be

# My Object
- *134 (number)* (UserObject)

However I am not sure if other but string-based keys are supported by the parser. It definitely won't render into JSON. May I ask where do you need this / what is the use case?

anentropic commented 8 years ago

Oh, I forgot that JSON keys must be strings, I was still thinking in Python

I tried the syntax above but Apiary editor complains the blueprint is invalid

Anyway, the existing syntax correctly represents the output JSON with string keys so I don't have a problem after all.

Thanks