Repeating a MSON data structure with different values

☆樱花仙子☆ 提交于 2019-12-10 11:44:06

问题


I have many places in my API where I will need to describe a list of objects. Each object has the same keys / structure but different values. How can I tweak the values of each instance of some data structure while retaining all the original type, description, etc of the original structure?

for example if I had the following data structure Restaurant

# Data Structures
## Restaurant (object)
+ restaurant_name: McDonald's (string, required) - The name of this restaurant
+ years_of_operation: 54 (number, required) - The number of years since established

Then, let's say I want to instantiate several Restaurants in a GET response like so:

### List all restaurants [GET /restaurants]

+ Response 200 (application/json)
    + Attributes
        + data (array)
            + (Restaurant)
            + (Restaurant)
                + restaurant_name: Bob Evans
                + years_of_operation: 23
            + (Restaurant)
                + restaurant_name: Eataly
                + years_of_operation: 16

the JSON body would look like this (note how years_of_operation for Bob Evans and Eatly are now numbers)

and the rendered documentation will only show this (the descriptions for restaurant_name and years_of_operation for Bob Evans and Eatly are now missing)

I thought that MSON would carry over those descriptions and type definitions. Otherwise, I have to update a description (or type, requirement, etc) everywhere that data structure is used... but I was under the impression this is a sort of problem MSON is supposed to solve? Am I doing something silly?

I'm posting here in addition to my github issue since it's been a long time since that repo has had contribution

来源:https://stackoverflow.com/questions/52335828/repeating-a-mson-data-structure-with-different-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!