或一个或多个身体特性和多个示例

问题描述 投票:0回答:1

我是RAML的新手,最近继承了我需要更新以反映新规范的项目。

这是一个相当简单的RAML文档,我要做的就是添加一个新的body属性,我想显示多个示例。

以前,该帖子需要一个“ codeType1”属性。

现在,有了一个新的“ codeType2”属性,并且这两个是必需的。因此,codeType1或codeType2必须在帖子正文中。我不知道如何在RAML中表达该要求。

此外,对于每种情况,我还要有两个示例。

我能够添加新的codeType,但是我不知道如何表达验证规则。

这是我目前拥有的:

#%RAML 1.0
title: Auth Service
version: v1
protocols: [HTTPS]
mediaType: application/json

/auth:
    post:
      description: Authenticate a client to the API.
      body:
        application/json:
          properties:
            {
            "codeType1": {
                type: string,
                required: true
              },
            "codeType2":{
                type: string,
                required: true
              },
            "userId":{
                type: string,
                required: true
              },
            "password":{
                type: string,
                required: true
              },
            }
          example:
            {
              "codeType1":"994056",
              "codeType2":"##0023",
              "userId":"[email protected]",
              "password":"Abc123!",
            }
      responses:
        200:
          description: Successful authentication.
          body:
            application/json:
              example:
                {
                  "status": "success",
                  "message": "Authentication success",
                  "data": {
                    "token": "SDKFHDSLFDJSFDKJFDHSFLJKFHLSKFSFLKFLSDFJHSLHFSDF"
                  }
                }
api raml
1个回答
0
投票

尝试一下:

#%RAML 1.0
title: Auth Service
version: v1
protocols: [HTTPS]
mediaType: application/json

types:
  UserCred:
    properties:
      userId:
      password:
  Type1:
    type: UserCred
    properties:
      codeType1:
  Type2:
    type: UserCred
    properties:
      codeType2:

/auth:
    post:
      description: Authenticate a client to the API.
      body:
        application/json:
          type: Type1 | Type2
          examples:
            ex1: 
              codeType1: "994056"
              userId: "[email protected]"
              password : "Abc123!"
            ex2:
              codeType2: "12345"
              userId: "[email protected]"
              password: "ZYX098"

我只复制了更改的部分。

这里有一些我上面使用的RAML 1.0规范的参考:

© www.soinside.com 2019 - 2024. All rights reserved.