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

Omit property of object defined in 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 实体并说明我想省略哪些字段?

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

  • 声明 id 属性 nullable

  • 在没有 id 的情况下声明 Article,然后从 Article 继承并附加 id

# Data Structures

## Article (object)
+ name: My first article (string)

## ArticleInstance (Article)
+ id (number)

## 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)