Skip to content

Commit 80a7f7d

Browse files
CopilotJerryNixonAniruddh25aaronburtle
authored
feat: dab init defaults runtime.rest.request-body-strict to false (#3166)
## Why make this change? `dab init` generated configs with `request-body-strict: true`, causing REST endpoints to reject requests with extra/unmapped fields by default. This added friction for new users and modern scenarios where flexible request bodies are preferred. ## What is this change? - **`ConfigGenerator.cs`**: Changed the `RestRequestBodyStrict` defaulting logic from `CliBool.False ? false : true` to `CliBool.True ? true : false` — when `--rest.request-body-strict` is omitted, the generated config now writes `false` - **`RestRuntimeOptions.cs`**: The record default (`RequestBodyStrict = true`) is preserved for backward compatibility — existing configs that omit this field continue to behave as before. Rewrote XML doc to be internally consistent: `true` rejects extraneous/unmapped fields; `false` allows and ignores them. Includes a note distinguishing the record default (`true`, for backward compat) from the `dab init` generated default (`false`). - **`InitOptions.cs`**: Updated `--rest.request-body-strict` help text to `"(Default: false) When true, rejects extraneous/unmapped fields in the REST request body. When false, allows and ignores them."` and replaced the stale preceding code comment with a clear description of both modes. - Snapshot files and hardcoded expected JSON in `ConfigGeneratorTests` updated to reflect the new generated default - **`config-generators/*.txt`**: Added `--rest.request-body-strict true` explicitly to `dab init` commands in `mssql-commands.txt`, `mysql-commands.txt`, `postgresql-commands.txt`, and `dwsql-commands.txt` — these scripts regenerate integration test config files during CI builds, and those configs must retain strict mode (`true`) for integration tests that validate extraneous-field rejection behavior - **`ConfigurationTests.TestReadingRuntimeConfigForCosmos.verified.txt`**: Updated snapshot to set `RequestBodyStrict: false` to reflect the new default ## How was this tested? - [x] Integration Tests - Config-generator command files updated to keep integration test configs in strict mode, preserving all existing integration test behavior (e.g. `PutOneTestWithExtraneousFieldsInRequestBody`) - [x] Unit Tests - `TestRestRequestBodyStrictMode` — updated `DataRow` for the no-flag case to assert `false` - `ConfigGeneratorTests.TestSpecialCharactersInConnectionString` — updated expected JSON - All 30 `InitTests` snapshots and 7 `EndToEndTests` snapshots (those that invoke `dab init` without the flag) updated to `RequestBodyStrict: false` - `ConfigurationTests.TestReadingRuntimeConfigForCosmos` snapshot updated to `RequestBodyStrict: false` - `AddEntityTests` and `UpdateEntityTests` snapshots intentionally unchanged — those use pre-built config strings, not `dab init`, and correctly reflect the record default of `true` ## Sample Request(s) ```bash dab init --database-type mssql --connection-string "@env('conn')" ``` Generated `dab-config.json` runtime section: ```json "rest": { "enabled": true, "path": "/api", "request-body-strict": false } ``` <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>dab init to default runtime.rest.request-body-strict to false </issue_title> > <issue_description>## What? > > When `dab init` is run, update its behavior to default `runtime.rest.request-body-strict` to `false` in the generated config. This will allow REST request bodies to accept and ignore additional fields by default, making development smoother and reducing unexpected errors. > > ## Why? > > Currently, `dab init` in the CLI generates a `dab-config.json` where the `runtime.rest.request-body-strict` option defaults to `true` (strict mode). This means all extraneous/unmapped fields in REST request bodies are rejected by default, including keys. This can cause confusion for new users and adds friction for modern scenarios where flexible request bodies are preferred, especially with C# developers.</issue_description> > > <agent_instructions>Introduce as little change as possible</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #3165 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/Azure/data-api-builder/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: JerryNixon <[email protected]> Co-authored-by: Aniruddh Munde <[email protected]> Co-authored-by: Aniruddh25 <[email protected]> Co-authored-by: aaronburtle <[email protected]>
1 parent 3199765 commit 80a7f7d

47 files changed

Lines changed: 51 additions & 51 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config-generators/dwsql-commands.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
init --config "dab-config.DwSql.json" --database-type dwsql --set-session-context true --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --cors-origin "http://localhost:5000"
1+
init --config "dab-config.DwSql.json" --database-type dwsql --set-session-context true --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --cors-origin "http://localhost:5000" --rest.request-body-strict true
22
add Publisher --config "dab-config.DwSql.json" --source publishers --permissions "anonymous:read" --source.key-fields "id"
33
add Stock --config "dab-config.DwSql.json" --source stocks --permissions "anonymous:create,read,update,delete" --source.key-fields "categoryid,pieceid"
44
add stocks_price --config "dab-config.DwSql.json" --source stocks_price --permissions "authenticated:create,read,update,delete" --source.key-fields "categoryid,pieceid,instant"

config-generators/mssql-commands.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
init --config "dab-config.MsSql.json" --database-type mssql --set-session-context true --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --cors-origin "http://localhost:5000" --graphql.multiple-create.enabled true
1+
init --config "dab-config.MsSql.json" --database-type mssql --set-session-context true --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --cors-origin "http://localhost:5000" --graphql.multiple-create.enabled true --rest.request-body-strict true
22
add Publisher --config "dab-config.MsSql.json" --source publishers --permissions "anonymous:read"
33
add Publisher_MM --config "dab-config.MsSql.json" --source publishers_mm --graphql "Publisher_MM:Publishers_MM" --permissions "anonymous:*"
44
add Stock --config "dab-config.MsSql.json" --source stocks --permissions "anonymous:create,read,update,delete"

config-generators/mysql-commands.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;uid=root;pwd=REPLACEME" --host-mode Development --cors-origin "http://localhost:5000"
1+
init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;uid=root;pwd=REPLACEME" --host-mode Development --cors-origin "http://localhost:5000" --rest.request-body-strict true
22
add Publisher --config "dab-config.MySql.json" --source publishers --permissions "anonymous:read"
33
add Stock --config "dab-config.MySql.json" --source stocks --permissions "anonymous:create,read,update,delete"
44
add Book --config "dab-config.MySql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books"

config-generators/postgresql-commands.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --cors-origin "http://localhost:5000"
1+
init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --cors-origin "http://localhost:5000" --rest.request-body-strict true
22
add Publisher --config "dab-config.PostgreSql.json" --source publishers --permissions "anonymous:read"
33
add Stock --config "dab-config.PostgreSql.json" --source stocks --permissions "anonymous:create,read,update,delete"
44
add Book --config "dab-config.PostgreSql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books"

src/Cli.Tests/ConfigGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void TestSpecialCharactersInConnectionString()
156156
""rest"": {
157157
""enabled"": true,
158158
""path"": ""/api"",
159-
""request-body-strict"": true
159+
""request-body-strict"": false
160160
},
161161
""graphql"": {
162162
""enabled"": true,

src/Cli.Tests/EndToEndTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ public void TestEnabledDisabledFlagsForApis(
12241224
[DataTestMethod]
12251225
[DataRow(true, false, DisplayName = "dab init command specifies --rest.request-body-strict as false - REST request body allows extraneous fields.")]
12261226
[DataRow(true, true, DisplayName = "dab init command specifies --rest.request-body-strict as true - REST request body doesn't allow extraneous fields.")]
1227-
[DataRow(false, true, DisplayName = "dab init command does not include --rest.request-body-strict flag. The default behavior is followed - REST request body doesn't allow extraneous fields.")]
1227+
[DataRow(false, false, DisplayName = "dab init command does not include --rest.request-body-strict flag. The default behavior is followed - REST request body allows extraneous fields.")]
12281228
public void TestRestRequestBodyStrictMode(bool includeRestRequestBodyStrictFlag, bool isRequestBodyStrict)
12291229
{
12301230
string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--host-mode", "development", "--database-type", "mssql",

src/Cli.Tests/Snapshots/EndToEndTests.TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Rest: {
1010
Enabled: true,
1111
Path: /api,
12-
RequestBodyStrict: true
12+
RequestBodyStrict: false
1313
},
1414
GraphQL: {
1515
Enabled: true,

src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Rest: {
1010
Enabled: true,
1111
Path: /api,
12-
RequestBodyStrict: true
12+
RequestBodyStrict: false
1313
},
1414
GraphQL: {
1515
Enabled: true,

src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Rest: {
1010
Enabled: true,
1111
Path: /api,
12-
RequestBodyStrict: true
12+
RequestBodyStrict: false
1313
},
1414
GraphQL: {
1515
Enabled: true,

src/Cli.Tests/Snapshots/EndToEndTests.TestConfigGeneratedAfterAddingEntityWithoutIEnumerables.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Rest: {
1010
Enabled: true,
1111
Path: /api,
12-
RequestBodyStrict: true
12+
RequestBodyStrict: false
1313
},
1414
GraphQL: {
1515
Enabled: true,

0 commit comments

Comments
 (0)