apiaryio / api-blueprint

API Blueprint
https://apiblueprint.org
MIT License
8.63k stars 2.14k forks source link

Allow any object? #398

Closed FranklinYu closed 7 years ago

FranklinYu commented 7 years ago

How do I allow any object to be value of a key? such as

{
  "prop": {"foo": 1, "bar": true}
}

I want to allow user to put any object as value of "prop". If I do

+ prop: `{"a": 1}` (object)

It says this is invalid, because an object can't have value example.

Actually my use case would be Map<String, Number> instead of plain object (keys are not known in advance). I'm wondering whether API Blueprint is able to specify that.

pksunkara commented 7 years ago

@franklinyu Just do something like this.

+ prop (object)

It means, it can be any object.

FranklinYu commented 7 years ago

Then it can't have any example. This hurts when it is actually not any object, just not able to express in current API Blueprint specification. I have to explain in the comments, which is not as loud as an example.

pksunkara commented 7 years ago

I don't understand. You said it can be any object and then you are saying it can't be any object? Can you please explain what exactly you are trying to do in a little more detail?

FranklinYu commented 7 years ago

I want to specify that it need to be Map<String, Number>, but the key can be any string. For example,

{
  "foo": 1,
  "bar": 2
}

is acceptable, but not

{
  "string": "string",
  "boolean": true,
  "object": {
    "key": "val"
  }
}

AFAIK there is no way to specify this structure in API Blueprint, so I'm wondering whether I can just show a valid example to readers of my API.

pksunkara commented 7 years ago

You can do something like this:

+ prop (object)
    + *key* (number)
FranklinYu commented 7 years ago

Not sure how that would work. Is that Generic Named Type? (I suddenly found that this issue belongs to MSON, but anyway.)

pksunkara commented 7 years ago

It is variable property name

On Fri, Jun 9, 2017, 00:54 Franklin Yu notifications@github.com wrote:

Not sure how that would work. Is that Generic Named Type https://apiblueprint.org/documentation/mson/specification.html#53-generic-named-type? (I suddenly found that this issue belongs to MSON, but anyway.)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/apiaryio/api-blueprint/issues/398#issuecomment-307249159, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKqb4fuKdf8O0hjtA52X6RfOcz4kow9ks5sCHuXgaJpZM4Np0JK .

FranklinYu commented 7 years ago

Thank you. That Variable Property Name is exactly what I need. However Apiary doesn't seem to support that:

+ Request
    + Attributes (object)
        + *key* (number)

and

+ Request
    + Attributes (object)
        + key (number)

looks the same in the generated documentation.

(documentation link for my own record)

pksunkara commented 7 years ago

Yes. It's not completely supported in apiary

On Fri, Jun 9, 2017, 18:33 Franklin Yu notifications@github.com wrote:

Thank you. That's exactly what I need. However Apiary doesn't seem to support that:

  • Request
    • Attributes (object)
      • key (number)

and

  • Request
    • Attributes (object)
      • key (number)

looks the same in the generated documentation.

(documentation link for my own record https://apiblueprint.org/documentation/mson/specification.html#322-variable-property-name )

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/apiaryio/api-blueprint/issues/398#issuecomment-307437329, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKqb6kbbQn-WYDsHmB4n54ujLQNokm0ks5sCXPEgaJpZM4Np0JK .