我是RAML的新手,最近继承了一个我需要更新以反映新规范的项目。
这是一个相当简单的RAML文档,我所做的就是添加一个新的body属性,我想展示多个示例。
以前,有一个"codeType1“属性,这是该职位所需的。
现在,有一个新的"codeType2“属性,其中一个是必需的。因此,无论是codeType1还是codeType2,都必须在post主体中。我不知道怎么用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":"name@email.com",
"password":"Abc123!",
}
responses:
200:
description: Successful authentication.
body:
application/json:
example:
{
"status": "success",
"message": "Authentication success",
"data": {
"token": "SDKFHDSLFDJSFDKJFDHSFLJKFHLSKFSFLKFLSDFJHSLHFSDF"
}
}
发布于 2019-11-10 21:41:57
试试这个:
#%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: "name@email.com"
password : "Abc123!"
ex2:
codeType2: "12345"
userId: "anothername@email.com"
password: "ZYX098"
我只是复制了我换过的部分。
下面是我在上面使用的RAML 1.0规范中的几个引用:
https://stackoverflow.com/questions/58664277
复制相似问题