Skip to content

Commit 39800fb

Browse files
Merge pull request #210717 from dlepow/addprop
[APIM] Add allow-additional-properties attribute to validation policy
2 parents e5e33fa + 64bd3be commit 39800fb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

articles/api-management/validation-policies.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentationcenter: ''
66
author: dlepow
77
ms.service: api-management
88
ms.topic: reference
9-
ms.date: 06/07/2022
9+
ms.date: 09/09/2022
1010
ms.author: danlep
1111
---
1212

@@ -79,7 +79,7 @@ The following table shows the schema formats and request or response content typ
7979
The policy validates the following content in the request or response against the schema:
8080

8181
* Presence of all required properties.
82-
* Absence of additional properties, if the schema has the `additionalProperties` field set to `false`.
82+
* Presence or absence of additional properties, if the schema has the `additionalProperties` field set. May be overriden with the `allow-additional-properties` attribute.
8383
* Types of all properties. For example, if a schema specifies a property as an integer, the request (or response) must include an integer and not another type, such as a string.
8484
* The format of the properties, if specified in the schema - for example, regex (if the `pattern` keyword is specified), `minimum` for integers, and so on.
8585

@@ -93,22 +93,22 @@ The policy validates the following content in the request or response against th
9393
<content-type-map any-content-type-value="content type string" missing-content-type-value="content type string">
9494
<type from|when="content type string" to="content type string" />
9595
</content-type-map>
96-
<content type="content type string" validate-as="json|xml|soap" schema-id="schema id" schema-ref="#/local/reference/path" action="ignore|prevent|detect" />
96+
<content type="content type string" validate-as="json|xml|soap" schema-id="schema id" schema-ref="#/local/reference/path" action="ignore|prevent|detect" allow-additional-properties="true|false" />
9797
</validate-content>
9898
```
9999

100100
### Examples
101101

102102
#### JSON schema validation
103103

104-
In the following example, API Management interprets requests with an empty content type header or requests with a content type header `application/hal+json` as requests with the content type `application/json`. Then, API Management performs the validation in the detection mode against a schema defined for the `application/json` content type in the API definition. Messages with payloads larger than 100 KB are blocked.
104+
In the following example, API Management interprets requests with an empty content type header or requests with a content type header `application/hal+json` as requests with the content type `application/json`. Then, API Management performs the validation in the detection mode against a schema defined for the `application/json` content type in the API definition. Messages with payloads larger than 100 KB are blocked. Requests containing additional properties are blocked, even if the schema's `additionalProperties` field is configured to allow additional properties.
105105

106106
```xml
107107
<validate-content unspecified-content-type-action="prevent" max-size="102400" size-exceeded-action="prevent" errors-variable-name="requestBodyValidation">
108108
<content-type-map missing-content-type-value="application/json">
109109
<type from="application/hal+json" to="application/json" />
110110
</content-type-map>
111-
<content type="application/json" validate-as="json" action="detect" />
111+
<content type="application/json" validate-as="json" action="detect" allow-additional-properties="false" />
112112
</validate-content>
113113
```
114114

@@ -147,6 +147,7 @@ In the following example, API Management interprets any request as a request wit
147147
| schema-id | Name of an existing schema that was [added](#schemas-for-content-validation) to the API Management instance for content validation. If not specified, the default schema from the API definition is used. | No | N/A |
148148
| 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.<br/><br/> For an XML schema, `schema-ref` isn't supported, and any top-level schema element can be used as the root of the XML request or response payload. The validation checks that all elements starting from the XML request or response payload root adhere to the provided XML schema. | No | N/A |
149149
| action | [Action](#actions) to perform for requests or responses whose body doesn't match the specified content type. | Yes | N/A |
150+
| allow-additional-properties | Boolean. For a JSON schema, specifies whether to implement a runtime override of the `additionalProperties` value configured in the schema: <br> - `true`: allow additional properties in the request or response body, even if the JSON schema's `additionalProperties` field is configured to not allow additional properties. <br> - `false`: do not allow additional properties in the request or response body, even if the JSON schema's `additionalProperties` field is configured to allow additional properties.<br/><br/>If the attribute isn't specified, the policy validates additional properties according to configuration of the `additionalProperties` field in the schema. | No | N/A |
150151

151152
### Schemas for content validation
152153

0 commit comments

Comments
 (0)