0

我想定义一个可选size对象。如果对象存在,则应该至少给出一个指定的属性(minmax)。我虽然是这样的:

properties:
    someval:
        type: string
    size:
        type: object
        required: false
        additionalProperties: false
        minProperties: 1
        properties:
            min:
                required: false
                type: string
            max:
                required: false
                type: string

但这似乎minProperies意味着size必须可用。如果我只设置最小值或最大值,至少我会收到此验证错误:

<pre>TypeError: Cannot convert undefined or null to object<br> &nbsp; &nbsp;at Function.keys (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at MinProperties.extractValue (C:\mypath\node_modules\raml-typesystem\dist\src\restrictions.js:1059:23)<br> &nbsp; &nbsp;at MinProperties.MinMaxRestriction.check (C:\mypath\node_modules\raml-typesystem\dist\src\restrictions.js:775:22)<br> &nbsp; &nbsp;at C:\mypath\node_modules\raml-typesystem\dist\src\typesystem.js:1564:89<br> &nbsp; &nbsp;at Array.forEach (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at InheritedType.AbstractType.validateDirect (C:\mypath\node_modules\raml-typesystem\dist\src\typesystem.js:1564:37)<br> &nbsp; &nbsp;at InheritedType.AbstractType.validate (C:\mypath\node_modules\raml-typesystem\dist\src\typesystem.js:1612:34)<br> &nbsp; &nbsp;at C:\mypath\node_modules\raml-validate\raml-validate.js:308:31<br> &nbsp; &nbsp;at C:\mypath\node_modules\raml-validate\raml-validate.js:405:18<br> &nbsp; &nbsp;at Array.map (&lt;anonymous&gt;)</pre>

如何在不使用始终设置的size对象的情况下实现初始规范?

4

1 回答 1

0

您可以尝试像这样分隔尺寸类型:

#%RAML 1.0
baseUri: https://mocksvc.qax.mulesoft.com/mocks/9a2d6433-e5f4-47c6-9c41-8701efcc9d9b
title: test
version: 1
protocols: [HTTP]
mediaType: application/json

types: 
  MinType:
    type: object
    additionalProperties: false
    properties:
      min:
        type: string
        required: true
  MaxType:
    type: object
    additionalProperties: false
    properties:
      max:
        type: string
        required: true
  MyType:
    type: object
    properties:
      someval:
        type: string
      size:
        type: MinType | MaxType
        additionalProperties: false
        required: false

/newResource:
  displayName: resourceName
  post:
    body: 
      type: MyType
      example: {"someval": "someval", "size" :{ "max": "1"}}
于 2018-11-14T19:27:05.017 回答