0

In my API RAML, there is a query parameter named 'sfIds' which is an array type. I need to implement validation within the RAML to ensure that the array elements are always numeric, such as [111, 222, 333] or [111]. An array such as [ABC,111] should not pass RAML validation.

Is there a way to define "types" for this validation?

Below is a segment of my RAML code; please be aware that this is just a portion of the full RAML. It is not functioning as anticipated in my Mule flow.

#%RAML 1.0
title: My Test API
version: v1
types:
  NumericArray:
    type: array
    items: number
/ids:
  get:
    queryParameters:
    sfIds?:
        type: NumericArray
        example: [111,222]

The error that I get in the Mule flow is:

Invalid value '[111,222]' for query parameter sfIds. /0 expected type: Number, found: JSONArray"
1
  • Since the issue is happening in a Mule application it would be helpful to provide details of Mule version, APIKit version, the URL used, the complete error message and maybe details of the flow and configurations related to the issue. Commented Apr 24, 2024 at 15:09

2 Answers 2

0

You can try with mentioning more specific type like number[] which is an Array of Number

#%RAML 1.0
title: My Test API
version: v1
types:
  NumericArray:
    type: number[]
/ids:
  get:
    queryParameters:
      sfIds?:
        type: NumericArray
        example: [111,222]

Url to access the above -> /api/ids?sfIds=123&sfIds=234 which will result in [123,234] when you access it using valuesOf(attributes.queryParams)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for sharing. I tried this but getting an exception in the API. "exceptionMessage": "org.mule.module.apikit.api.exception.InvalidQueryParameterException:Invalid value '[1235]' for query parameter sfIds. /0 expected type: Number, found: JSONArray" Please advise
@TriumphSpitfire how are you accesing the url?? I have added the url in answer.. that is the right format
I think you can not pass something like /api/ids?sfIds=[111,222] to validate array of numbers @TriumphSpitfire
0

I have managed to get this working. Here is the RAML that is now functioning.

#%RAML 1.0
title: My Test API
version: v1
types:
  NumericArray:
    type: array
    items: number
    minItems: 1
/ids:
  get:
    queryParameters:
      sfIds?:
        type: array
        items:
         type: NumericArray

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.