Skip to content

Commit

Permalink
Fix by dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mielek committed Aug 23, 2024
1 parent c496cd2 commit 91df2a3
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 83 deletions.
14 changes: 7 additions & 7 deletions src/Authoring/Configs/CorsConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;

/// <summary>
/// The cors policy adds cross-origin resource sharing (CORS) support to an operation or an API to allow cross-domain calls from browser-based clients.
Expand All @@ -9,7 +9,7 @@ public class CorsConfig
/// The Access-Control-Allow-Credentials header in the preflight response will be set to the value of this attribute and affect the client's ability to submit credentials in cross-domain requests. Policy expressions are allowed.
/// </summary>
public bool? AllowCredentials { get; init; }

/// <summary>
/// Controls the processing of cross-origin requests that don't match the policy settings. Policy expressions are allowed.
/// When OPTIONS request is processed as a preflight request and Origin header doesn't match policy settings:
Expand All @@ -20,27 +20,27 @@ public class CorsConfig
/// - If the attribute is set to false, allow the request to proceed normally and don't add CORS headers to the response
/// </summary>
public string? TerminateUnmatchedRequest { get; init; }

/// <summary>
/// Contains origin elements that describe the allowed origins for cross-domain requests. allowed-origins can contain either a single origin element that specifies * to allow any origin, or one or more origin elements that contain a URI.
/// </summary>
public required string[] AllowedOrigins { get; init; }

/// <summary>
/// This element is required if methods other than GET or POST are allowed. Contains method elements that specify the supported HTTP verbs. The value * indicates all methods.
/// </summary>
public string[]? AllowedMethods { get; init; }

/// <summary>
/// The Access-Control-Max-Age header in the preflight response will be set to the value of this attribute and affect the user agent's ability to cache the preflight response. Policy expressions are allowed.
/// </summary>
public uint? PreflightResultMaxAge { get; init; }

/// <summary>
/// This element contains header elements specifying names of the headers that can be included in the request.
/// </summary>
public required string[] AllowedHeaders { get; init; }

/// <summary>
/// This element contains header elements specifying names of the headers that will be accessible by the client.
/// </summary>
Expand Down
20 changes: 10 additions & 10 deletions src/Authoring/Configs/ForwardRequestConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;

/// <summary>
/// Configuration of forward request policy
Expand All @@ -11,50 +11,50 @@ public class ForwardRequestConfig
/// Policy expressions are allowed. You can specify either timeout or timeout-ms but not both.
/// </summary>
public uint? Timeout { get; init; }

/// <summary>
/// The amount of time in milliseconds to wait for the HTTP response headers to be returned by the backend service before a timeout error is raised.
/// Minimum value is 0 ms. Policy expressions are allowed. You can specify either timeout or timeout-ms but not both.
/// </summary>
public uint? TimeoutMs { get; init; }

/// <summary>
/// The amount of time in seconds to wait for a 100 Continue status code to be returned by the backend service before a timeout error is raised. Policy expressions are allowed.
/// </summary>
public uint? ContinueTimeout { get; init; }

/// <summary>
/// The HTTP spec version to use when sending the HTTP response to the backend service. When using 2or1, the gateway will favor HTTP /2 over /1, but fall back to HTTP /1 if HTTP /2 doesn't work.
/// </summary>
public string? HttpVersion { get; init; }

/// <summary>
/// Specifies whether redirects from the backend service are followed by the gateway or returned to the caller. Policy expressions are allowed.
/// </summary>
public bool? FollowRedirects { get; init; }

/// <summary>
/// When set to true, request is buffered and will be reused on retry.
/// </summary>
public bool? BufferRequestBody { get; init; }

/// <summary>
/// Affects processing of chunked responses. When set to false, each chunk received from the backend is immediately returned to the caller.
/// When set to true, chunks are buffered (8 KB, unless end of stream is detected) and only then returned to the caller.
/// Set to false with backends such as those implementing server-sent events (SSE) that require content to be returned or streamed immediately to the caller. Policy expressions aren't allowed.
/// </summary>
public bool? BufferResponse { get; init; }

