Skip to content

Commit d280125

Browse files
CopilotJerryNixon
andcommitted
Address PR feedback: null-safe error message, clearer error text, document prefix matching
Co-authored-by: JerryNixon <[email protected]>
1 parent 127c3f2 commit d280125

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/Core/Configurations/RuntimeConfigValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ private static void ValidateRestPathSettingsForEntity(string entityName, string
676676
if (!RuntimeConfigValidatorUtil.TryValidateEntityRestPath(pathForEntity, out string? errorMessage))
677677
{
678678
throw new DataApiBuilderException(
679-
message: $"The rest path: {pathForEntity} for entity: {entityName} {errorMessage}",
679+
message: $"The rest path: {pathForEntity} for entity: {entityName} {errorMessage ?? "contains invalid characters."}",
680680
statusCode: HttpStatusCode.ServiceUnavailable,
681681
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError
682682
);

src/Core/Configurations/RuntimeConfigValidatorUtil.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ public static bool TryValidateEntityRestPath(string entityRestPath, out string?
124124

125125
if (_reservedUriCharsRgx.IsMatch(segment))
126126
{
127-
errorMessage = "contains characters that are not allowed in URL paths. " +
128-
"Valid paths contain only alphanumeric characters, hyphens (-), and underscores (_), " +
129-
"with forward slashes (/) as path separators.";
127+
errorMessage = "contains reserved characters that are not allowed in URL paths.";
130128
return false;
131129
}
132130
}

src/Core/Services/RestService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ public bool TryGetRestRouteFromConfig([NotNullWhen(true)] out string? configured
439439
/// For example, a request route should be of the form
440440
/// {EntityPath}/{PKColumn}/{PkValue}/{PKColumn}/{PKValue}...
441441
/// or {SubDir}/.../{EntityPath}/{PKColumn}/{PkValue}/{PKColumn}/{PKValue}...
442+
///
443+
/// Note: Uses shortest-prefix matching. When multiple entity paths could match,
444+
/// the shortest matching path takes precedence. For example, if both "api" and
445+
/// "api/books" are valid entity paths, a request to "/api/books/id/1" will match
446+
/// "api" with primaryKeyRoute "books/id/1". Configure unique, non-overlapping
447+
/// paths to avoid ambiguity.
442448
/// </summary>
443449
/// <param name="routeAfterPathBase">The request route (no '/' prefix) containing the entity path
444450
/// (and optionally primary key).</param>

src/Service.Tests/UnitTests/ConfigValidationUnitTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,13 +2070,13 @@ public void ValidateRestMethodsForEntityInConfig(
20702070
DisplayName = "Rest path for an entity containing reserved character ? fails config validation.")]
20712071
[DataRow(true, "EntityA", "entity#RestPath", true, "The rest path: entity#RestPath for entity: EntityA contains '#' which is reserved for URL fragments.",
20722072
DisplayName = "Rest path for an entity containing reserved character # fails config validation.")]
2073-
[DataRow(true, "EntityA", "entity[]RestPath", true, "The rest path: entity[]RestPath for entity: EntityA contains characters that are not allowed in URL paths. Valid paths contain only alphanumeric characters, hyphens (-), and underscores (_), with forward slashes (/) as path separators.",
2073+
[DataRow(true, "EntityA", "entity[]RestPath", true, "The rest path: entity[]RestPath for entity: EntityA contains reserved characters that are not allowed in URL paths.",
20742074
DisplayName = "Rest path for an entity containing reserved character [] fails config validation.")]
2075-
[DataRow(true, "EntityA", "entity+Rest*Path", true, "The rest path: entity+Rest*Path for entity: EntityA contains characters that are not allowed in URL paths. Valid paths contain only alphanumeric characters, hyphens (-), and underscores (_), with forward slashes (/) as path separators.",
2075+
[DataRow(true, "EntityA", "entity+Rest*Path", true, "The rest path: entity+Rest*Path for entity: EntityA contains reserved characters that are not allowed in URL paths.",
20762076
DisplayName = "Rest path for an entity containing reserved character +* fails config validation.")]
20772077
[DataRow(true, "Entity?A", null, true, "The rest path: Entity?A for entity: Entity?A contains '?' which is reserved for query strings in URLs.",
20782078
DisplayName = "Entity name for an entity containing reserved character ? fails config validation.")]
2079-
[DataRow(true, "Entity&*[]A", null, true, "The rest path: Entity&*[]A for entity: Entity&*[]A contains characters that are not allowed in URL paths. Valid paths contain only alphanumeric characters, hyphens (-), and underscores (_), with forward slashes (/) as path separators.",
2079+
[DataRow(true, "Entity&*[]A", null, true, "The rest path: Entity&*[]A for entity: Entity&*[]A contains reserved characters that are not allowed in URL paths.",
20802080
DisplayName = "Entity name containing reserved character &*[] fails config validation.")]
20812081
[DataRow(false, "EntityA", "entityRestPath", true, DisplayName = "Rest path correctly configured as a non-empty string without any reserved characters.")]
20822082
[DataRow(false, "EntityA", "entityRest/?Path", false,

0 commit comments

Comments
 (0)