Skip to content

Commit 8608acb

Browse files
authored
Merge pull request #117 from MarkAtRamp51/feature/supporting-schema-comments
Support for schema comments
2 parents cc8854e + 5c9b119 commit 8608acb

File tree

15 files changed

+113
-16
lines changed

15 files changed

+113
-16
lines changed

src/EntityFrameworkCore.Scaffolding.Handlebars/CodeTemplates/CSharpEntityType/Class.hbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
namespace {{namespace}}
44
{
5-
{{#if class-annotation}}
6-
{{spaces 4}}{{{class-annotation}}}
7-
{{/if}}
5+
{{#if comment}}
6+
/// <summary>
7+
/// {{comment}}
8+
/// </summary>
9+
{{/if}}
10+
{{#if class-annotation}}
11+
{{{class-annotation}}}
12+
{{/if}}
813
public partial class {{class}}
914
{
1015
{{{> constructor}}}

src/EntityFrameworkCore.Scaffolding.Handlebars/CodeTemplates/CSharpEntityType/Partials/Properties.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{{#each properties}}
2+
{{#if property-comment}}
3+
{{spaces 8}}/// <summary>
4+
{{spaces 8}}/// {{property-comment}}
5+
{{spaces 8}}/// </summary>
6+
{{/if}}
27
{{#each property-annotations}}
38
{{spaces 8}}{{{property-annotation}}}
49
{{/each}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{{> imports}}
22

3+
{{#if comment}}
4+
/**
5+
* {{comment}}
6+
*/
7+
{{/if}}
38
export interface {{class}} {
49
{{{> properties}}}
510
}

src/EntityFrameworkCore.Scaffolding.Handlebars/CodeTemplates/TypeScriptEntityType/Partials/Properties.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{{#each properties}}
2+
{{#if property-comment}}
3+
{{spaces 4}}/**
4+
{{spaces 4}}* {{property-comment}}
5+
{{spaces 4}}*/
6+
{{/if}}
27
{{spaces 4}}{{property-name}}: {{property-type}};
38
{{/each}}
49
{{#if nav-properties}}

src/EntityFrameworkCore.Scaffolding.Handlebars/HbsCSharpEntityTypeGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ protected override void GenerateClass(IEntityType entityType)
152152
}
153153

154154
var transformedEntityName = EntityTypeTransformationService.TransformEntityName(entityType.Name);
155-
155+
156+
TemplateData.Add("comment", entityType.GetComment());
156157
TemplateData.Add("class", transformedEntityName);
157158

158159
GenerateConstructor(entityType);
@@ -220,6 +221,7 @@ protected override void GenerateProperties(IEntityType entityType)
220221
{ "property-type", propertyType },
221222
{ "property-name", property.Name },
222223
{ "property-annotations", PropertyAnnotationsData },
224+
{ "property-comment", property.GetComment() },
223225
{ "property-isnullable", property.IsNullable },
224226
{ "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
225227
});

src/EntityFrameworkCore.Scaffolding.Handlebars/HbsEntityTypeTransformationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public List<Dictionary<string, object>> TransformProperties(List<Dictionary<stri
127127
{ "property-type", transformedProp.PropertyType },
128128
{ "property-name", transformedProp.PropertyName },
129129
{ "property-annotations", property["property-annotations"] },
130+
{ "property-comment", property["property-comment"] },
130131
{ "property-isnullable", transformedProp.PropertyIsNullable },
131132
{ "nullable-reference-types", property["nullable-reference-types"] }
132133
});

src/EntityFrameworkCore.Scaffolding.Handlebars/HbsTypeScriptEntityTypeGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ protected override void GenerateClass(IEntityType entityType)
125125

126126
var transformedEntityName = EntityTypeTransformationService.TransformEntityName(entityType.Name);
127127

128+
TemplateData.Add("comment", entityType.GetComment());
128129
TemplateData.Add("class", transformedEntityName);
129130

130131
GenerateConstructor(entityType);
@@ -178,6 +179,7 @@ protected override void GenerateProperties(IEntityType entityType)
178179
{ "property-type", TypeScriptHelper.TypeName(property.ClrType) },
179180
{ "property-name", TypeScriptHelper.ToCamelCase(property.Name) },
180181
{ "property-annotations", new List<Dictionary<string, object>>() },
182+
{ "property-comment", property.GetComment() },
181183
{ "property-isnullable", property.IsNullable },
182184
{ "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
183185
});

test/Scaffolding.Handlebars.Tests/CodeTemplates/CSharpEntityType/Class.hbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
namespace {{namespace}}
44
{
5-
{{#if class-annotation}}
6-
{{spaces 4}}{{{class-annotation}}}
7-
{{/if}}
5+
{{#if comment}}
6+
/// <summary>
7+
/// {{comment}}
8+
/// </summary>
9+
{{/if}}
10+
{{#if class-annotation}}
11+
{{{class-annotation}}}
12+
{{/if}}
813
public partial class {{class}}
914
{
1015
{{{> constructor}}}

test/Scaffolding.Handlebars.Tests/Contexts/NorthwindDbContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public NorthwindDbContext(DbContextOptions options) : base(options) { }
1414

1515
protected override void OnModelCreating(ModelBuilder modelBuilder)
1616
{
17+
modelBuilder.Entity<Category>()
18+
.HasComment("A category of products")
19+
.Property(category => category.CategoryName)
20+
.HasComment("The name of a category");
1721
}
1822
}
1923
}

test/Scaffolding.Handlebars.Tests/EmbeddedResourceTemplateFileServiceTests.ExpectedTemplates.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ public partial class {{class}} : DbContext
3232
3333
namespace {{namespace}}
3434
{
35-
{{#if class-annotation}}
36-
{{spaces 4}}{{{class-annotation}}}
37-
{{/if}}
35+
{{#if comment}}
36+
/// <summary>
37+
/// {{comment}}
38+
/// </summary>
39+
{{/if}}
40+
{{#if class-annotation}}
41+
{{{class-annotation}}}
42+
{{/if}}
3843
public partial class {{class}}
3944
{
4045
{{{> constructor}}}

0 commit comments

Comments
 (0)