forked from Avanade/Beef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeGenConfig.cs
800 lines (688 loc) · 46.7 KB
/
CodeGenConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
using CoreEx.Entities.Extended;
using Microsoft.Extensions.Logging;
using OnRamp;
using OnRamp.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Beef.CodeGen.Config.Entity
{
/// <summary>
/// Represents the global entity code-generation configuration.
/// </summary>
[CodeGenClass("CodeGeneration", Title = "'CodeGeneration' object (entity-driven)",
Description = "The `CodeGeneration` object defines global properties that are used to drive the underlying entity-driven code generation.",
ExampleMarkdown = @"A YAML configuration [example](../samples/My.Hr/My.Hr.CodeGen/entity.beef.yaml) is as follows:
``` yaml
refDataNamespace: My.Hr.Common.Entities
refDataText: true
eventSubjectRoot: My
eventActionFormat: PastTense
entities:
```")]
[CodeGenCategory("DotNet", Title = "Provides the _.NET_ configuration.")]
[CodeGenCategory("RefData", Title = "Provides the _Reference Data_ configuration.")]
[CodeGenCategory("Entity", Title = "Provides the _Entity class_ configuration.")]
[CodeGenCategory("Events", Title = "Provides the _Events_ configuration.")]
[CodeGenCategory("WebApi", Title = "Provides the _Web API (Controller)_ configuration.")]
[CodeGenCategory("Manager", Title = "Provides the _Manager-layer_ configuration.")]
[CodeGenCategory("Data", Title = "Provides the generic _Data-layer_ configuration.")]
[CodeGenCategory("Database", Title = "Provides the _Database Data-layer_ configuration.")]
[CodeGenCategory("EntityFramework", Title = "Provides the _Entity Framewotrk (EF) Data-layer_ configuration.")]
[CodeGenCategory("Cosmos", Title = "Provides the _CosmosDB Data-layer_ configuration.")]
[CodeGenCategory("OData", Title = "Provides the _OData Data-layer_ configuration.")]
[CodeGenCategory("HttpAgent", Title = "Provides the _HTTP Agent Data-layer_ configuration.")]
[CodeGenCategory("gRPC", Title = "Provides the _gRPC_ configuration.")]
[CodeGenCategory("Path", Title = "Provides the _Path (Directory)_ configuration.")]
[CodeGenCategory("Namespace", Title = "Provides the _.NET Namespace_ configuration.")]
[CodeGenCategory("Auth", Title = "Provides the _Authorization_ configuration.")]
[CodeGenCategory("Collections", Title = "Provides related child (hierarchical) configuration.")]
public class CodeGenConfig : ConfigRootBase<CodeGenConfig>
{
#region DotNet
/// <summary>
/// Indicates whether to use Results.
/// </summary>
[JsonPropertyName("withResult")]
[CodeGenProperty("DotNet", Title = "Indicates whether to use `CoreEx.Results` (aka Railway-oriented programming).",
Description = "Defaults to `true`. This can be overridden within the `Entity`(s) and/or `Operation`(s).")]
public bool? WithResult { get; set; }
/// <summary>
/// Indicates whether to use preprocessor directives in the generated output.
/// </summary>
[JsonPropertyName("preprocessorDirectives")]
[CodeGenProperty("DotNet", Title = "Indicates whether to use preprocessor directives in the generated output.")]
public bool? PreprocessorDirectives { get; set; }
#endregion
#region RefData
/// <summary>
/// Gets or sets the namespace for the Reference Data entities (adds as a c# <c>using</c> statement).
/// </summary>
[JsonPropertyName("refDataNamespace")]
[CodeGenProperty("RefData", Title = "The namespace for the Reference Data entities (adds as a c# `using` statement).", IsImportant = true,
Description = "Defaults to `Company` + `.` (literal) + AppName + `.Business.Entities` (literal).")]
public string? RefDataNamespace { get; set; }
/// <summary>
/// Gets or sets the namespace for the Reference Data common entities (adds as a c# <c>using</c> statement).
/// </summary>
[JsonPropertyName("refDataCommonNamespace")]
[CodeGenProperty("RefData", Title = "The namespace for the Reference Data common entities (adds as a c# `using` statement).", IsImportant = true,
Description = "Defaults to `Company` + `.` (literal) + AppName + `.Common.Entities` (literal).")]
public string? RefDataCommonNamespace { get; set; }
/// <summary>
/// Indicates whether a corresponding <i>text</i> property is added by default when generating a Reference Data `Property` for an `Entity`.
/// </summary>
[JsonPropertyName("refDataText")]
[CodeGenProperty("RefData", Title = "Indicates whether a corresponding `Text` property is added when generating a Reference Data `Property` for an `Entity`.", IsImportant = true,
Description = "This is used where serializing within the Web API `Controller` and the `ExecutionContext.IsRefDataTextSerializationEnabled` is set to `true` (which is automatically set where the url contains `$text=true`). This can be further configured on the `Entity` and for each `Property`.")]
public bool? RefDataText { get; set; }
/// <summary>
/// Gets or sets the Reference Data identifier Type option.
/// </summary>
[JsonPropertyName("refDataType")]
[CodeGenProperty("RefData", Title = "The Reference Data identifier Type option.", IsImportant = true, Options = ["int", "long", "Guid", "string"],
Description = "Required to identify an entity as being Reference Data. Specifies the underlying .NET Type used for the Reference Data identifier. Results in all underlying entities becoming Reference Data.")]
public string? RefDataType { get; set; }
/// <summary>
/// Gets or sets the <c>RouteAtttribute</c> for the Reference Data Web API controller required for named pre-fetching.
/// </summary>
[JsonPropertyName("refDataWebApiRoute")]
[CodeGenProperty("RefData", Title = "The `RouteAtttribute` for the Reference Data Web API controller required for named pre-fetching. The `WebApiRoutePrefix` will be prepended where specified.", IsImportant = true)]
public string? RefDataWebApiRoute { get; set; }
/// <summary>
/// Gets or sets the list of extended (non-inferred) Dependency Injection (DI) parameters for the generated `ReferenceDataData` constructor.
/// </summary>
[JsonPropertyName("refDataDataCtorParams")]
[CodeGenPropertyCollection("Data", Title = "The list of additional (non-inferred) Dependency Injection (DI) parameters for the generated `ReferenceDataData` constructor.",
Description = "Each constructor parameter should be formatted as `Type` + `^` + `Name`; e.g. `IConfiguration^Config`. Where the `Name` portion is not specified it will be inferred. " +
"Where the `Type` matches an already inferred value it will be ignored.")]
public List<string>? RefDataDataCtorParams { get; set; }
#endregion
#region Entity
/// <summary>
/// Get or sets the JSON Serializer to use for JSON property attribution.
/// </summary>
[JsonPropertyName("jsonSerializer")]
[CodeGenProperty("Entity", Title = "The JSON Serializer to use for JSON property attribution.", Options = ["SystemText", "Newtonsoft"],
Description = "Defaults to `SystemText`. This can be overridden within the `Entity`(s).")]
public string? JsonSerializer { get; set; }
/// <summary>
/// Gets or sets the default JSON name for the ETag property.
/// </summary>
[JsonPropertyName("etagJsonName")]
[CodeGenProperty("Entity", Title = "The default JSON name for the `ETag` property.", Options = ["etag", "eTag", "_etag", "_eTag", "ETag", "ETAG"],
Description = "Defaults to `etag`. Note that the `JsonName` can be set individually per property where required.")]
public string? ETagJsonName { get; set; }
/// <summary>
/// Gets or sets the additional Namespace using statement to the added to the generated <c>Entity</c> code.
/// </summary>
[JsonPropertyName("usingNamespace1")]
[CodeGenProperty("Entity", Title = "The additional Namespace using statement to be added to the generated `Entity` code.",
Description = "Typically used where referening a `Type` from a Namespace that is not generated by default.")]
public string? UsingNamespace1 { get; set; }
/// <summary>
/// Gets or sets the additional Namespace using statement to the added to the generated <c>Entity</c> code.
/// </summary>
[JsonPropertyName("usingNamespace2")]
[CodeGenProperty("Entity", Title = "The additional Namespace using statement to be added to the generated `Entity` code.",
Description = "Typically used where referening a `Type` from a Namespace that is not generated by default.")]
public string? UsingNamespace2 { get; set; }
/// <summary>
/// Gets or sets the additional Namespace using statement to the added to the generated <c>Entity</c> code.
/// </summary>
[JsonPropertyName("usingNamespace3")]
[CodeGenProperty("Entity", Title = "The additional Namespace using statement to be added to the generated `Entity` code.",
Description = "Typically used where referening a `Type` from a Namespace that is not generated by default.")]
public string? UsingNamespace3 { get; set; }
#endregion
#region WebApi
/// <summary>
/// Gets or sets the authorize attribute value to be used for the corresponding entity Web API controller; generally either <c>Authorize</c> or <c>AllowAnonynous</c>.
/// </summary>
[JsonPropertyName("webApiAuthorize")]
[CodeGenProperty("WebApi", Title = "The authorize attribute value to be used for the corresponding entity Web API controller; generally either `Authorize` or `AllowAnonymous`.",
Description = "This can be overridden within the `Entity`(s) and/or their corresponding `Operation`(s).")]
public string? WebApiAuthorize { get; set; }
/// <summary>
/// Indicates whether the HTTP Response Location Header route (`Operation.WebApiLocation`)` is automatically inferred.
/// </summary>
[JsonPropertyName("webApiAutoLocation")]
[CodeGenProperty("WebApi", Title = "Indicates whether the HTTP Response Location Header route (`Operation.WebApiLocation`) is automatically inferred.",
Description = "This will automatically set the `Operation.WebApiLocation` for an `Operation` named `Create` where there is a corresponding named `Get`. This can be overridden within the `Entity`(s).")]
public bool? WebApiAutoLocation { get; set; }
/// <summary>
/// Gets or sets the <c>RoutePrefixAtttribute</c> for the corresponding entity Web API controller.
/// </summary>
[JsonPropertyName("webApiRoutePrefix")]
[CodeGenProperty("WebApi", Title = "The base (prefix) `URI` prepended to all `Operation.WebApiRoute` values.", IsImportant = true)]
public string? WebApiRoutePrefix { get; set; }
/// <summary>
/// The list of tags to add for the generated `WebApi`.
/// </summary>
[JsonPropertyName("webApiTags")]
[CodeGenPropertyCollection("WebApi", Title = "The list of tags to add for the generated `WebApi`.",
Description = "This can be overridden within the `Entity`(s) and/or their corresponding `Operation`(s).")]
public List<string>? WebApiTags { get; set; }
#endregion
#region Manager
/// <summary>
/// Indicates whether a `Cleaner.Cleanup` is performed for the operation parameters within the Manager-layer.
/// </summary>
[JsonPropertyName("managerCleanUp")]
[CodeGenProperty("Manager", Title = "Indicates whether a `Cleaner.Cleanup` is performed for the operation parameters within the Manager-layer.",
Description = "This can be overridden within the `Entity`(s) and `Operation`(s).")]
public bool? ManagerCleanUp { get; set; }
/// <summary>
/// Gets or sets the `Validation` framework.
/// </summary>
[JsonPropertyName("validationFramework")]
[CodeGenProperty("Manager", Title = "The `Validation` framework to use for the entity-based validation.", Options = ["CoreEx", "FluentValidation"],
Description = "Defaults to `CoreEx` (literal). This can be overridden within the `Entity`(s), `Operation`(s) and `Parameter`(s).")]
public string? ValidationFramework { get; set; }
#endregion
#region Data
/// <summary>
/// Gets or sets the data source auto-implementation option.
/// </summary>
[JsonPropertyName("autoImplement")]
[CodeGenProperty("Data", Title = "The data source auto-implementation option.", IsImportant = true, Options = ["Database", "EntityFramework", "Cosmos", "OData", "HttpAgent", "None"],
Description = "Defaults to `None`. Indicates that the implementation for the underlying `Operations` will be auto-implemented using the selected data source (unless explicitly overridden). When selected some of the related attributes will also be required (as documented). " +
"Additionally, the `AutoImplement` can be further specified/overridden per `Operation`.")]
public string? AutoImplement { get; set; }
/// <summary>
/// Gets or sets the default .NET database interface name used where `Operation.AutoImplement` is `Database`.
/// </summary>
[JsonPropertyName("databaseType")]
[CodeGenProperty("Database", Title = "The .NET database type and optional name (used where `Operation.AutoImplement` is `Database`).", IsImportant = true,
Description = "Defaults to `IDatabase`. Should be formatted as `Type` + `^` + `Name`; e.g. `IDatabase^Db`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).")]
public string? DatabaseType { get; set; }
/// <summary>
/// Gets or sets the default database schema name.
/// </summary>
[JsonPropertyName("databaseSchema")]
[CodeGenProperty("Database", Title = "The default database schema name.", IsImportant = true,
Description = "Defaults to `dbo`.")]
public string? DatabaseSchema { get; set; }
/// <summary>
/// Gets or sets the database provider.
/// </summary>
[JsonPropertyName("databaseProvider")]
[CodeGenProperty("Database", Title = "The default database schema name.", IsImportant = true, Options = ["SqlServer", "MySQL", "Postgres"],
Description = "Defaults to `SqlServer`. Enables specific database provider functionality/formatting/etc. where applicable.")]
public string? DatabaseProvider { get; set; }
/// <summary>
/// Indicates that a `DatabaseMapperEx` will be used versus `DatabaseMapper` (uses Reflection).
/// </summary>
[JsonPropertyName("databaseMapperEx")]
[CodeGenProperty("Database", Title = "Indicates that a `DatabaseMapperEx` will be used; versus, `DatabaseMapper` (which uses Reflection internally).",
Description = "Defaults to `true`. The `DatabaseMapperEx` essentially replaces the `DatabaseMapper` as it is more performant (extended/explicit); this option can be used where leagcy/existing behavior is required.")]
public bool? DatabaseMapperEx { get; set; }
/// <summary>
/// Gets or sets the default .NET Entity Framework interface name used where `Operation.AutoImplement` is `EntityFramework`.
/// </summary>
[JsonPropertyName("entityFrameworkType")]
[CodeGenProperty("EntityFramework", Title = "The .NET Entity Framework type and optional name (used where `Operation.AutoImplement` is `EntityFramework`).",
Description = "Defaults to `IEfDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `IEfDb^Ef`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).")]
public string? EntityFrameworkType { get; set; }
/// <summary>
/// Gets or sets the default .NET Cosmos interface name used where `Operation.AutoImplement` is `Cosmos`.
/// </summary>
[JsonPropertyName("cosmosType")]
[CodeGenProperty("Cosmos", Title = "The .NET Cosmos DB type and name (used where `Operation.AutoImplement` is `Cosmos`).", IsImportant = true,
Description = "Defaults to `ICosmosDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `ICosmosDb^Cosmos`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).")]
public string? CosmosType { get; set; }
/// <summary>
/// Gets or sets the default .NET OData interface name used where `Operation.AutoImplement` is `OData`.
/// </summary>
[JsonPropertyName("odataType")]
[CodeGenProperty("OData", Title = "The .NET OData interface name used where `Operation.AutoImplement` is `OData`.", IsImportant = true,
Description = "Defaults to `IOData`. Should be formatted as `Type` + `^` + `Name`; e.g. `IOData^OData`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).")]
public string? ODataType { get; set; }
/// <summary>
/// Gets or sets the default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.
/// </summary>
[JsonPropertyName("httpAgentType")]
[CodeGenProperty("HttpAgent", Title = "The default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.", IsImportant = true,
Description = "Defaults to `IHttpAgent`. Should be formatted as `Type` + `^` + `Name`; e.g. `IHttpAgent^HttpAgent`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).")]
public string? HttpAgentType { get; set; }
/// <summary>
/// Gets or sets the default ETag to/from RowVersion Mapping Converter used.
/// </summary>
[JsonPropertyName("etagDefaultMapperConverter")]
[CodeGenProperty("Data", Title = "The default ETag to/from RowVersion column Mapping Converter used where `Operation.AutoImplement` is `Database` or `EntityFramework`.", IsImportant = true,
Description = "Defaults to `StringToBase64Converter`.")]
public string? ETagDefaultMapperConverter { get; set; }
/// <summary>
/// Gets or sets the default Reference Data property Converter used by the generated Mapper(s) where not specifically defined.
/// </summary>
[JsonPropertyName("refDataDefaultMapperConverter")]
[CodeGenProperty("Data", Title = "The default Reference Data property `Converter` used by the generated `Mapper`(s) where not specifically defined.",
Options = [
"ReferenceDataCodeConverter", "ReferenceDataCodeConverter{T}", "ReferenceDataCodeConverter<T>",
"ReferenceDataIdConverter{T, int}", "ReferenceDataIdConverter<T, int>", "ReferenceDataIdConverter{T, int?}", "ReferenceDataIdConverter<T, int?>",
"ReferenceDataIdConverter{T, long}", "ReferenceDataIdConverter<T, long>", "ReferenceDataIdConverter{T, long?}", "ReferenceDataIdConverter<T, long?>",
"ReferenceDataIdConverter{T, Guid}", "ReferenceDataIdConverter<T, Guid>", "ReferenceDataIdConverter{T, Guid?}", "ReferenceDataIdConverter<T, Guid?>",
"ReferenceDataInt32IdConverter", "ReferenceDataInt32IdConverter{T}", "ReferenceDataInt32IdConverter<T>",
"ReferenceDataNullableInt32IdConverter", "ReferenceDataNullableInt32IdConverter{T}", "ReferenceDataNullableInt32IdConverter<T>",
"ReferenceDataInt64IdConverter", "ReferenceDataInt64IdConverter{T}", "ReferenceDataInt64IdConverter<T>",
"ReferenceDataNullableInt64IdConverter", "ReferenceDataNullableInt64IdConverter{T}", "ReferenceDataNullableInt64IdConverter<T>",
"ReferenceDataGuidIdConverter", "ReferenceDataGuidIdConverter{T}", "ReferenceDataGuidIdConverter<T>",
"ReferenceDataNullableGuidIdConverter", "ReferenceDataNullableGuidIdConverter{T}", "ReferenceDataNullableGuidIdConverter<T>" ],
Description = "Defaults to `ReferenceDataCodeConverter<T>`. Where this value is suffixed by `<T>` or `{T}` this will automatically be set to the `Type`.")]
public string? RefDataDefaultMapperConverter { get; set; }
/// <summary>
/// Gets or sets the Reference Data code data name
/// </summary>
[JsonPropertyName("refDataCodeDataName")]
[CodeGenProperty("RefData", Title = "The Reference Data `Code` data name.",
Description = "Defaults to `Code` (literal).")]
public string? RefDataCodeDataName { get; set; }
/// <summary>
/// Gets or sets the Reference Data text data name.
/// </summary>
[JsonPropertyName("refDataTextDataName")]
[CodeGenProperty("RefData", Title = "The Reference Data `Text` data name.",
Description = "Defaults to `Text` (literal).")]
public string? RefDataTextDataName { get; set; }
/// <summary>
/// Gets or sets the Reference Data is active name.
/// </summary>
[JsonPropertyName("refDataIsActiveDataName")]
[CodeGenProperty("RefData", Title = "The Reference Data `IsActive` data name.",
Description = "Defaults to `IsActive` (literal).")]
public string? RefDataIsActiveDataName { get; set; }
/// <summary>
/// Gets or sets the Reference Data sort order data name.
/// </summary>
[JsonPropertyName("refDataSortOrderDataName")]
[CodeGenProperty("RefData", Title = "The Reference Data `SortOrder` data name.",
Description = "Defaults to `SortOrder` (literal).")]
public string? RefDataSortOrderDataName { get; set; }
/// <summary>
/// Gets or sets the Reference Data is ETag name.
/// </summary>
[JsonPropertyName("refDataETagDataName")]
[CodeGenProperty("RefData", Title = "The Reference Data `ETag` data name.",
Description = "Defaults to `RowVersion` (literal).")]
public string? RefDataETagDataName { get; set; } = "*";
#endregion
#region Events
/// <summary>
/// Gets or sets the layer to add logic to publish an event for a <c>Create</c>, <c>Update</c> or <c>Delete</c> operation.
/// </summary>
[JsonPropertyName("eventPublish")]
[CodeGenProperty("Events", Title = "The layer to add logic to publish an event for a `Create`, `Update` or `Delete` operation.", IsImportant = true, Options = ["None", "DataSvc", "Data"],
Description = "Defaults to `DataSvc`. Used to enable the sending of messages to the likes of EventHub, ServiceBus, SignalR, etc. This can be overridden within the `Entity`(s).")]
public string? EventPublish { get; set; }
/// <summary>
/// Gets or sets the URI root for the event source by prepending to all event source URIs.
/// </summary>
[JsonPropertyName("eventSourceRoot")]
[CodeGenProperty("Events", Title = "The URI root for the event source by prepending to all event source URIs.",
Description = "The event source is only updated where an `EventSourceKind` is not `None`. This can be extended within the `Entity`(s).")]
public string? EventSourceRoot { get; set; }
/// <summary>
/// Gets or sets the URI kind for the event source URIs.
/// </summary>
[JsonPropertyName("eventSourceKind")]
[CodeGenProperty("Events", Title = "The URI kind for the event source URIs.", Options = ["None", "Absolute", "Relative", "RelativeOrAbsolute"],
Description = "Defaults to `None` (being the event source is not updated).")]
public string? EventSourceKind { get; set; }
/// <summary>
/// Gets or sets the root for the event Subject name by prepending to all event subject names.
/// </summary>
[JsonPropertyName("eventSubjectRoot")]
[CodeGenProperty("Events", Title = "The root for the event Subject name by prepending to all event subject names.", IsImportant = true,
Description = "Used to enable the sending of messages to the likes of EventHub, ServiceBus, SignalR, etc. This can be overridden within the `Entity`(s).")]
public string? EventSubjectRoot { get; set; }
/// <summary>
/// Gets or sets the subject path separator.
/// </summary>
[JsonPropertyName("eventSubjectSeparator")]
[CodeGenProperty("Event", Title = "The subject path separator.",
Description = "Defaults to `.`. Used only where the subject is automatically inferred.")]
public string? EventSubjectSeparator { get; set; }
/// <summary>
/// Gets or sets the formatting for the Action when an Event is published.
/// </summary>
[JsonPropertyName("eventActionFormat")]
[CodeGenProperty("Event", Title = "The formatting for the Action when an Event is published.", Options = ["None", "PastTense"], IsImportant = true,
Description = "Defaults to `None` (no formatting required, i.e. as-is)`.")]
public string? EventActionFormat { get; set; }
/// <summary>
/// Indicates whether a `System.TransactionScope` should be created and orchestrated at the `DataSvc`-layer whereever generating event publishing logic.
/// </summary>
[JsonPropertyName("eventTransaction")]
[CodeGenProperty("Event", Title = "Indicates whether a `System.TransactionScope` should be created and orchestrated at the `DataSvc`-layer whereever generating event publishing logic.", IsImportant = true,
Description = "Usage will force a rollback of any underlying data transaction (where the provider supports TransactionScope) on failure, such as an `EventPublish` error. " +
"This is by no means implying a Distributed Transaction (DTC) should be invoked; this is only intended for a single data source that supports a TransactionScope to guarantee reliable event publishing. " +
"Defaults to `false`. This essentially defaults the `Entity.EventTransaction` where not otherwise specified. This should only be used where `EventPublish` is `DataSvc` and a transactionally-aware data source is being used.")]
public bool? EventTransaction { get; set; }
#endregion
#region Grpc
/// <summary>
/// Indicates whether gRPC support (more specifically service-side) is required.
/// </summary>
[JsonPropertyName("grpc")]
[CodeGenProperty("gRPC", Title = "Indicates whether gRPC support (more specifically service-side) is required.", IsImportant = true,
Description = "gRPC support is an explicit opt-in model. Must be set to `true` for any of the subordinate gRPC capabilities to be code-generated. Will require each `Entity`, and corresponding `Property` and `Operation` to be opted-in specifically.")]
public bool? Grpc { get; set; }
#endregion
#region Path
/// <summary>
/// Gets or sets the base path (directory) prefix for the artefacts.
/// </summary>
[JsonPropertyName("pathBase")]
[CodeGenProperty("Path", Title = "The base path (directory) prefix for the artefacts; other `Path*` properties append to this value when they are not specifically overridden.",
Description = "Defaults to `Company` (runtime parameter) + `.` + `AppName` (runtime parameter). For example `Beef.Demo`.")]
public string? PathBase { get; set; }
/// <summary>
/// Gets or sets the path (directory) for the Common-related artefacts.
/// </summary>
[JsonPropertyName("pathCommon")]
[CodeGenProperty("Path", Title = "The path (directory) for the Database-related artefacts.",
Description = "Defaults to `PathBase` + `.Common` (literal). For example `Beef.Demo.Common`.")]
public string? PathCommon { get; set; }
/// <summary>
/// Gets or sets the path (directory) for the Business-related (.NET) artefacts.
/// </summary>
[JsonPropertyName("pathBusiness")]
[CodeGenProperty("Path", Title = "The path (directory) for the Business-related (.NET) artefacts.",
Description = "Defaults to `PathBase` + `.Business` (literal). For example `Beef.Demo.Business`.")]
public string? PathBusiness { get; set; }
/// <summary>
/// Gets or sets the path (directory) for the API-related (.NET) artefacts.
/// </summary>
[JsonPropertyName("pathApi")]
[CodeGenProperty("Path", Title = "The path (directory) for the API-related (.NET) artefacts.",
Description = "Defaults to `PathBase` + `.` + `ApiName` (runtime parameter). For example `Beef.Demo.Api`.")]
public string? PathApi { get; set; }
#endregion
#region Namespace
/// <summary>
/// Gets or sets the base Namespace (root) for the .NET artefacts.
/// </summary>
[JsonPropertyName("namespaceBase")]
[CodeGenProperty("Namespace", Title = "The base Namespace (root) for the .NET artefacts.",
Description = "Defaults to `Company` (runtime parameter) + `.` + `AppName` (runtime parameter). For example `Beef.Demo`.")]
public string? NamespaceBase { get; set; }
/// <summary>
/// Gets or sets the Namespace (root) for the Common-related .NET artefacts.
/// </summary>
[JsonPropertyName("namespaceCommon")]
[CodeGenProperty("Namespace", Title = "The Namespace (root) for the Common-related .NET artefacts.",
Description = "Defaults to `NamespaceBase` + `.Common` (literal). For example `Beef.Demo.Common`.")]
public string? NamespaceCommon { get; set; }
/// <summary>
/// Gets or sets the Namespace (root) for the Business-related .NET artefacts.
/// </summary>
[JsonPropertyName("namespaceBusiness")]
[CodeGenProperty("Namespace", Title = "The Namespace (root) for the Business-related .NET artefacts.",
Description = "Defaults to `NamespaceBase` + `.Business` (literal). For example `Beef.Demo.Business`.")]
public string? NamespaceBusiness { get; set; }
/// <summary>
/// Gets or sets the Namespace (root) for the Api-related .NET artefacts.
/// </summary>
[JsonPropertyName("namespaceApi")]
[CodeGenProperty("Namespace", Title = "The Namespace (root) for the Api-related .NET artefacts.",
Description = "Defaults to `NamespaceBase` + `.` + `ApiName` (runtime parameter). For example `Beef.Demo.Api`.")]
public string? NamespaceApi { get; set; }
#endregion
#region Auth
/// <summary>
/// Gets the default auth action for a create.
/// </summary>
[JsonPropertyName("authActionCreate")]
[CodeGenProperty("Auth", Title = "The default `Operation.AuthAction` for an `Operation.Type` of `Create`.", Description = "Defaults to `Create`.")]
public string? AuthActionCreate { get; set; }
/// <summary>
/// Gets the default auth action for a get or getcoll.
/// </summary>
[JsonPropertyName("authActionRead")]
[CodeGenProperty("Auth", Title = "The default `Operation.AuthAction` for an `Operation.Type` of `Get` or `GetColl`.", Description = "Defaults to `Read`.")]
public string? AuthActionRead { get; set; }
/// <summary>
/// Gets the default auth action for a update.
/// </summary>
[JsonPropertyName("authActionUpdate")]
[CodeGenProperty("Auth", Title = "The default `Operation.AuthAction` for an `Operation.Type` of `Update`.", Description = "Defaults to `Update`.")]
public string? AuthActionUpdate { get; set; }
/// <summary>
/// Gets the default auth action for a delete.
/// </summary>
[JsonPropertyName("authActionDelete")]
[CodeGenProperty("Auth", Title = "The default `Operation.AuthAction` for an `Operation.Type` of `Delete`.", Description = "Defaults to `Delete`.")]
public string? AuthActionDelete { get; set; }
#endregion
/// <summary>
/// Gets or sets the corresponding <see cref="EntityConfig"/> collection.
/// </summary>
[JsonPropertyName("entities")]
[CodeGenPropertyCollection("Collections", Title = "The corresponding `Entity` collection.", IsImportant = true,
Markdown = "An `Entity` object provides the primary configuration for an entity, its properties and operations.")]
public List<EntityConfig>? Entities { get; set; }
/// <summary>
/// Gets the <see cref="Entities"/> that are selected for IXxxManager.
/// </summary>
public List<EntityConfig>? IManagerEntities => Entities!.Where(x => CompareNullOrValue(x.ExcludeIManager, false) && x.Operations!.Count > 0).ToList();
/// <summary>
/// Gets the <see cref="Entities"/> that are selected for IXxxData.
/// </summary>
public List<EntityConfig>? IDataSvcEntities => Entities!.Where(x => CompareNullOrValue(x.ExcludeIDataSvc, false) && x.Operations!.Count > 0).ToList();
/// <summary>
/// Gets the <see cref="Entities"/> that are selected for IXxxData.
/// </summary>
public List<EntityConfig>? IDataEntities => Entities!.Where(x => CompareNullOrValue(x.ExcludeIData, false) && x.Operations!.Count > 0).ToList();
/// <summary>
/// Gets the <see cref="Entities"/> that are selected for Reference Data.
/// </summary>
public List<EntityConfig>? RefDataEntities => Entities!.Where(x => !string.IsNullOrEmpty(x.RefDataType) && CompareNullOrValue(x.Abstract, false)).ToList();
/// <summary>
/// Gets the <see cref="Entities"/> that are selected for Grpc.
/// </summary>
public List<EntityConfig>? GrpcEntities => Entities!.Where(x => CompareValue(x.Grpc, true) && CompareNullOrValue(x.Abstract, false)).ToList();
/// <summary>
/// Gets the company name from the <see cref="IRootConfig.RuntimeParameters"/>.
/// </summary>
public string? Company => CodeGenArgs!.GetCompany(true);
/// <summary>
/// Gets the application name from the <see cref="IRootConfig.RuntimeParameters"/>.
/// </summary>
public string? AppName => CodeGenArgs!.GetAppName(true);
/// <summary>
/// Gets the API name from the <see cref="IRootConfig.RuntimeParameters"/>.
/// </summary>
public string? ApiName => DefaultWhereNull(CodeGenArgs!.GetParameter<string>(CodeGenConsole.ApiNameParamName), () => "Api")!;
/// <summary>
/// Gets the entity scope from the from the <see cref="IRootConfig.RuntimeParameters"/> (defaults to 'Common').
/// </summary>
public string RuntimeEntityScope => GetRuntimeParameter<string?>("EntityScope") ?? "Business";
/// <summary>
/// Indicates whether to generate an <c>Entity</c> as a <c>DataModel</c> where the <see cref="EntityConfig.DataModel"/> is selected (from the <see cref="IRootConfig.RuntimeParameters"/>).
/// </summary>
public bool ModelFromEntity => GetRuntimeParameter<bool>("ModelFromEntity");
/// <summary>
/// Indicates whether the intended Entity code generation is a Data Model and therefore should not inherit from <see cref="EntityBase"/> (from the <see cref="IRootConfig.RuntimeParameters"/>).
/// </summary>
public bool IsDataModel => GetRuntimeParameter<bool>("IsDataModel");
/// <summary>
/// Indicates whether the intended code generation is explicitly for Reference Data.
/// </summary>
public bool IsRefData => GetRuntimeParameter<bool>("IsRefData");
/// <summary>
/// Gets the reference data specific properties.
/// </summary>
public RefDataConfig? RefData { get; private set; }
/// <summary>
/// Gets the list of all the used validators.
/// </summary>
public List<ParameterConfig> Validators { get; } = [];
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override async Task PrepareAsync()
{
PathBase = DefaultWhereNull(PathBase, () => $"{Company}.{AppName}");
PathCommon = DefaultWhereNull(PathCommon, () => $"{PathBase}.Common");
PathBusiness = DefaultWhereNull(PathBusiness, () => $"{PathBase}.Business");
PathApi = DefaultWhereNull(PathApi, () => $"{PathBase}.{ApiName}");
NamespaceBase = DefaultWhereNull(NamespaceBase, () => $"{Company}.{AppName}");
NamespaceCommon = DefaultWhereNull(NamespaceCommon, () => $"{NamespaceBase}.Common");
NamespaceBusiness = DefaultWhereNull(NamespaceBusiness, () => $"{NamespaceBase}.Business");
NamespaceApi = DefaultWhereNull(NamespaceApi, () => $"{NamespaceBase}.{ApiName}");
if (ExtraProperties is not null)
{
DatabaseType ??= ExtraProperties.Where(x => string.Compare(x.Key, "databaseName", StringComparison.InvariantCultureIgnoreCase) == 0).Select(x => x.Value.ToString()).FirstOrDefault();
EntityFrameworkType ??= ExtraProperties.Where(x => string.Compare(x.Key, "entityFrameworkName", StringComparison.InvariantCultureIgnoreCase) == 0).Select(x => x.Value.ToString()).FirstOrDefault();
CosmosType ??= ExtraProperties.Where(x => string.Compare(x.Key, "cosmosName", StringComparison.InvariantCultureIgnoreCase) == 0).Select(x => x.Value.ToString()).FirstOrDefault();
ODataType ??= ExtraProperties.Where(x => string.Compare(x.Key, "odataName", StringComparison.InvariantCultureIgnoreCase) == 0).Select(x => x.Value.ToString()).FirstOrDefault();
HttpAgentType ??= ExtraProperties.Where(x => string.Compare(x.Key, "httpAgentName", StringComparison.InvariantCultureIgnoreCase) == 0).Select(x => x.Value.ToString()).FirstOrDefault();
}
WithResult = DefaultWhereNull(WithResult, () => true);
PreprocessorDirectives = DefaultWhereNull(PreprocessorDirectives, () => false);
ManagerCleanUp = DefaultWhereNull(ManagerCleanUp, () => false);
ValidationFramework = DefaultWhereNull(ValidationFramework, () => "CoreEx");
WebApiAutoLocation = DefaultWhereNull(WebApiAutoLocation, () => false);
EventSourceKind = DefaultWhereNull(EventSourceKind, () => "None");
EventSubjectSeparator = DefaultWhereNull(EventSubjectSeparator, () => ".");
EventPublish = DefaultWhereNull(EventPublish, () => "DataSvc");
EventActionFormat = DefaultWhereNull(EventActionFormat, () => "None");
RefDataNamespace = DefaultWhereNull(RefDataNamespace, () => $"{Company}.{AppName}.Business.Entities");
RefDataCommonNamespace = DefaultWhereNull(RefDataCommonNamespace, () => $"{Company}.{AppName}.Common.Entities");
AutoImplement = DefaultWhereNull(AutoImplement, () => "None");
DatabaseProvider = DefaultWhereNull(DatabaseProvider, () => "SqlServer");
DatabaseSchema = DefaultWhereNull(DatabaseSchema, () => DatabaseProvider == "SqlServer" ? "dbo" : "");
DatabaseType = DefaultWhereNull(DatabaseType, () => "IDatabase");
DatabaseMapperEx = DefaultWhereNull(DatabaseMapperEx, () => true);
EntityFrameworkType = DefaultWhereNull(EntityFrameworkType, () => "IEfDb");
CosmosType = DefaultWhereNull(CosmosType, () => "ICosmosDb");
ODataType = DefaultWhereNull(ODataType, () => "IOData");
HttpAgentType = DefaultWhereNull(HttpAgentType, () => "IHttpAgent");
JsonSerializer = DefaultWhereNull(JsonSerializer, () => "SystemText");
ETagJsonName = DefaultWhereNull(ETagJsonName, () => "etag");
ETagDefaultMapperConverter = DefaultWhereNull(ETagDefaultMapperConverter, () => nameof(CoreEx.Mapping.Converters.StringToBase64Converter));
RefDataDefaultMapperConverter = DefaultWhereNull(RefDataDefaultMapperConverter, () => "ReferenceDataCodeConverter<T>");
RefDataCodeDataName = DefaultWhereNull(RefDataCodeDataName, () => "Code");
RefDataTextDataName = DefaultWhereNull(RefDataTextDataName, () => "Text");
RefDataIsActiveDataName = DefaultWhereNull(RefDataIsActiveDataName, () => "IsActive");
RefDataSortOrderDataName = DefaultWhereNull(RefDataSortOrderDataName, () => "SortOrder");
WebApiTags ??= [];
AuthActionCreate = DefaultWhereNull(AuthActionCreate, () => "Create");
AuthActionRead = DefaultWhereNull(AuthActionRead, () => "Read");
AuthActionUpdate = DefaultWhereNull(AuthActionUpdate, () => "Update");
AuthActionDelete = DefaultWhereNull(AuthActionDelete, () => "Delete");
if (!string.IsNullOrEmpty(WebApiRoutePrefix))
RefDataWebApiRoute = string.IsNullOrEmpty(RefDataWebApiRoute) ? WebApiRoutePrefix :
$"{(WebApiRoutePrefix.EndsWith('/') ? WebApiRoutePrefix[..^1] : WebApiRoutePrefix)}/{(RefDataWebApiRoute.StartsWith('/') ? RefDataWebApiRoute[1..] : RefDataWebApiRoute)}";
if (WebApiRoutePrefix is not null && WebApiRoutePrefix.StartsWith("/"))
WebApiRoutePrefix = WebApiRoutePrefix[1..];
Entities = await PrepareCollectionAsync(Entities).ConfigureAwait(false);
RefData = new RefDataConfig();
await RefData.PrepareAsync(Root!, this).ConfigureAwait(false);
foreach (var e in Entities)
{
foreach (var o in e.Operations!)
{
foreach (var p in o.Parameters!.Where(x => x.Validator != null))
{
var pc = new ParameterConfig { Name = p.Validator, Type = p.Validator, ValidationFramework = p.ValidationFramework };
if (!Validators.Any(x => x.Type == pc.Type))
Validators.Add(pc);
}
}
}
// Check for any deprecated properties and warn/error.
WarnWhereDeprecated(this, this,
"refDataCache",
"refDataAppendToNamespace",
"refDataBusNamespace",
"entityScope",
"entityUsing",
"appBasedAgentArgs",
"validatorLayer",
"dataUsingNamespace",
"databaseUsingNamespace",
"entityFrameworkUsingNamespace",
"cosmosUsingNamespace",
"odataUsingNamespace",
"eventOutbox",
"eventSubjectFormat",
"eventCasing");
WarnWhereDeprecated(this, this,
("databaseName", " Please use 'databaseType' instead.", false),
("entityFrameworkName", " Please use 'entityFrameworkType' instead.", false),
("cosmosName", " Please use 'cosmosType' instead.", false),
("odataName", " Please use 'odataType' instead.", false),
("httpAgentName", " Please use 'httpAgentType' instead.", false));
}
/// <summary>
/// Warn where the property has been deprecated.
/// </summary>
/// <param name="root">The root <see cref="CodeGenConfig"/>.</param>
/// <param name="config">The <see cref="ConfigBase"/>.</param>
/// <param name="names">The list of deprecated properties.</param>
internal static void WarnWhereDeprecated(CodeGenConfig root, ConfigBase config, params string[] names)
{
if (config.ExtraProperties == null || config.ExtraProperties.Count == 0 || names.Length == 0)
return;
foreach (var xp in config.ExtraProperties)
{
if (names.Contains(xp.Key))
root.CodeGenArgs?.Logger?.LogWarning("{Deprecated}", $"Warning: Config [{config.BuildFullyQualifiedName(xp.Key)}] has been deprecated and will be ignored.");
}
}
/// <summary>
/// Warn where the property has been deprecated.
/// </summary>
/// <param name="root">The root <see cref="CodeGenConfig"/>.</param>
/// <param name="config">The <see cref="ConfigBase"/>.</param>
/// <param name="properties">The list of deprecated properties.</param>
internal static void WarnWhereDeprecated(CodeGenConfig root, ConfigBase config, params (string Property, string? Message, bool IsError)[] properties)
{
if (config.ExtraProperties == null || config.ExtraProperties.Count == 0 || properties.Length == 0)
return;
foreach (var xp in config.ExtraProperties)
{
var (Property, Message, IsError) = properties!.FirstOrDefault(x => x.Property == xp.Key);
if (Property != null)
{
if (IsError)
throw new CodeGenException(Property, $"Config [{config.BuildFullyQualifiedName(xp.Key)}] has been deprecated and is no longer supported.{(string.IsNullOrEmpty(Message) ? string.Empty : Message)}");
else
root.CodeGenArgs?.Logger?.LogWarning("{Deprecated}", $"Warning: Config [{config.BuildFullyQualifiedName(xp.Key)}] has been deprecated.{(string.IsNullOrEmpty(Message) ? string.Empty : Message)}");
}
}
}
/// <summary>
/// Gets the formatted text.
/// </summary>
/// <param name="text">The original text.</param>
/// <param name="formatter">The text formatter function.</param>
/// <returns>The formatted text.</returns>
/// <remarks>Where the text starts with a <c>+</c> (plus sign) then the text will be used as-is (without the plus); otherwise, the formatter will be used.</remarks>
internal static string? GetFormattedText(string? text, Func<string, string?> formatter)
{
text = text?.TrimEnd();
if (string.IsNullOrEmpty(text))
return text;
if (text.StartsWith('+'))
return text[1..];
return formatter(text);
}
/// <summary>
/// Gets the sentence text.
/// </summary>
/// <param name="text">The original text.</param>
/// <returns>The text with a terminating full stop.</returns>
internal static string? GetSentenceText(string? text)
{
if (string.IsNullOrEmpty(text))
return text;
else
return text.EndsWith('.') ? text : text + ".";
}
}
}