apiaryio / api-blueprint

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

How can I make a nest of object using data structure? #406

Closed gyarasu closed 6 years ago

gyarasu commented 6 years ago

I read the documentation. https://apiblueprint.org/documentation/advanced-tutorial.html

According to Data Structures section, we can write data structure in array like below example.

### List All Questions [GET]
+ Response 200 (application/json)

    + Attributes (array[Question])

## Data Structures

### Question
+ question: Favourite programming language? (required)
+ published_at: `2014-11-11T08:40:51.620Z` (required)
+ url: /questions/1 (required)
+ choices (array[Choice], required)

### Choice
+ choice: Javascript (required)
+ url: /questions/1/choices/1 (required)
+ votes: 2048 (number, required)

By the way, I want to define JSON structure as bellow.

{
  Obj1: { ... },
  Obj2: {....}
}

Obj1 and Obj2 are defined as Data Structure respectively. How can I write?

I tried to write this. But I didn't get it.

+ Response 200 (application/json)
    + Attributes (Obj)

## Data Structures
### Obj
+ Obj1 (object)
    + (Obj1)
+ Obj2 (object)
    + (Obj2)

### Obj1
+ ID: 1 (string, required)
+ Name: 'My Name' (string, required)

### Obj2
+ URL: `http://example.com` (string, required)
+ Title: example site (string, required)

Do you have any idea?

kylef commented 6 years ago
+ Response 200 (application/json)
    + Attributes (Obj)

## Data Structures
### Obj
+ Obj1 (Obj1)
+ Obj2 (Obj2)

### Obj1
+ ID: 1 (string, required)
+ Name: 'My Name' (string, required)

### Obj2
+ URL: `http://example.com` (string, required)
+ Title: example site (string, required)
gyarasu commented 6 years ago

@kylef Thank you very very much! I got it:)