省略 MSON 中定义的对象的属性



如何省略定义的 MSON 中的属性?我使用 MSON 定义了一个简单的实体(对象):

# Data Structures
## Article (object)
Represents an article
## Properties
+ id: 1 (number, optional)
+ name: My first article (string)
## Articles [/articles]
### Get all articles [GET]
Get all articles available on this website.
+ Response 200 (application/json)
 + Attributes (array[Article])
### Create an article [POST]
Create new article.
+ Request (application/json)
    + Attributes (Article)

我在几个 api 端点中使用Article对象。问题是我不希望在发布新文章时指定id,因此我想在POST方法的文档中省略它。是否可以在所有端点中包含Article实体并说出我要省略哪些字段?

实际上没有办法做到这一点。您有两种选择:

  • 使用属性nullable声明id

  • 声明Article不带id,稍后从Article继承并附加id

# 数据结构## 文章(对象)+ 名称: 我的第一篇文章 (字符串)## 文章实例 (文章)+ ID(数字)## 文章 [/文章]### 获取所有文章 [获取]获取本网站上提供的所有文章。+ 响应 200(应用程序/json) + 属性(数组[文章])### 创建文章 [发布]创建新文章。+ 请求(应用程序/json)    + 属性 (文章)

最新更新