raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 857 forks source link

Question for validatin Union Types #694

Closed sacabornero closed 6 years ago

sacabornero commented 6 years ago

Asume we have the following definitions:

types/transactionDetails

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

types: 
  transactionDetail:
    type: object
    discriminator: transactionType
    properties:
      transactionType: 
        type: string
        enum: [CUSTOMER, CONTRACT]
        (annotations.enumDescription):
          - CUSTOMER: Method for requesting the necessary information for non-customers (or customers) to external bureaus.
          - CONTRACT: Method for requesting the necessary information for the interveners of a contract to external bureaus.
        required: false
        description: The transaction type.
        (annotations.bindingDefinition):
          - method: "GET"
            input: "NONE"
            output: "REQUIRED"
          - method: "POST"
            input: "REQUIRED"
            output: "REQUIRED"
          - method: "PATCH"
            input: "REQUIRED"

types/contract

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

types: 
  contract:
    type: transactionDetail.transactionDetail
    discriminatorValue: CONTRACT
    # If transactionType == "CONTRACT", the object will be of the purchase type
    properties:
      number:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: string
        description: |
              Contract number.
        required: false
      numberType:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "REQUIRED"
            output: "NONE"
        type: string
        enum: ["BOCF", "CCC", "IBAN", "IUC"]
        (annotations.enumDescription):
          - BOCF : BOCF type contract number, unique to BBVA.
          - CCC : Client Account Code used in Spain.
          - IBAN : International Bank Account Number.
          - IUC : Unique contract identifier
        description: |
          Type of format in which the contract is expressed.
        required: false

types/customerBureau

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

types: 
  customerBureau:
    type: transactionDetail.transactionDetail
    discriminatorValue: CUSTOMER
    # If transactionType == "CUSTOMER", the object will be of the purchase type
    properties:
      customerId:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: string
        description: |
             Customer identifier.
        required: false
      firstName:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: string
        description: |
             Name of the person.
        required: false
      middleName:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: string
        description: |
             Name of the person occurring between the first and family names, as a second given name or a maternal surname.
        required: false
      lastName:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: string
        description: |
          Name(s) written after the "given names" and could be the main name.
        required: false
      identityDocument:
        (annotations.bindingDefinition):
          - method: "POST"
            input: "OPTIONAL"
            output: "NONE"
        type: identityDocument.identityDocument
        description: |
          Identity document information related to the customer.
        required: false

types/transaction

#%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.

And here we have a post method:

#%RAML 1.0
title: Risks
version: v0.3.0
description: !include docs/apiDescription.md
baseUri: https://www.bbvaapis.com/risks/v0

uses:
  customerBureau: types/customerBureau.raml
  financialDebts: types/financialDebts.raml
  identityDocuments: types/identityDocuments.raml
  rating: types/rating.raml
  contract: types/contract.raml
  transaction: types/transaction.raml

annotationTypes:
  enumDescription: !include ../glapi-global-apis-commons-commons/annotations/enumDescription.raml

resourceTypes:
  consulting-post: !include ../glapi-global-apis-commons-commons/resourceTypes/consulting-post.raml
  collection: !include ../glapi-global-apis-commons-commons/resourceTypes/collection.raml

/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.

I'm having trouble with the json examples when I try to validate, I'm getting this message;

Validation 
File: C:\Users\xe76572\Downloads\ejemplos_raml\esapi-es-apis-people-risks-master@c1a7b76492b\api.raml
Line: 36
Column: 25
Message: Unknown property: 'identityDocument'
Column: 25
Message: Unknown property: 'middleName'
Column: 25
Message: Unknown property: 'lastName'
Column: 25
Message: Unknown property: 'firstName'

File: C:\Users\xe76572\Downloads\ejemplos_raml\esapi-es-apis-people-risks-master@c1a7b76492b\api.raml
Line: 40
Column: 25
Message: Unknown property: 'customerId'

File: C:\Users\xe76572\Downloads\ejemplos_raml\esapi-es-apis-people-risks-master@c1a7b76492b\api.raml
Line: 44
Column: 25
Message: Unknown property: 'number'
Column: 25
Message: Unknown property: 'numberType'

How can I make the different examples valid?