我需要在raml中指定一个API,其中必须指定对象属性,否则验证将失败。这是通过/^note\d+$/?: # restrict any properties whose keys start with "note"
# followed by a string of one or more digits
type: string
实现的。
此外,我想指定请求对象可以包含模式属性,类似于官方示例:
Moreover, if additionalProperties is false (explicitly or by inheritance) in a given type definition, then explicitly setting pattern properties in that definition is not allowed. If additionalProperties is true (or omitted) in a given type definition, then pattern properties are allowed and further restrict the additional properties allowed in that type.
仅靠这两个事情就可以了,但是当放在一起时,它们将不再起作用(如RAML规范中所述):
types:
Person:
description: |-
Document representing a person.
additionalProperties: false
properties:
firstName?:
description: |-
The person's first name
type: string
/^person_info_.+$/?:
description: Additional person info.
type: string
所以问题是我怎么能达到这个要求。像这样:
extraneous key [person_info_1] is not permitted
请注意,此示例将无法显示
之类的内容do {
try FileManager.default.trashItem(at: NSURL(fileURLWithPath: "/Users/catalina/Desktop/Doc.docx") as URL, resultingItemURL: nil)
} catch let err as NSError {
print(err)
}
答案 0 :(得分:0)
我阅读RAML规范的方式是说,针对属性进行验证时,存在3个严格级别:
很高兴对2的含义进行更正,但这就是规范的阅读方式。