From cc8f4713ebfc41c810d8cf92e881ee1393823fdc Mon Sep 17 00:00:00 2001 From: VisualBean Date: Tue, 26 Mar 2024 01:15:22 +0100 Subject: [PATCH] remove unused expressions --- .../Expressions/BodyExpression.cs | 68 ----------- .../Expressions/CompositeExpression.cs | 45 -------- .../Expressions/HeaderExpression.cs | 50 -------- .../Expressions/MethodExpression.cs | 20 ---- .../Expressions/PathExpression.cs | 50 -------- .../Expressions/QueryExpression.cs | 50 -------- .../Expressions/RequestExpression.cs | 34 ------ .../Expressions/ResponseExpression.cs | 34 ------ .../Expressions/RuntimeExpressions.cs | 107 ------------------ .../Expressions/SourceExpression.cs | 73 ------------ .../Expressions/StatusCodeExpression.cs | 27 ----- .../Expressions/UrlExpression.cs | 27 ----- .../Models/RuntimeExpressionAnyWrapper.cs | 71 ------------ 13 files changed, 656 deletions(-) delete mode 100644 src/LEGO.AsyncAPI/Expressions/BodyExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/CompositeExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/HeaderExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/MethodExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/PathExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/QueryExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/RequestExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/ResponseExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/RuntimeExpressions.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/SourceExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/StatusCodeExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Expressions/UrlExpression.cs delete mode 100644 src/LEGO.AsyncAPI/Models/RuntimeExpressionAnyWrapper.cs diff --git a/src/LEGO.AsyncAPI/Expressions/BodyExpression.cs b/src/LEGO.AsyncAPI/Expressions/BodyExpression.cs deleted file mode 100644 index 2e8fe5d7..00000000 --- a/src/LEGO.AsyncAPI/Expressions/BodyExpression.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Body expression. - /// - public sealed class BodyExpression : SourceExpression - { - /// - /// body string. - /// - public const string Body = "body"; - - /// - /// Prefix for a pointer. - /// - public const string PointerPrefix = "#"; - - /// - /// Initializes a new instance of the class. - /// - public BodyExpression() - : base(null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// a JSON Pointer [RFC 6901](https://tools.ietf.org/html/rfc6901). - public BodyExpression(JsonPointer pointer) - : base(pointer?.ToString()) - { - if (pointer == null) - { - throw Error.ArgumentNull(nameof(pointer)); - } - } - - /// - /// Gets the expression string. - /// - public override string Expression - { - get - { - if (string.IsNullOrWhiteSpace(this.Value)) - { - return Body; - } - - return Body + PointerPrefix + this.Value; - } - } - - /// - /// Gets the fragment string. - /// - public string Fragment - { - get - { - return this.Value; - } - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/CompositeExpression.cs b/src/LEGO.AsyncAPI/Expressions/CompositeExpression.cs deleted file mode 100644 index 62e1a823..00000000 --- a/src/LEGO.AsyncAPI/Expressions/CompositeExpression.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - using System.Collections.Generic; - using System.Linq; - using System.Text.RegularExpressions; - - /// - /// String literal with embedded expressions. - /// - public class CompositeExpression : RuntimeExpression - { - private readonly string template; - private Regex expressionPattern = new Regex(@"{(?\$[^}]*)"); - - /// - /// Expressions embedded into string literal. - /// - public List ContainedExpressions = new List(); - - /// - /// Create a composite expression from a string literal with an embedded expression. - /// - /// - public CompositeExpression(string expression) - { - this.template = expression; - - // Extract subexpressions and convert to RuntimeExpressions - var matches = this.expressionPattern.Matches(expression); - - foreach (var item in matches.Cast()) - { - var value = item.Groups["exp"].Captures.Cast().First().Value; - this.ContainedExpressions.Add(RuntimeExpression.Build(value)); - } - } - - /// - /// Return original string literal with embedded expression. - /// - public override string Expression => this.template; - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/HeaderExpression.cs b/src/LEGO.AsyncAPI/Expressions/HeaderExpression.cs deleted file mode 100644 index ebee9cd6..00000000 --- a/src/LEGO.AsyncAPI/Expressions/HeaderExpression.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Header expression, The token identifier in header is case-insensitive. - /// - public class HeaderExpression : SourceExpression - { - /// - /// header. string. - /// - public const string Header = "header."; - - /// - /// Initializes a new instance of the class. - /// - /// The token string, it's case-insensitive. - public HeaderExpression(string token) - : base(token) - { - if (string.IsNullOrWhiteSpace(token)) - { - throw Error.ArgumentNullOrWhiteSpace(nameof(token)); - } - } - - /// - /// Gets the expression string. - /// - public override string Expression - { - get - { - return Header + this.Value; - } - } - - /// - /// Gets the token string. - /// - public string Token - { - get - { - return this.Value; - } - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/MethodExpression.cs b/src/LEGO.AsyncAPI/Expressions/MethodExpression.cs deleted file mode 100644 index 95404d68..00000000 --- a/src/LEGO.AsyncAPI/Expressions/MethodExpression.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Method expression. - /// - public sealed class MethodExpression : RuntimeExpression - { - /// - /// $method. string. - /// - public const string Method = "$method"; - - /// - /// Gets the expression string. - /// - public override string Expression { get; } = Method; - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/PathExpression.cs b/src/LEGO.AsyncAPI/Expressions/PathExpression.cs deleted file mode 100644 index 8b89565f..00000000 --- a/src/LEGO.AsyncAPI/Expressions/PathExpression.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Path expression, the name in path is case-sensitive. - /// - public sealed class PathExpression : SourceExpression - { - /// - /// path. string. - /// - public const string Path = "path."; - - /// - /// Initializes a new instance of the class. - /// - /// The name string, it's case-insensitive. - public PathExpression(string name) - : base(name) - { - if (string.IsNullOrWhiteSpace(name)) - { - throw Error.ArgumentNullOrWhiteSpace(nameof(name)); - } - } - - /// - /// Gets the expression string. - /// - public override string Expression - { - get - { - return Path + this.Value; - } - } - - /// - /// Gets the name string. - /// - public string Name - { - get - { - return this.Value; - } - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/QueryExpression.cs b/src/LEGO.AsyncAPI/Expressions/QueryExpression.cs deleted file mode 100644 index 7aebbb8e..00000000 --- a/src/LEGO.AsyncAPI/Expressions/QueryExpression.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Query expression, the name in query is case-sensitive. - /// - public sealed class QueryExpression : SourceExpression - { - /// - /// query. string. - /// - public const string Query = "query."; - - /// - /// Initializes a new instance of the class. - /// - /// The name string, it's case-insensitive. - public QueryExpression(string name) - : base(name) - { - if (string.IsNullOrWhiteSpace(name)) - { - throw Error.ArgumentNullOrWhiteSpace(nameof(name)); - } - } - - /// - /// Gets the expression string. - /// - public override string Expression - { - get - { - return Query + this.Value; - } - } - - /// - /// Gets the name string. - /// - public string Name - { - get - { - return this.Value; - } - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/RequestExpression.cs b/src/LEGO.AsyncAPI/Expressions/RequestExpression.cs deleted file mode 100644 index 47850bf9..00000000 --- a/src/LEGO.AsyncAPI/Expressions/RequestExpression.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// $request. expression. - /// - public sealed class RequestExpression : RuntimeExpression - { - /// - /// $request. string. - /// - public const string Request = "$request."; - - /// - /// Initializes a new instance of the class. - /// - /// The source of the request. - public RequestExpression(SourceExpression source) - { - this.Source = source ?? throw Error.ArgumentNull(nameof(source)); - } - - /// - /// Gets the expression string. - /// - public override string Expression => Request + this.Source.Expression; - - /// - /// The expression. - /// - public SourceExpression Source { get; } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/ResponseExpression.cs b/src/LEGO.AsyncAPI/Expressions/ResponseExpression.cs deleted file mode 100644 index 8a335209..00000000 --- a/src/LEGO.AsyncAPI/Expressions/ResponseExpression.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// $response. expression. - /// - public sealed class ResponseExpression : RuntimeExpression - { - /// - /// $response. string. - /// - public const string Response = "$response."; - - /// - /// Initializes a new instance of the class. - /// - /// The source of the response. - public ResponseExpression(SourceExpression source) - { - this.Source = source ?? throw Error.ArgumentNull(nameof(source)); - } - - /// - /// Gets the expression string. - /// - public override string Expression => Response + this.Source.Expression; - - /// - /// The expression. - /// - public SourceExpression Source { get; } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/RuntimeExpressions.cs b/src/LEGO.AsyncAPI/Expressions/RuntimeExpressions.cs deleted file mode 100644 index 2c88373a..00000000 --- a/src/LEGO.AsyncAPI/Expressions/RuntimeExpressions.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - using System; - using LEGO.AsyncAPI.Exceptions; - - /// - /// Base class for the AsyncApi runtime expression. - /// - public abstract class RuntimeExpression : IEquatable - { - /// - /// The dollar sign prefix for a runtime expression. - /// - public const string Prefix = "$"; - - /// - /// The expression string. - /// - public abstract string Expression { get; } - - /// - /// Build the runtime expression from input string. - /// - /// The runtime expression. - /// The built runtime expression object. - public static RuntimeExpression Build(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) - { - throw Error.ArgumentNullOrWhiteSpace(nameof(expression)); - } - - if (!expression.StartsWith(Prefix)) - { - return new CompositeExpression(expression); - } - - // $url - if (expression == UrlExpression.Url) - { - return new UrlExpression(); - } - - // $method - if (expression == MethodExpression.Method) - { - return new MethodExpression(); - } - - // $statusCode - if (expression == StatusCodeExpression.StatusCode) - { - return new StatusCodeExpression(); - } - - // $request. - if (expression.StartsWith(RequestExpression.Request)) - { - var subString = expression.Substring(RequestExpression.Request.Length); - var source = SourceExpression.Build(subString); - return new RequestExpression(source); - } - - // $response. - if (expression.StartsWith(ResponseExpression.Response)) - { - var subString = expression.Substring(ResponseExpression.Response.Length); - var source = SourceExpression.Build(subString); - return new ResponseExpression(source); - } - - throw new AsyncApiException(string.Format("The runtime expression '{0}' has invalid format.", expression)); - } - - /// - /// GetHashCode implementation for IEquatable. - /// - public override int GetHashCode() - { - return this.Expression.GetHashCode(); - } - - /// - /// Equals implementation for IEquatable. - /// - public override bool Equals(object obj) - { - return this.Equals(obj as RuntimeExpression); - } - - /// - /// Equals implementation for object of the same type. - /// - public bool Equals(RuntimeExpression obj) - { - return obj != null && obj.Expression == this.Expression; - } - - /// - public override string ToString() - { - return this.Expression; - } - } -} diff --git a/src/LEGO.AsyncAPI/Expressions/SourceExpression.cs b/src/LEGO.AsyncAPI/Expressions/SourceExpression.cs deleted file mode 100644 index c5bbde98..00000000 --- a/src/LEGO.AsyncAPI/Expressions/SourceExpression.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - using LEGO.AsyncAPI.Exceptions; - - /// - /// Source expression. - /// - public abstract class SourceExpression : RuntimeExpression - { - /// - /// Initializes a new instance of the class. - /// - /// The value string. - protected SourceExpression(string value) - { - this.Value = value; - } - - /// - /// Gets the expression string. - /// - protected string Value { get; } - - /// - /// Build the source expression from input string. - /// - /// The source expression. - /// The built source expression. - public new static SourceExpression Build(string expression) - { - if (!string.IsNullOrWhiteSpace(expression)) - { - var expressions = expression.Split('.'); - if (expressions.Length == 2) - { - if (expression.StartsWith(HeaderExpression.Header)) - { - // header. - return new HeaderExpression(expressions[1]); - } - - if (expression.StartsWith(QueryExpression.Query)) - { - // query. - return new QueryExpression(expressions[1]); - } - - if (expression.StartsWith(PathExpression.Path)) - { - // path. - return new PathExpression(expressions[1]); - } - } - - // body - if (expression.StartsWith(BodyExpression.Body)) - { - var subString = expression.Substring(BodyExpression.Body.Length); - if (string.IsNullOrEmpty(subString)) - { - return new BodyExpression(); - } - - return new BodyExpression(new JsonPointer(subString)); - } - } - - throw new AsyncApiException(string.Format("The source expression '{0}' has invalid format.", expression)); - } - } -} diff --git a/src/LEGO.AsyncAPI/Expressions/StatusCodeExpression.cs b/src/LEGO.AsyncAPI/Expressions/StatusCodeExpression.cs deleted file mode 100644 index c8ef862e..00000000 --- a/src/LEGO.AsyncAPI/Expressions/StatusCodeExpression.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// StatusCode expression. - /// - public sealed class StatusCodeExpression : RuntimeExpression - { - /// - /// $statusCode string. - /// - public const string StatusCode = "$statusCode"; - - /// - /// Gets the expression string. - /// - public override string Expression { get; } = StatusCode; - - /// - /// Private constructor. - /// - public StatusCodeExpression() - { - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Expressions/UrlExpression.cs b/src/LEGO.AsyncAPI/Expressions/UrlExpression.cs deleted file mode 100644 index 83e01aa4..00000000 --- a/src/LEGO.AsyncAPI/Expressions/UrlExpression.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Expressions -{ - /// - /// Url expression. - /// - public sealed class UrlExpression : RuntimeExpression - { - /// - /// $url string. - /// - public const string Url = "$url"; - - /// - /// Gets the expression string. - /// - public override string Expression { get; } = Url; - - /// - /// Private constructor. - /// - public UrlExpression() - { - } - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Models/RuntimeExpressionAnyWrapper.cs b/src/LEGO.AsyncAPI/Models/RuntimeExpressionAnyWrapper.cs deleted file mode 100644 index 130746ea..00000000 --- a/src/LEGO.AsyncAPI/Models/RuntimeExpressionAnyWrapper.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Models -{ - using LEGO.AsyncAPI.Expressions; - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - - /// - /// The wrapper either for or . - /// - public class RuntimeExpressionAnyWrapper : IAsyncApiElement - { - private AsyncApiAny any; - private RuntimeExpression expression; - - /// - /// Gets/Sets the . - /// - public AsyncApiAny Any - { - get - { - return this.any; - } - - set - { - this.expression = null; - this.any = value; - } - } - - /// - /// Gets/Set the . - /// - public RuntimeExpression Expression - { - get - { - return this.expression; - } - - set - { - this.any = null; - this.expression = value; - } - } - - /// - /// Write . - /// - public void WriteValue(IAsyncApiWriter writer) - { - if (writer == null) - { - throw Error.ArgumentNull(nameof(writer)); - } - - if (this.any != null) - { - writer.WriteAny(this.any); - } - else if (this.expression != null) - { - writer.WriteValue(this.expression.Expression); - } - } - } -} \ No newline at end of file