Skip to content

Commit

Permalink
Resolve #74. (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored Sep 24, 2020
1 parent b0f4511 commit a01222a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tools/Beef.CodeGen.Core/Beef.CodeGen.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Beef.CodeGen</RootNamespace>
<Version>4.1.2</Version>
<Version>4.1.3</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ApplicationIcon />
<StartupObject />
Expand Down
5 changes: 4 additions & 1 deletion tools/Beef.CodeGen.Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v4.1.3
- *Fixed*: Issue [74](https://github.com/Avanade/Beef/issues/74) fixed. `WebApiAuthorize` attribute was honouring previous override sideeffect. Changed attribute configuration from a `bool` to a `string`. Code-gen will output the supplied value as-is. XML boolean values are automatically converted. _Note:_ the XML Schema and corresponding documentation have not been updated; this will occur during a future release.

## v4.1.2
- *Enhancement:* The is the first stage of the custom code-gen capability retirement; to be replaced by [`Handlebars.Net`](https://github.com/rexm/Handlebars.Net) as the code-generation engine. All the _entity_ and _reference date_ related code-generation templates (and related) have been ported. The _database_ related code-generation is still using the legacy custom.
- *Enhancement:* The `CodeGen` namespace from `Beef.Core` has been moved relocated. A new `StringConversion` now provides access to the existing string conversion functions (e.g. `ToSentenceCase`).
Expand All @@ -11,7 +14,7 @@ Represents the **NuGet** versions.
- *Enhancement:* Introduction of Dependency Injection support.

## v3.1.20
- *Fixed*: Issue [66](https://github.com/Avanade/Beef/issues/63) fixed. Changed the path separator to be `/` so that is compatible on Windows and Linux. By using `/` this matches the `Path.AltDirectorySeparatorChar`(https://docs.microsoft.com/en-us/dotnet/api/system.io.path.altdirectoryseparatorchar) for Windows and `Path.DirectorySeparatorChar`(https://docs.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar) for Linux, making it universally compatible.
- *Fixed*: Issue [66](https://github.com/Avanade/Beef/issues/66) fixed. Changed the path separator to be `/` so that is compatible on Windows and Linux. By using `/` this matches the `Path.AltDirectorySeparatorChar`(https://docs.microsoft.com/en-us/dotnet/api/system.io.path.altdirectoryseparatorchar) for Windows and `Path.DirectorySeparatorChar`(https://docs.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar) for Linux, making it universally compatible.

## v3.1.19
- *Enhancment:* Request [62](https://github.com/Avanade/Beef/issues/62) applied. Generate a non-zero exit code when detecting updated files if none are expected. E.g. if executing the code generation as part of build pipeline.
Expand Down
10 changes: 5 additions & 5 deletions tools/Beef.CodeGen.Core/Config/Entity/CodeGenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public class CodeGenConfig : ConfigBase<CodeGenConfig, CodeGenConfig>, IRootConf
#region WebApi

/// <summary>
/// Indicates whether the Web API controller should use <c>Authorize</c> (<c>true</c>); otherwise, <c>AllowAnonynous</c> (<c>false</c>).
/// 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>
[JsonProperty("webApiAuthorize", DefaultValueHandling = DefaultValueHandling.Ignore)]
[PropertySchema("WebApi", Title = "Indicates whether the Web API controller should use `Authorize` (`true`); otherwise, `AllowAnonynous` (`false`).",
Description = "Defaults to the `AllowAnonynous` (`false`). This can be overidden within the `Entity`(s) and/or their corresponding `Operation`(s).")]
public bool? WebApiAuthorize { get; set; }
[PropertySchema("WebApi", Title = "The authorize attribute value to be used for the corresponding entity Web API controller; generally either `Authorize` or `AllowAnonymous`.",
Description = "Defaults to the `AllowAnonymous`. This can be overidden within the `Entity`(s) and/or their corresponding `Operation`(s).")]
public string? WebApiAuthorize { get; set; }

#endregion

Expand Down Expand Up @@ -408,7 +408,7 @@ protected override void Prepare()
ODataName = DefaultWhereNull(ODataName, () => "IOData");
JsonSerializer = DefaultWhereNull(JsonSerializer, () => "Newtonsoft");
RefDataDefaultMapperConverter = DefaultWhereNull(RefDataDefaultMapperConverter, () => "ReferenceDataCodeConverter");
WebApiAuthorize = DefaultWhereNull(WebApiAuthorize, () => false);
WebApiAuthorize = DefaultWhereNull(WebApiAuthorize, () => "AllowAnonymous");

if (Entities != null && Entities.Count > 0)
{
Expand Down
6 changes: 3 additions & 3 deletions tools/Beef.CodeGen.Core/Config/Entity/EntityConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,12 @@ public class EntityConfig : ConfigBase<CodeGenConfig, CodeGenConfig>
public string? WebApiRoutePrefix { get; set; }

/// <summary>
/// Indicates whether the Web API controller should use <c>Authorize</c> (<c>true</c>); otherwise, <c>AllowAnonynous</c> (<c>false</c>).
/// 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>
[JsonProperty("webApiAuthorize", DefaultValueHandling = DefaultValueHandling.Ignore)]
[PropertySchema("WebApi", Title = "Indicates whether the Web API controller should use `Authorize` (`true`); otherwise, `AllowAnonynous` (`false`).",
[PropertySchema("WebApi", Title = "The authorize attribute value to be used for the corresponding entity Web API controller; generally either `Authorize` or `AllowAnonymous`.",
Description = "Defaults to the `CodeGeneration.WebApiAuthorize` configuration property (inherits) where not specified; can be overridden at the `Operation` level also.")]
public bool? WebApiAuthorize { get; set; }
public string? WebApiAuthorize { get; set; }

/// <summary>
/// Gets or sets the access modifier for the generated Web API `Controller` constructor.
Expand Down
9 changes: 9 additions & 0 deletions tools/Beef.CodeGen.Core/Config/Entity/OperationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ public class OperationConfig : ConfigBase<CodeGenConfig, EntityConfig>
[PropertySchema("WebApi", Title = "The Web API `RouteAtttribute` to be appended to the `Entity.WebApiRoutePrefix`.", IsImportant = true)]
public string? WebApiRoute { get; set; }

/// <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>
[JsonProperty("webApiAuthorize", DefaultValueHandling = DefaultValueHandling.Ignore)]
[PropertySchema("WebApi", Title = "The authorize attribute value to be used for the corresponding entity Web API controller; generally either `Authorize` or `AllowAnonymous`.",
Description = "Defaults to the `Entity.WebApiAuthorize` configuration property (inherits) where not specified.")]
public string? WebApiAuthorize { get; set; }

/// <summary>
/// Gets or sets the HTTP Method for the operation.
/// </summary>
Expand Down Expand Up @@ -698,6 +706,7 @@ protected override void Prepare()

PrepareParameters();

WebApiAuthorize = DefaultWhereNull(WebApiAuthorize, () => Parent!.WebApiAuthorize);
WebApiRoute = DefaultWhereNull(WebApiRoute, () => Type switch
{
"GetColl" => "",
Expand Down
5 changes: 4 additions & 1 deletion tools/Beef.CodeGen.Core/Config/XmlJsonRename.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public static class XmlJsonRename

private static readonly List<(ConfigurationEntity Entity, string XmlName, Func<string?, string?> Converter)> _xmlToJsonConvert = new List<(ConfigurationEntity, string, Func<string?, string?>)>(new (ConfigurationEntity, string, Func<string?, string?>)[]
{
(ConfigurationEntity.Entity, "ExcludeData", (xml) => string.IsNullOrEmpty(xml) ? null : (xml == "true" ? "Yes" : "Mapper"))
(ConfigurationEntity.CodeGen, "WebApiAuthorize", (xml) => string.IsNullOrEmpty(xml) ? null : (xml == "true" ? "Authorize" : (xml == "false" ? "Authorize" : xml))),
(ConfigurationEntity.Entity, "ExcludeData", (xml) => string.IsNullOrEmpty(xml) ? null : (xml == "true" ? "Yes" : "Mapper")),
(ConfigurationEntity.Entity, "WebApiAuthorize", (xml) => string.IsNullOrEmpty(xml) ? null : (xml == "true" ? "Authorize" : (xml == "false" ? "Authorize" : xml))),
(ConfigurationEntity.Operation, "WebApiAuthorize", (xml) => string.IsNullOrEmpty(xml) ? null : (xml == "true" ? "Authorize" : (xml == "false" ? "Authorize" : xml)))
});

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions tools/Beef.CodeGen.Core/Templates/EntityGrpcService_cs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {{Root.Company}}.{{Root.AppName}}.{{Root.ApiName}}.Grpc
/// <summary>
/// Provides the {{{EntityNameSeeComments}}} gRPC Server functionality.
/// </summary>
[{{#if WebApiAuthorize}}Authorize{{else}}AllowAnonymous{{/if}}]
[{{WebApiAuthorize}}]
public partial class {{Name}}Service : {{Name}}GrpcService.{{Name}}GrpcServiceBase
{
private readonly I{{Name}}Manager _manager;
Expand All @@ -52,7 +52,7 @@ namespace {{Root.Company}}.{{Root.AppName}}.{{Root.ApiName}}.Grpc
/// <param name="request">The <see cref="{{Parent.Name}}{{Name}}Request"/>.</param>
/// <param name="context">The <see cref="ServerCallContext"/>.</param>
/// <returns>The {{#if HasReturnValue}}{{seecomments ReturnType}}{{else}}{{seecomments 'Google.Protobuf.WellKnownTypes.Empty'}}{{/if}}.</returns>
[{{#if WebApiAuthorize}}Authorize{{else}}AllowAnonymous{{/if}}]
[{{WebApiAuthorize}}]
public override Task<{{#if HasReturnValue}}{{ReturnType}}{{else}}Google.Protobuf.WellKnownTypes.Empty{{/if}}> {{Name}}({{Parent.Name}}{{Name}}Request request, ServerCallContext context)
{
return new GrpcService<{{#if HasReturnValue}}{{ReturnType}}{{else}}Google.Protobuf.WellKnownTypes.Empty{{/if}}>(context, async () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace {{Root.Company}}.{{Root.AppName}}.{{Root.ApiName}}.Controllers
/// <summary>
/// Provides the {{{EntityNameSeeComments}}} Web API functionality.
/// </summary>
[{{#if WebApiAuthorize}}Authorize{{else}}AllowAnonymous{{/if}}]
[{{{WebApiAuthorize}}}]
{{#ifval WebApiRoutePrefix}}
[Route("{{WebApiRoutePrefix}}")]
{{/ifval}}
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace {{Root.Company}}.{{Root.AppName}}.{{Root.ApiName}}.Controllers
{{#if HasReturnValue}}
/// <returns>{{{WebApiReturnText}}}</returns>
{{/if}}
[{{#if WebApiAuthorize}}Authorize{{else}}AllowAnonymous{{/if}}]
[{{{WebApiAuthorize}}}]
[{{WebApiMethod}}("{{WebApiRoute}}")]
[ProducesResponseType({{#if HasReturnValue}}typeof({{#ifeq Type 'GetColl'}}{{BaseReturnType}}Collection{{else}}{{BaseReturnType}}{{/ifeq}}), {{/if}}(int)HttpStatusCode.{{WebApiStatus}})]
{{#if HasReturnValue}}
Expand Down

0 comments on commit a01222a

Please sign in to comment.