@@ -135,7 +135,7 @@ public void CreateDocument(bool doOverrideExistingDocument = false)
135135 string url = string . IsNullOrEmpty ( runtimeBaseRoute ) ? restEndpointPath : runtimeBaseRoute + "/" + restEndpointPath ;
136136 OpenApiComponents components = new ( )
137137 {
138- Schemas = CreateComponentSchemas ( runtimeConfig . Entities , runtimeConfig . DefaultDataSourceName )
138+ Schemas = CreateComponentSchemas ( runtimeConfig . Entities , runtimeConfig . DefaultDataSourceName , runtimeConfig . IsRequestBodyStrict )
139139 } ;
140140
141141 // Collect all entity tags and their descriptions for the top-level tags array
@@ -976,9 +976,14 @@ private static OpenApiMediaType CreateResponseContainer(string responseObjectSch
976976 /// 2) {EntityName}_NoAutoPK -> No auto-generated primary keys present in schema, used for POST requests where PK is not autogenerated and GET (all).
977977 /// 3) {EntityName}_NoPK -> No primary keys present in schema, used for POST requests where PK is autogenerated and GET (all).
978978 /// Schema objects can be referenced elsewhere in the OpenAPI document with the intent to reduce document verbosity.
979+ /// When isRequestBodyStrict is false, request body schemas will have additionalProperties set to true
980+ /// to indicate that extra fields are allowed and will be ignored.
979981 /// </summary>
982+ /// <param name="entities">Runtime entities from configuration.</param>
983+ /// <param name="defaultDataSourceName">Default data source name.</param>
984+ /// <param name="isRequestBodyStrict">Whether extra fields are rejected in request bodies.</param>
980985 /// <returns>Collection of schemas for entities defined in the runtime configuration.</returns>
981- private Dictionary < string , OpenApiSchema > CreateComponentSchemas ( RuntimeEntities entities , string defaultDataSourceName )
986+ private Dictionary < string , OpenApiSchema > CreateComponentSchemas ( RuntimeEntities entities , string defaultDataSourceName , bool isRequestBodyStrict )
982987 {
983988 Dictionary < string , OpenApiSchema > schemas = new ( ) ;
984989 // for rest scenario we need the default datasource name.
@@ -1006,18 +1011,20 @@ private Dictionary<string, OpenApiSchema> CreateComponentSchemas(RuntimeEntities
10061011 if ( dbObject . SourceType is EntitySourceType . StoredProcedure )
10071012 {
10081013 // Request body schema whose properties map to stored procedure parameters
1014+ // When isRequestBodyStrict is false, additionalProperties is set to true to indicate extra fields are allowed.
10091015 DatabaseStoredProcedure spObject = ( DatabaseStoredProcedure ) dbObject ;
1010- schemas . Add ( entityName + SP_REQUEST_SUFFIX , CreateSpRequestComponentSchema ( fields : spObject . StoredProcedureDefinition . Parameters ) ) ;
1016+ schemas . Add ( entityName + SP_REQUEST_SUFFIX , CreateSpRequestComponentSchema ( fields : spObject . StoredProcedureDefinition . Parameters , allowAdditionalProperties : ! isRequestBodyStrict ) ) ;
10111017
10121018 // Response body schema whose properties map to the stored procedure's first result set columns
10131019 // as described by sys.dm_exec_describe_first_result_set.
1014- schemas . Add ( entityName + SP_RESPONSE_SUFFIX , CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities ) ) ;
1020+ schemas . Add ( entityName + SP_RESPONSE_SUFFIX , CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities , allowAdditionalProperties : false ) ) ;
10151021 }
10161022 else
10171023 {
10181024 // Create component schema for FULL entity with all primary key columns (included auto-generated)
10191025 // which will typically represent the response body of a request or a stored procedure's request body.
1020- schemas . Add ( entityName , CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities ) ) ;
1026+ // When isRequestBodyStrict is false, additionalProperties is set to true to indicate extra fields are allowed.
1027+ schemas . Add ( entityName , CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities , allowAdditionalProperties : ! isRequestBodyStrict ) ) ;
10211028
10221029 // Create an entity's request body component schema excluding autogenerated primary keys.
10231030 // A POST request requires any non-autogenerated primary key references to be in the request body.
@@ -1037,7 +1044,8 @@ private Dictionary<string, OpenApiSchema> CreateComponentSchemas(RuntimeEntities
10371044 }
10381045 }
10391046
1040- schemas . Add ( $ "{ entityName } _NoAutoPK", CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities ) ) ;
1047+ // When isRequestBodyStrict is false, additionalProperties is set to true to indicate extra fields are allowed.
1048+ schemas . Add ( $ "{ entityName } _NoAutoPK", CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities , allowAdditionalProperties : ! isRequestBodyStrict ) ) ;
10411049
10421050 // Create an entity's request body component schema excluding all primary keys
10431051 // by removing the tracked non-autogenerated primary key column names and removing them from
@@ -1053,7 +1061,8 @@ private Dictionary<string, OpenApiSchema> CreateComponentSchemas(RuntimeEntities
10531061 }
10541062 }
10551063
1056- schemas . Add ( $ "{ entityName } _NoPK", CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities ) ) ;
1064+ // When isRequestBodyStrict is false, additionalProperties is set to true to indicate extra fields are allowed.
1065+ schemas . Add ( $ "{ entityName } _NoPK", CreateComponentSchema ( entityName , fields : exposedColumnNames , metadataProvider , entities , allowAdditionalProperties : ! isRequestBodyStrict ) ) ;
10571066 }
10581067 }
10591068
@@ -1068,8 +1077,9 @@ private Dictionary<string, OpenApiSchema> CreateComponentSchemas(RuntimeEntities
10681077 /// </summary>
10691078 /// </summary>
10701079 /// <param name="fields">Collection of stored procedure parameter metadata.</param>
1080+ /// <param name="allowAdditionalProperties">When true, sets additionalProperties to true indicating extra fields are allowed.</param>
10711081 /// <returns>OpenApiSchema object representing a stored procedure's request body.</returns>
1072- private static OpenApiSchema CreateSpRequestComponentSchema ( Dictionary < string , ParameterDefinition > fields )
1082+ private static OpenApiSchema CreateSpRequestComponentSchema ( Dictionary < string , ParameterDefinition > fields , bool allowAdditionalProperties )
10731083 {
10741084 Dictionary < string , OpenApiSchema > properties = new ( ) ;
10751085 HashSet < string > required = new ( ) ;
@@ -1097,7 +1107,8 @@ private static OpenApiSchema CreateSpRequestComponentSchema(Dictionary<string, P
10971107 {
10981108 Type = SCHEMA_OBJECT_TYPE ,
10991109 Properties = properties ,
1100- Required = required
1110+ Required = required ,
1111+ AdditionalPropertiesAllowed = allowAdditionalProperties
11011112 } ;
11021113
11031114 return schema ;
@@ -1115,10 +1126,11 @@ private static OpenApiSchema CreateSpRequestComponentSchema(Dictionary<string, P
11151126 /// <param name="fields">List of mapped (alias) field names.</param>
11161127 /// <param name="metadataProvider">Metadata provider for database objects.</param>
11171128 /// <param name="entities">Runtime entities from configuration.</param>
1129+ /// <param name="allowAdditionalProperties">When true, sets additionalProperties to true indicating extra fields are allowed.</param>
11181130 /// <exception cref="DataApiBuilderException">Raised when an entity's database metadata can't be found,
11191131 /// indicating a failure due to the provided entityName.</exception>
11201132 /// <returns>Entity's OpenApiSchema representation.</returns>
1121- private static OpenApiSchema CreateComponentSchema ( string entityName , HashSet < string > fields , ISqlMetadataProvider metadataProvider , RuntimeEntities entities )
1133+ private static OpenApiSchema CreateComponentSchema ( string entityName , HashSet < string > fields , ISqlMetadataProvider metadataProvider , RuntimeEntities entities , bool allowAdditionalProperties )
11221134 {
11231135 if ( ! metadataProvider . EntityToDatabaseObject . TryGetValue ( entityName , out DatabaseObject ? dbObject ) || dbObject is null )
11241136 {
@@ -1166,7 +1178,8 @@ private static OpenApiSchema CreateComponentSchema(string entityName, HashSet<st
11661178 {
11671179 Type = SCHEMA_OBJECT_TYPE ,
11681180 Properties = properties ,
1169- Description = entityConfig ? . Description
1181+ Description = entityConfig ? . Description ,
1182+ AdditionalPropertiesAllowed = allowAdditionalProperties
11701183 } ;
11711184
11721185 return schema ;
0 commit comments