我需要在raml中指定一个API,其中必须指定对象属性,否则验证将失败。这是通过additionalProperties: false
实现的。
此外,我想指定请求对象可以包含模式属性,类似于官方示例:
/^note\d+$/?: # restrict any properties whose keys start with "note"
# followed by a string of one or more digits
type: string
这两个东西单独都可以,但是放在一起时它们就不再起作用了(在RAML规范中指定):
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.
所以问题是我怎样才能达到这一要求。类似于:
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
我阅读RAML规范的方式,就是说,针对属性进行验证时,严格性分为三个级别:
我很高兴对2的含义进行更正,但这就是规范的阅读方式。