You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding support for positive boolean options in CLI (#1686)
## Why make this change?
To adjust CLI boolean options to properly allow true/false values as
per: #1679
## What is this change?
1. Added new options - `--rest.enabled` and `--graphql.enabled` to `dab
init` options.
2. Introduce an enum `CliBool` with values - `None`,`True`,`False`, to
represent boolean options in CLI. When the option is omitted from the
init command, the value of `CliBool.None` would be assigned to the
option, or else appropriate `True`/`False` value would be parset out and
assigned to the option.
2. When both positive and negative flags are included in the init
command then:
- Config generation fails when the semantics differ.
- If the semantics match, then appropriate value is assigned to
`Runtime.Rest.Enabled`/`Runtime.GraphQL.Enabled` properties.
3. When only one of `--rest.enabled`/`--rest.disabled ` (or
corresponding flags for graphql) option is included in the init command,
the value assigned to that option is honored.
## How was this tested?
- [x] Unit Tests - are added via
`EndToEndTests.TestEnabledDisabledFlagsForApis` test confirming the
behavior for different cases.
[DataRow(ApiType.REST,false,false,true,true,DisplayName="Validate that REST endpoint is enabled when both enabled and disabled options are omitted from the init command.")]
774
+
[DataRow(ApiType.REST,false,true,true,true,DisplayName="Validate that REST endpoint is enabled when enabled option is set to true and disabled option is omitted from the init command.")]
775
+
[DataRow(ApiType.REST,true,false,true,false,DisplayName="Validate that REST endpoint is disabled when enabled option is omitted and disabled option is included in the init command.")]
776
+
[DataRow(ApiType.REST,true,true,false,false,DisplayName="Validate that REST endpoint is disabled when enabled option is set to false and disabled option is included in the init command.")]
777
+
[DataRow(ApiType.REST,true,true,true,true,true,DisplayName="Validate that config generation fails when enabled and disabled options provide conflicting values for REST endpoint.")]
778
+
[DataRow(ApiType.GraphQL,false,false,true,true,DisplayName="Validate that GraphQL endpoint is enabled when both enabled and disabled options are omitted from the init command.")]
779
+
[DataRow(ApiType.GraphQL,false,true,true,true,DisplayName="Validate that GraphQL endpoint is enabled when enabled option is set to true and disabled option is omitted from the init command.")]
780
+
[DataRow(ApiType.GraphQL,true,false,true,false,DisplayName="Validate that GraphQL endpoint is disabled when enabled option is omitted and disabled option is included in the init command.")]
781
+
[DataRow(ApiType.GraphQL,true,true,false,false,DisplayName="Validate that GraphQL endpoint is disabled when enabled option is set to false and disabled option is included in the init command.")]
782
+
[DataRow(ApiType.GraphQL,true,true,true,true,true,DisplayName="Validate that config generation fails when enabled and disabled options provide conflicting values for GraphQL endpoint.")]
Copy file name to clipboardExpand all lines: src/Cli/ConfigGenerator.cs
+63-4Lines changed: 63 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -92,13 +92,33 @@ public static bool TryCreateRuntimeConfig(InitOptions options, FileSystemRuntime
92
92
Dictionary<string,JsonElement>dbOptions=new();
93
93
94
94
HyphenatedNamingPolicynamingPolicy=new();
95
-
boolrestDisabled=options.RestDisabled;
95
+
96
+
// If --rest.disabled flag is included in the init command, we log a warning to not use this flag as it will be deprecated in future versions of DAB.
97
+
if(options.RestDisabledistrue)
98
+
{
99
+
_logger.LogWarning("The option --rest.disabled will be deprecated and support for the option will be removed in future versions of Data API builder."+
100
+
" We recommend that you use the --rest.enabled option instead.");
101
+
}
102
+
103
+
// If --graphql.disabled flag is included in the init command, we log a warning to not use this flag as it will be deprecated in future versions of DAB.
104
+
if(options.GraphQLDisabledistrue)
105
+
{
106
+
_logger.LogWarning("The option --graphql.disabled will be deprecated and support for the option will be removed in future versions of Data API builder."+
107
+
" We recommend that you use the --graphql.enabled option instead.");
@@ -221,6 +241,45 @@ public static bool TryCreateRuntimeConfig(InitOptions options, FileSystemRuntime
221
241
returntrue;
222
242
}
223
243
244
+
/// <summary>
245
+
/// Helper method to determine if the api is enabled or not based on the enabled/disabled options in the dab init command.
246
+
/// The method also validates that there is no mismatch in semantics of enabling/disabling the REST/GraphQL API(s)
247
+
/// based on the values supplied in the enabled/disabled options for the API in the init command.
248
+
/// </summary>
249
+
/// <param name="apiDisabledOptionValue">Value of disabled option as in the init command. If the option is omitted in the command, default value is assigned.</param>
250
+
/// <param name="apiEnabledOptionValue">Value of enabled option as in the init command. If the option is omitted in the command, default value is assigned.</param>
0 commit comments