Skip to content

Commit ea4c73c

Browse files
committed
fix: handle required constraints on internal use properties.
1 parent 6ee88e1 commit ea4c73c

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fix `c-admin-editor-page` briefly showing editors while the item is initially loading.
66
- `c-input` no longer wraps default slot fallback content in a superfluous div.
77
- `c-input` no longer attempts to delegate shared-key one-to-one properties to `c-select`, a scenario that is not possible to select values for.
8+
- DTOs no longer generate MapToNew methods with unsatisfied `required` constraints.
89

910
# 6.0.1
1011
- `createAspNetCoreHmrPlugin` now displays NPM package mismatches with the standard vite overlay instead of a custom overlay.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using IntelliTect.Coalesce.DataAnnotations;
2+
3+
namespace IntelliTect.Coalesce.Tests.TargetClasses.TestDbContext;
4+
5+
[Create(SecurityPermissionLevels.DenyAll)]
6+
[Edit(SecurityPermissionLevels.DenyAll)]
7+
public class RequiredInternalUseModel
8+
{
9+
public int Id { get; set; }
10+
11+
[InternalUse]
12+
public required string InternalRequiredProp { get; init; }
13+
}

src/IntelliTect.Coalesce.Tests/TargetClasses/TestDbContext/TestDbContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AppDbContext : DbContext
1919
public DbSet<ComplexModelDependent> ComplexModelDependents { get; set; }
2020
public DbSet<ReadOnlyEntityUsedAsMethodInput> ReadOnlyEntityUsedAsMethodInputs { get; set; }
2121
public DbSet<RequiredAndInitModel> RequiredAndInitModels { get; set; }
22+
public DbSet<RequiredInternalUseModel> RequiredInternalUseModels { get; set; }
2223
public DbSet<Test> Tests { get; set; }
2324

2425
public DbSet<AbstractModel> AbstractModels { get; set; }

src/IntelliTect.Coalesce/TypeDefinition/MethodViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ public ConstructorUsage DtoMapToNewConstructorUsage
340340
#if NET7_0_OR_GREATER
341341
if (!this.HasAttribute<System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute>())
342342
{
343-
foreach (var requiredProp in Parent.ClientProperties.Where(p => p.HasRequiredKeyword))
343+
foreach (var requiredProp in Parent.Properties.Where(p => p.HasRequiredKeyword))
344344
{
345345
if (!incomingProperties.ContainsKey(requiredProp.Name))
346346
{
347347
return new ConstructorUsage
348348
{
349349
IsAcceptable = false,
350350
Reason = $"Required property `{requiredProp.Name}` is not accepted as an input, " +
351-
$"so Coalesce cannnot satisfy its `required` constraint. Adding [SetsRequiredMembers] will suppress this."
351+
$"so Coalesce cannot satisfy its `required` constraint. Adding [SetsRequiredMembers] will suppress this."
352352
};
353353
}
354354
}

0 commit comments

Comments
 (0)