apiaryio / mson

Markdown Syntax for Object Notation
MIT License
899 stars 181 forks source link

Ability to select a particular sample of a referenced name type #24

Open jmdacruz opened 9 years ago

jmdacruz commented 9 years ago

I recently found myself in the following situation: I defined a couple of Named Type objects, one referencing the other(e.g., object A has a reference to object B). Each of the objects may have a couple of Sample sections. I'd like to have the ability, when defining the Sample section of object A, to reference a particular Sample in object B's definition. This would allow me to document difference scenarios of the API.

Moreover, I'd like to see Samples that are just instantiations of the type definitions, or that are somehow validated against the type definition (in order to avoid inconsistencies between samples and the type definition)

pksunkara commented 9 years ago

This is something we have been thinking about but the MSON feature is still in beta and we would like to finish supporting it first.

jmdacruz commented 9 years ago

Sounds good! Just wanted to get it on your radar.

I think it will become an important feature over time, as people start using Apiary for emulating different sample outputs using the "Prefer" header (which I think it's a very powerful feature). Developers using the "Prefer" header in combination with complex (e.g., nested) objects won't be able to use MSON because of the limitation I've documented in this issue (the alternative would be having different Named Types for each sample, which defeats the purpose of using MSON)

zdne commented 9 years ago

or that are somehow validated against the type definition (in order to avoid inconsistencies between samples and the type definition)

This is definitely planned for a future release of the parser.

As for the referencing one sample from another – I do not really see a use as for it. Maybe an example would help?

Note, in MSON, there is nothing like type definition and instantiation – those two are essentially a the same.

Isn't something like:

# Data Structures
## A (object)
+ a1: 1
+ a2: 2

# Resource A [/a]
## Create [GET]
+ request (application/json)
  + attributes (A)

+ response 201

+ request (application/json)
  + attributes (A)
    + a2: 42

+ response 400

working for you?

Note this is related to https://github.com/apiaryio/api-blueprint/issues/58 (when it comes to specifying what is a response based on input properties)

jmdacruz commented 9 years ago

I see... so you basically try to instantiate the attributes at the Resource, when you are instantiating the data structure. I tried with the blueprint below, but it's not working for me (let me know if there is something wrong with it...)

FORMAT: 1A
HOST: http://parametrizedmson.apiblueprint.org/

# Testing parametrized MSON

Just testing parametrized MSON.

# Resource A [/a]
## Create [GET]
+ request (application/json)
  + attributes (A)

+ response 201

+ request (application/json)
  + attributes (A)
      + a2: 42

+ response 400

# Data Structures
## A (object)
+ a1: 1
+ a2: 2

Comments and questions:

Name Type Required Description Value
a2 optional 42
a1 optional 1
a2 optional 2
# Data Structures

## Item (object)

### Properties
- uuid: `08ff7052-2e95-11e3-a1fc-000c294eede0` (required, string, sample) - A unique ID
- property1: 42
- property2: 56

## Collection (object)

### Properties
- data (object, required, sample)
    - currentItemCount: `1` (required, number, sample) - Number of items in the current view of the collection
    - totalItems: `1` (required, number, sample) - Number of total items in the collection
    - items (array[Item])
pksunkara commented 9 years ago

Hey @jmdacruz

Regarding the a: 42 not overriding the a: 2, it is an known bug and we are working on it. But other than, your 2 other feature requests are good and we will be looking into them. Thanks.

jmdacruz commented 9 years ago

Great to now! Thanks!

zdne commented 9 years ago

@pksunkara is there a tracking issue for the "a: 42 not overriding the a: 2" ?

pksunkara commented 9 years ago

hmm... Looks like we don't have a tracking issue for it.

zdne commented 9 years ago

@pksunkara so please create one or turn this one into it (but preferably the former and on the parser). Thanks!

zdne commented 9 years ago

If we do not have a tracking issue then it is not a know issue :)

pksunkara commented 9 years ago

https://github.com/apiaryio/drafter/issues/44

zdne commented 9 years ago

thanks @pksunkara

zdne commented 9 years ago

Just to reiterate. Is there another issue but the fix of https://github.com/apiaryio/drafter/issues/44 .

@jmdacruz are we looking for a way to display different samples in libraries using MSON or are we asking parser – representation renderer to render specific sample instead of the default one?

pksunkara commented 9 years ago

From what I understood, @jmdacruz was talking about having a way to select a specific sample to be sent the to the renderer in certain cases instead of the default one.

Example (disregard the syntax): We have a named type User with samples describing users pavan and kyle.

+ (array)
    + (User:pavan)
    + (User:kyle)

should render the following:

[
  {
    "username": "pavan"
  },
  {
    "username": "kyle"
  }
]
jmdacruz commented 8 years ago

@zdne can you elaborate on the difference between these two alternatives?

are we looking for a way to display different samples in libraries using MSON or are we asking parser – representation renderer to render specific sample instead of the default one?