Getting error while trying to validate the header against oas policy

When I’m trying to validate the request content against the oas policy by passing the required header named X-My-Header which is an type of array, there were no errors when I sent one value in that header but whenever I’m trying to send multiple values in it
Teja_0-1675767130076.png

Getting error like this:

"OASValidation OpenAPI-Spec-Validation-1 with resource \"oas://OpenAPI-Spec-Validation-1.yaml\": failed with reason: \"[ERROR - Parameter 'X-My-Header' expected an array style of 'simple' [explode=false].: []]\""

I got to know that for headers default serialization method is simple style with

explode=false which means comma-separated values But even when Im sending in that way also getting error

Here is the spec parameter part: (using spec version 3.0.1)

X-My-Header:
      name: X-My-Header
      in: header
      description: test
      required: true
      schema:
        type: array
        items:
          type: number
          enum: 
            - 1
            - 2

Please help me here. Thanks in advance

2 Likes

I’m sending in the same format only which u mentioned but still getting the same error from OAS policy.

Teja_0-1676266974840.png

Hello @kurtkanaskie , @dchiesa1 I have the same issue as well, is there an issue with this function? any help is appreciated.

I just tested this using your exact parameter in my Apigee X org and it’s working as expected (“runtimeVersion”: “1-11-0-apigee-8”).

curl "https://$HOST/oas/v3/persons?required=ok" --header 'x-my-header: 2'
OK

curl "https://$HOST/oas/v3/persons?required=ok" --header 'x-my-header: 3'
{
  "fault": {
    "faultstring": "OASValidation OAS-ValidateRequestYAML with resource \"oas://persons_oas_v3.yaml\": failed with reason: \"[ERROR - Instance value (3) not found in enum (possible values: [1,2]): []]\"",
    "detail": {
      "errorcode": "steps.oasvalidation.Failed"
    }
  }
}

@Teja Did you try setting explode property to true ?

X-My-Header:
      name: X-My-Header
      in: header
      description: test
      required: true
      style: simple
      explode: true
      schema:
        type: array
        items:
          type: number
          enum: 
            - 1
            - 2

Hi @Teja Now i am facing the same issue…did you find the solution for this?

This worked for me

components:
  parameters:
    x-required:
      name: X-Required
      in: header
      description: test Required header
      required: true
      schema:
        type: array
        items:
          type: number
          enum: 
            - 1
            - 2

And gave me this error when I sent 3 in the header

{
    "fault": {
        "faultstring": "OASValidation OAS-ValidateRequestYAML with resource \"oas://persons_oas_v3.yaml\": failed with reason: \"[ERROR - Instance value (3) not found in enum (possible values: [1,2]): []]\"",
        "detail": {
            "errorcode": "steps.oasvalidation.Failed"
        }
    }
}

It also worked when I made the array a string and quoted the numbers in the OAS

components:
  parameters:
    x-required:
      name: x-required
      in: header
      description: test Required header
      required: true
      schema:
        type: array
        items:
          type: string
          enum: 
            - "1"
            - "2"

Then I get this error:

{
    "fault": {
        "faultstring": "OASValidation OAS-ValidateRequestYAML with resource \"oas://persons_oas_v3.yaml\": failed with reason: \"[ERROR - Instance value (\"3\") not found in enum (possible values: [\"1\",\"2\"]): []]\"",
        "detail": {
            "errorcode": "steps.oasvalidation.Failed"
        }
    }
}

I’m sending header as: curl $URL --header ‘x-required: 3’

My policy

<OASValidation continueOnError="false" enabled="true" name="OAS-ValidateRequestYAML">
  <Source>request</Source>
  <OASResource>oas://persons_oas_v3.yaml</OASResource>
  <Options>
    <ValidateMessageBody>true</ValidateMessageBody>
    <AllowUnspecifiedParameters>
      <Header>true</Header>
      <Query>true</Query>
    </AllowUnspecifiedParameters>
  </Options>
</OASValidation>