简体   繁体   中英

Azure API Management policy: validate request body against json schema

I am trying to implement a content validation policy in Azure API management. I created a schema named event .

The policy looks like this:

<validate-content unspecified-content-type-action="prevent" max-size="12000" size-exceeded-action="prevent" errors-variable-name="validationErrors">
    <content type="application/json" validate-as="json" action="prevent" schema-id="event" schema-ref="#/components/schemas/event" />
</validate-content>

When I try to test it, I get an error message in trace saying that the schema reference is wrong:

"details": "Could not resolve schema reference '#/components/schemas/event'. Path '', line 1, position 1."

Documentation says:

<content type="content type string" validate-as="json|xml|soap" schema-id="schema id" schema-ref="#/local/reference/path" action="ignore|prevent|detect" />

But I didn't find any clue how to find the schema-id and the schema-ref attributes.

When I open the schema there's nothing like this on the screen neither in the "Overview" nor under "Properties". Please someone tell me how to fill these to make the policy working. Or, if it exists, point me to the documentation where I can read it:)

schema-id and schema-ref both are optional attributes for validating request body against json schema.

As per this Azure API Management validation policies | Microsoft Docs :

schema-id: Name of an existing schema that was added to the API Management instance for content validation. If not specified, the default schema from the API definition is used.
schema-ref: For a JSON schema specified in schema-id , optional reference to a valid local reference path in the JSON document. Example: #/components/schemas/address . The attribute should return a JSON object that API Management handles as a valid JSON schema.

Make sure to check Azure API Management validation policies | Microsoft Docs schemas for content validation, provide correct schema location whether you are importing from a file or URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM