【问题标题】:RAML 1.0, Map types complex regular expressionRAML 1.0,映射类型复杂的正则表达式
【发布时间】:2016-06-04 11:36:10
【问题描述】:

在我的 api 中,我有一个包含 uuid->Drive 映射的类型。我使用了 Map 类型 [1] 来定义它:

type: object
properties:
  drives:
    required: false
    type: object
    properties:
      [(a-zA-Z0-9-)*] :
         type: Drive

这项工作,但我想在模式上更精确。但是我无法让它工作。

  • ["(a-zA-Z0-9){8}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){12}"]: 好像没有用作正则表达式。
  • [(a-zA-Z0-9){8}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){12}]:流集合条目之间缺少逗号

如何在带有 RAML 1.0 的 Map 类型中使用复杂的表达式?

(我正在使用 API 工作台)

[1]http://docs.raml.org/specs/1.0/#raml-10-spec-map-types

【问题讨论】:

    标签: regex raml


    【解决方案1】:

    您需要使用以 /^ 开头并以 $/ 结尾的 RegEx 字符串

    #%RAML 1.0
    title: My API With Types
    types:
      Person:
        properties:
          name:
            required: true
            type: string
          age:
            required: false
            type: number
          /^note\d+$/: # restrict any properties whose keys start with "note"
                       # followed by a string of one or more digits
            type: string
    

    https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#additional-properties

    【讨论】:

      【解决方案2】:

      使用 patternProperties 而不是替代语法,我的 RAML 中没有任何错误。然而,API Workbench 似乎什么也没验证。

      【讨论】:

        猜你喜欢
        • 2015-02-21
        • 1970-01-01
        • 2023-03-04
        • 2017-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-16
        • 2019-04-30
        相关资源
        最近更新 更多