是从体型(RAML)中排除属性的方法吗?

Ant*_*nov 4 api raml

当您使用类型并使用RAML 1.0编写API时,是否有办法从请求主体中排除一个或多个属性

我会解释一下.我有一个类型:'Order',带有一组属性.我有一个资源/orders和方法post,允许用户创建一个新的订单.请求主体是订单结构json,响应也是订单结构.

但我不希望用户在提交请求时指定订单ID.但是该响应将返回该id(以及更多"仅响应"字段).我不想创建一个额外的类型,OrderRequest然后继承它的Order类型,也许有一个更优雅的解决方案?

所以我希望有一种方法可以从请求主体中排除某些属性,并保留其他属性以便使用它们的描述和示例.

谢谢,抱歉我的英文:)

gal*_*kin 7

使用两种类型.第二个将是第一个孩子.例:

#%RAML 1.0
title: GitHub API
version: v3
baseUri: https://api.github.com
mediaType:  application/json
types:
  OrderCreating:
    type: object
    properties:
      products:
        description: List of product ids with amount.
        required: true
        type: object
        properties:
          []:
            type: number
      coupon?: string
  Order:
    type: OrderCreating
    properties:
      id: integer
      price: number
...
/orders:
  post:
    body:
      application/json:
        type: OrderCreating
  /{orderId}:
    get:
      responses:
        200:
          body:
            application/json:
              type: Order
Run Code Online (Sandbox Code Playgroud)

您还可以在库中包含类型声明.