Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit e0a126e

Browse files
committed
sanity check for nested resources
1 parent b1bca0c commit e0a126e

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

BootGen/Api.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ public Api(ResourceCollection resourceCollection, ControllerCollection controlle
2323
foreach (var resource in Resources)
2424
{
2525
if (resource.Pivot != null && resource.RootResource == null) {
26-
throw new Exception($"{resource.Name} is declared as a Many-To-Many nested resource on {resource.ParentResource.Name}, but is does not have an associated root resource.");
26+
throw new Exception($"{resource.Name.Plural} is declared as a Many-To-Many nested resource on {resource.ParentResource.Name.Plural}, but is does not have an associated root resource.");
2727
}
2828
if (resource.RootResource != null && resource.RootResource.Class != resource.Class) {
29-
throw new Exception($"Type mismatch: ${resource.Name} has type ${resource.Class.Name}, but its associated root resource has type {resource.RootResource.Class.Name}");
29+
throw new Exception($"Type mismatch: ${resource.Name.Plural} has type ${resource.Class.Name}, but its associated root resource has type {resource.RootResource.Class.Name}");
30+
}
31+
if (resource.ParentResource != null) {
32+
var property = resource.ParentResource.Class.Properties.FirstOrDefault(p => p.Name == resource.Name.Plural);
33+
if (property == null || !property.IsCollection || property.Class != resource.Class || !property.IsClientOnly) {
34+
throw new Exception($"{resource.Name.Plural} is declared as a nested resource on {resource.ParentResource.Name.Plural}, but the {resource.ParentResource.Class.Name} class does not " +
35+
$"have a client-only property with the following signature: public List<{resource.Class.Name}> {resource.Name.Plural} {{ get; set; }}");
36+
}
3037
}
3138
Routes.AddRange(resource.GetRoutes());
3239
if (resource.Pivot == null)

0 commit comments

Comments
 (0)