/// <summary>
/// When set to true, triggers on-error section for response codes in the range from 400 to 599 inclusive. Policy expressions aren't allowed.
/// </summary>
public bool? FailOnErrorStatusCode { get; init; }

public ForwardRequestConfig()
{
if(Timeout.HasValue && TimeoutMs.HasValue)
if (Timeout.HasValue && TimeoutMs.HasValue)
{
throw new ArgumentException("You can specify either timeout or timeout-ms but not both.");
}
}
}
}
2 changes: 1 addition & 1 deletion src/Authoring/Configs/SetBodyConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;

public class SetBodyConfig
{
Expand Down
2 changes: 1 addition & 1 deletion src/Authoring/DocumentScope.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
namespace Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;

public enum DocumentScope
{
Expand Down
2 changes: 1 addition & 1 deletion src/Authoring/IOutboundContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface IOutboundContext : IHaveExpressionContext
void Base();

void SetBody(string body);

/// <summary>
/// Inlines the specified policy as is to policy document.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{
var result = new CSharpPolicyCompiler(document).Compile();

foreach(var error in result.Errors)
foreach (var error in result.Errors)
{
Console.Out.WriteLine(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/CSharpPolicyCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Compilation/CompilationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis;

Expand All @@ -8,13 +8,13 @@ public class CompilationContext : ICompilationContext, ICompilationResult
{
private readonly IList<string> _errors = new List<string>();
private readonly XElement _rootElement;

public CompilationContext(SyntaxNode syntaxRoot, XElement rootElement)
{
SyntaxRoot = syntaxRoot;
_rootElement = rootElement;
}

public void AddPolicy(XNode element) => _rootElement.Add(element);

public void ReportError(string message) => _errors.Add(message);
Expand Down
5 changes: 3 additions & 2 deletions src/Core/Compilation/CompilerUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Expressions;
Expand Down Expand Up @@ -70,7 +70,8 @@ public static InitializerValue Process(

return new InitializerValue
{
Type = (creationSyntax.Type as IdentifierNameSyntax)?.Identifier.ValueText, NamedValues = result,
Type = (creationSyntax.Type as IdentifierNameSyntax)?.Identifier.ValueText,
NamedValues = result,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/IMethodPolicyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Mielek.Azure.ApiManagement.PolicyToolkit.Compilation;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/IReturnValueMethodPolicyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Mielek.Azure.ApiManagement.PolicyToolkit.Compilation;

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Compilation/Policy/AuthenticationBasicCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;
using Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;

namespace Mielek.Azure.ApiManagement.PolicyToolkit.Compilation.Policy;

Expand All @@ -10,7 +10,7 @@ public class AuthenticationBasicCompiler : IMethodPolicyHandler
public string MethodName => nameof(IInboundContext.AuthenticationBasic);
public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
{
if(node.ArgumentList.Arguments.Count != 2)
if (node.ArgumentList.Arguments.Count != 2)
{
context.ReportError($"Wrong argument count for authentication-basic policy. {node.GetLocation()}");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;
using Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;

namespace Mielek.Azure.ApiManagement.PolicyToolkit.Compilation.Policy;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/Policy/BaseCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/Policy/CorsCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down
25 changes: 14 additions & 11 deletions src/Core/Compilation/Policy/ForwardRequestCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand All @@ -19,7 +19,7 @@ public class ForwardRequestCompiler : IMethodPolicyHandler
{ nameof(ForwardRequestConfig.BufferResponse), "buffer-response" },
{ nameof(ForwardRequestConfig.FailOnErrorStatusCode), "fail-on-error-status-code" }
};

public string MethodName => nameof(IBackendContext.ForwardRequest);

public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
Expand All @@ -35,25 +35,28 @@ public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
{
if (node.ArgumentList.Arguments[0].Expression is not ObjectCreationExpressionSyntax config)
{
context.ReportError($"Forward request policy argument must be an object creation expression. {node.GetLocation()}");
context.ReportError(
$"Forward request policy argument must be an object creation expression. {node.GetLocation()}");
return;
}

var initializer = config.Process(context);
if(initializer.Type != nameof(ForwardRequestConfig))
if (initializer.Type != nameof(ForwardRequestConfig))
{
context.ReportError($"Forward request policy argument must be of type ForwardRequestConfig. {node.GetLocation()}");
context.ReportError(
$"Forward request policy argument must be of type ForwardRequestConfig. {node.GetLocation()}");
return;
}

if (initializer.NamedValues is not null)
{
if(initializer.NamedValues.ContainsKey(nameof(ForwardRequestConfig.Timeout))
&& initializer.NamedValues.ContainsKey(nameof(ForwardRequestConfig.TimeoutMs)))
if (initializer.NamedValues.ContainsKey(nameof(ForwardRequestConfig.Timeout))
&& initializer.NamedValues.ContainsKey(nameof(ForwardRequestConfig.TimeoutMs)))
{
context.ReportError($"Forward request policy cannot have both timeout and timeout-ms. {node.GetLocation()}");
context.ReportError(
$"Forward request policy cannot have both timeout and timeout-ms. {node.GetLocation()}");
}

foreach ((string key, InitializerValue value) in initializer.NamedValues)
{
var name = FieldToAttribute.GetValueOrDefault(key, key);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/Policy/InlinePolicyCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml;
using System.Xml;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/Policy/SetBodyCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;

using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Compilation/Policy/SetHeaderCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Xml.Linq;

using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;
using Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using System.Xml.Linq;
using Mielek.Azure.ApiManagement.PolicyToolkit.Authoring;
using Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies;

using static Mielek.Azure.ApiManagement.PolicyToolkit.Builders.Policies.SetHeaderPolicyBuilder;

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Compilation/Syntax/BlockCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand All @@ -17,13 +17,13 @@ public void AddCompiler(ISyntaxCompiler compiler)
{
_compilers.Add(compiler.Syntax, compiler);
}

public SyntaxKind Syntax => SyntaxKind.Block;

public void Compile(ICompilationContext context, SyntaxNode node)
{
var block = node as BlockSyntax ?? throw new NullReferenceException();

foreach (var statement in block.Statements)
{
if (_compilers.TryGetValue(statement.Kind(), out var compiler))
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Compilation/Syntax/ExpressionStatementCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down Expand Up @@ -26,7 +26,7 @@ public void Compile(ICompilationContext context, SyntaxNode node)
}

var memberAccess = invocation.Expression as MemberAccessExpressionSyntax;
if(memberAccess == null)
if (memberAccess == null)
{
context.ReportError($"{invocation.Expression.GetType().Name} is not supported. {invocation.Expression.GetLocation()}");
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Compilation/Syntax/IfStatementCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Net;
using System.Net;
using System.Xml.Linq;

using Microsoft.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Serialization/RazorCodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static string ToCleanXml(string code, out IReadOnlyDictionary<string, str
result.Append(code, lastIndex, match.Index - lastIndex);
var index = FindClosingIndex(code, match, out var isMultiline);
var cSharpCode = code.Substring(match.Index + 2, index - match.Index - 2).Trim();
var formatlessCode = new TriviaRemoverRewriter().Visit(CSharpSyntaxTree.ParseText(cSharpCode).GetRoot()).NormalizeWhitespace("", "").ToString();
var formatlessCode = new TriviaRemoverRewriter().Visit(CSharpSyntaxTree.ParseText(cSharpCode).GetRoot()).NormalizeWhitespace("", "").ToString();
var marker = $"__expression__{Guid.NewGuid()}__";
expressions.Add(marker, isMultiline ? $"@{{{formatlessCode}}}" : $"@({formatlessCode})");
result.Append(marker);
Expand Down
4 changes: 2 additions & 2 deletions src/Emulator/ApimRuntimeEmulator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Mielek.Azure.ApiManagement.PolicyToolkit.Emulator;
using Mielek.Azure.ApiManagement.PolicyToolkit.Emulator;

public class ApimRuntimeEmulator
{

}
Loading

0 comments on commit 91df2a3

Please sign in to comment.