RAML:可以使用对象A或对象B

时间:2018-09-06 09:01:24

标签: api ram

我正在用RAML编写一些REST文档,但是我被卡住了。

我的问题:-我有一个POST请求,可以接收一个或另一个对象。仅需要其中之一。

我的解决方案是创建一个带有Union的类型:

    #%RAML 1.0 Library
    uses:
      annotations: ../../glapi-global-apis-commons-commons/annotations/annotationsLibrary.raml
      contract: contract.raml
      customerBureau: customerBureau.raml

    types: 
      transaction:
        type: object
        properties:
          detail:
            (annotations.bindingDefinition):
              - method: "POST"
                input: "OPTIONAL"
                output: "NONE"
            type:  customerBureau.customerBureau | contract.contract
            required: false
            description: |
              Detailed information according to the transaction type.

然后在请求中像这样使用它:

/external-filters/request:
    description: |
        Service for requesting the necessary information for non-customers (or customers) or the interveners of a contract to external bureaus.
    type: consulting-post
    post:
        description: |
            Method for requesting the necessary information for non-customers (or customers)  or the interveners of a contract to external bureaus. Will be mandatory
            the personal information of the non-customers (name, middle name and identity document). If the user was client
            the information required will be the customer identificator. If what is wanted is the information for the interveners of a contract the required information will be the contract number and format.
        body:
            application/json:
                type: transaction.transaction
                examples:
                    non-customer:
                        value: !include examples/external-filters/request/post-204-non-customer.json
                        description: JSON input example when request information about external filters of a non-customer
                        displayName: Non-customer JSON input
                    customer:
                        value: !include examples/external-filters/request/post-204-customer.json
                        description: JSON input example when request information about external filters of a Customer
                        displayName: Customer JSON input
                    contract:
                        value: !include examples/external-filters/request/post-204-contract.json
                        description: JSON input example when request information about external filters of the interveners of a Contract
                        displayName: Contract JSON input
        responses:
            204:
                description: No content.

问题是示例未经验证,我收到此错误:

  

验证文件:   C:\ Users \ xe76572 \ Downloads \ ejemplos_raml \ esapi-es-apis-people-risks-master @ c1a7b76492b \ api.raml   行:36列:25消息:未知属性:'identityDocument'   列:25消息:未知属性:'middleName'列:25消息:   未知属性:“ lastName”列:25消息:未知属性:   “名字”

     

文件:   C:\ Users \ xe76572 \ Downloads \ ejemplos_raml \ esapi-es-apis-people-risks-master @ c1a7b76492b \ api.raml   行:40列:25消息:未知属性:'customerId'

     

文件:   C:\ Users \ xe76572 \ Downloads \ ejemplos_raml \ esapi-es-apis-people-risks-master @ c1a7b76492b \ api.raml   行:44列:25消息:未知属性:'number'列:25   消息:未知属性:'numberType'

任何想法为什么或如何解决?

0 个答案:

没有答案