Commit a4505f8
Remove whitespaces from autoentity-generated names to prevent invalid REST paths and GraphQL singular/plural tables for SQL objects with spaces (#3609)
## Why make this change?
Tables with whitespace in names (for example, `Order Items`) were being
auto-generated into entity names like `dbo_Order Items`, which then
produced invalid REST paths as well as invalid GraphQL names for
singular/plural tables which failed config validation. This change
ensures autoentity name generation does not pass whitespace through to
REST path and GraphQL singular/plural tables defaults.
- Autoentity naming currently interpolates `{schema}` / `{object}`
verbatim; whitespace in object names breaks `dab validate`.
## What is this change?
- **Autoentity name normalization (MsSql metadata path)**
- Added `RemoveWhitespaceAddCamelCase` in `SqlMetadataProvider` and
applied it to generated `entity_name` before entity creation. The method
name is intentionally specific to clarify it only removes whitespace
(not other invalid characters).
- Normalization removes whitespace and uppercases the character
immediately following each removed whitespace (camelCase-join), e.g.
`dbo_Order Items` → `dbo_OrderItems`.
- Added a guard after normalization: if the result is empty (e.g. the
raw entity name was entirely whitespace), an error is logged with the
original name and schema for context, and the entry is skipped.
- Collision detection is improved: when `TryAdd` fails because two
database objects normalize to the same entity name (e.g. `"Order Item"`
and `"OrderItem"` both yield `"OrderItem"`), the exception message
includes the pre-normalization name and schema to make the collision
diagnosable.
```csharp
protected static string RemoveWhitespaceAddCamelCase(string name)
{
StringBuilder result = new(name.Length);
bool capitalizeNext = false;
foreach (char character in name)
{
if (char.IsWhiteSpace(character))
{
capitalizeNext = true;
continue;
}
result.Append(capitalizeNext ? char.ToUpperInvariant(character) : character);
capitalizeNext = false;
}
return result.ToString();
}
```
- **Focused test coverage**
- Added a dedicated `TestAutoentitiesGeneratedWithSpacesInObjectName`
test method that explicitly asserts the sanitized entity name
`dbo_OrderItems` (via `const string EXPECTED_ENTITY_NAME`) and validates
end-to-end REST and GraphQL access with that name.
- Whitespace-handling validation is now separated from the non-default
schema cases in `TestAutoentitiesGeneratedWithUnusualElements` for
better readability and maintainability.
## How was this tested?
- [ ] Integration Tests
- [x] Unit Tests
## Sample Request(s)
- Example CLI usage to reproduce/validate behavior:
- `dab auto-config add mydef --patterns.include "dbo.Order Items"
--patterns.name "{schema}_{object}"`
- `dab validate`
- Expected generated entity naming behavior:
- SQL object: `dbo.[Order Items]`
- Generated entity/REST path segment: `dbo_OrderItems` (no whitespace)
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Co-authored-by: Ruben Cerna <rcernaserna@microsoft.com>
Co-authored-by: Souvik Ghosh <souvikofficial04@gmail.com>
Co-authored-by: Anusha Kolan <anushakolan10@gmail.com>1 parent fba075a commit a4505f8
4 files changed
Lines changed: 212 additions & 23 deletions
File tree
- src
- Core/Services/MetadataProviders
- Service.Tests
- Configuration
Lines changed: 37 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
342 | 363 | | |
343 | 364 | | |
344 | 365 | | |
| |||
360 | 381 | | |
361 | 382 | | |
362 | 383 | | |
| 384 | + | |
| 385 | + | |
363 | 386 | | |
364 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
365 | 394 | | |
366 | | - | |
| 395 | + | |
367 | 396 | | |
368 | 397 | | |
369 | 398 | | |
370 | 399 | | |
371 | 400 | | |
| 401 | + | |
372 | 402 | | |
373 | 403 | | |
374 | 404 | | |
| |||
384 | 414 | | |
385 | 415 | | |
386 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
387 | 423 | | |
388 | 424 | | |
389 | 425 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
722 | 722 | | |
723 | 723 | | |
724 | 724 | | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
725 | 752 | | |
726 | 753 | | |
727 | 754 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5882 | 5882 | | |
5883 | 5883 | | |
5884 | 5884 | | |
| 5885 | + | |
| 5886 | + | |
| 5887 | + | |
| 5888 | + | |
| 5889 | + | |
| 5890 | + | |
| 5891 | + | |
| 5892 | + | |
| 5893 | + | |
| 5894 | + | |
| 5895 | + | |
| 5896 | + | |
| 5897 | + | |
| 5898 | + | |
| 5899 | + | |
| 5900 | + | |
| 5901 | + | |
| 5902 | + | |
| 5903 | + | |
| 5904 | + | |
| 5905 | + | |
| 5906 | + | |
| 5907 | + | |
| 5908 | + | |
| 5909 | + | |
| 5910 | + | |
| 5911 | + | |
| 5912 | + | |
| 5913 | + | |
| 5914 | + | |
| 5915 | + | |
| 5916 | + | |
| 5917 | + | |
| 5918 | + | |
| 5919 | + | |
| 5920 | + | |
| 5921 | + | |
| 5922 | + | |
| 5923 | + | |
| 5924 | + | |
| 5925 | + | |
| 5926 | + | |
| 5927 | + | |
| 5928 | + | |
| 5929 | + | |
| 5930 | + | |
| 5931 | + | |
| 5932 | + | |
| 5933 | + | |
| 5934 | + | |
| 5935 | + | |
| 5936 | + | |
| 5937 | + | |
| 5938 | + | |
| 5939 | + | |
| 5940 | + | |
| 5941 | + | |
| 5942 | + | |
| 5943 | + | |
| 5944 | + | |
| 5945 | + | |
| 5946 | + | |
| 5947 | + | |
| 5948 | + | |
| 5949 | + | |
| 5950 | + | |
| 5951 | + | |
| 5952 | + | |
| 5953 | + | |
| 5954 | + | |
| 5955 | + | |
| 5956 | + | |
| 5957 | + | |
| 5958 | + | |
| 5959 | + | |
| 5960 | + | |
| 5961 | + | |
| 5962 | + | |
| 5963 | + | |
| 5964 | + | |
| 5965 | + | |
| 5966 | + | |
| 5967 | + | |
| 5968 | + | |
| 5969 | + | |
| 5970 | + | |
| 5971 | + | |
| 5972 | + | |
| 5973 | + | |
| 5974 | + | |
| 5975 | + | |
| 5976 | + | |
| 5977 | + | |
| 5978 | + | |
| 5979 | + | |
| 5980 | + | |
| 5981 | + | |
| 5982 | + | |
| 5983 | + | |
| 5984 | + | |
| 5985 | + | |
| 5986 | + | |
| 5987 | + | |
| 5988 | + | |
| 5989 | + | |
| 5990 | + | |
| 5991 | + | |
| 5992 | + | |
| 5993 | + | |
| 5994 | + | |
| 5995 | + | |
| 5996 | + | |
5885 | 5997 | | |
5886 | 5998 | | |
5887 | 5999 | | |
| |||
5895 | 6007 | | |
5896 | 6008 | | |
5897 | 6009 | | |
5898 | | - | |
| 6010 | + | |
5899 | 6011 | | |
5900 | 6012 | | |
5901 | 6013 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
309 | 311 | | |
310 | 312 | | |
311 | 313 | | |
312 | | - | |
313 | | - | |
| 314 | + | |
314 | 315 | | |
315 | 316 | | |
316 | 317 | | |
317 | 318 | | |
318 | | - | |
319 | | - | |
| 319 | + | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
339 | 339 | | |
340 | 340 | | |
341 | | - | |
342 | | - | |
| 341 | + | |
343 | 342 | | |
344 | 343 | | |
345 | 344 | | |
| |||
348 | 347 | | |
349 | 348 | | |
350 | 349 | | |
351 | | - | |
352 | | - | |
| 350 | + | |
353 | 351 | | |
354 | 352 | | |
355 | 353 | | |
| |||
394 | 392 | | |
395 | 393 | | |
396 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
397 | 405 | | |
398 | 406 | | |
399 | 407 | | |
| |||
826 | 834 | | |
827 | 835 | | |
828 | 836 | | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
0 commit comments