0

I have a attribute address, in Json response I'll get array of address and when address is not available Iam getting "" empty string as response. I declared address as array type in raml file, so Iam getting error when I receive "" Empty String. So, How to accept both string and array of objects as input for a same attribute in raml file.

RAML file

addresses:
  type:
  properties:
    streetNo:
      type: string

Response:
  type: object
  properties:
    address:
      type: addresses[]

How to accept both string and array of objects as input for a same attribute in raml file.

I might get the output as "" empty string in Json response if no address available. At that time I am getting error.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56

1 Answers1

0

In RAML, you can define an attribute to accept multiple data types as input using the "union" type. The union type allows you to specify multiple types for a single attribute and allows the attribute to accept any of the specified types.

For example, if you want to accept both a string and an array of objects as input for a single attribute, you can define the attribute as follows:

attributeName: type: string | object[ ]

This means that attributeName can accept either a string value or an array of objects. When using this attribute, you can pass either a string or an array of objects as input and it will be valid according to the RAML definition.

Andrew O
  • 1
  • 1