diff --git a/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs b/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs index ba742fef0..07195c69e 100644 --- a/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs +++ b/ArchiSteamFarm/IPC/Integration/CustomAttributesSchemaFilter.cs @@ -41,9 +41,9 @@ namespace ArchiSteamFarm.IPC.Integration { return; } - context.MemberInfo.GetCustomAttribute()?.Apply(schema); - context.MemberInfo.GetCustomAttribute()?.Apply(schema); - context.MemberInfo.GetCustomAttribute()?.Apply(schema); + foreach (CustomSwaggerAttribute customSwaggerAttribute in context.MemberInfo.GetCustomAttributes()) { + customSwaggerAttribute.Apply(schema); + } } } } diff --git a/ArchiSteamFarm/IPC/Integration/CustomSwaggerAttribute.cs b/ArchiSteamFarm/IPC/Integration/CustomSwaggerAttribute.cs new file mode 100644 index 000000000..df2db1d61 --- /dev/null +++ b/ArchiSteamFarm/IPC/Integration/CustomSwaggerAttribute.cs @@ -0,0 +1,31 @@ +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// | +// Copyright 2015-2021 Ɓukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using JetBrains.Annotations; +using Microsoft.OpenApi.Models; + +namespace ArchiSteamFarm.IPC.Integration { + [PublicAPI] + public abstract class CustomSwaggerAttribute : Attribute { + public abstract void Apply(OpenApiSchema schema); + } +} diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs index 669c98775..ab212ff21 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs @@ -20,14 +20,13 @@ // limitations under the License. using System; -using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; using Microsoft.OpenApi.Models; namespace ArchiSteamFarm.IPC.Integration { [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] [PublicAPI] - public sealed class SwaggerItemsMinMaxAttribute : ValidationAttribute { + public sealed class SwaggerItemsMinMaxAttribute : CustomSwaggerAttribute { public uint MaximumUint { get => BackingMaximum.HasValue ? decimal.ToUInt32(BackingMaximum.Value) : default(uint); set => BackingMaximum = value; @@ -41,7 +40,7 @@ namespace ArchiSteamFarm.IPC.Integration { private decimal? BackingMaximum; private decimal? BackingMinimum; - public void Apply(OpenApiSchema schema) { + public override void Apply(OpenApiSchema schema) { if (schema == null) { throw new ArgumentNullException(nameof(schema)); } diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs index 56af37bf9..77ab3a64f 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerSteamIdentifierAttribute.cs @@ -20,7 +20,6 @@ // limitations under the License. using System; -using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; using Microsoft.OpenApi.Models; using SteamKit2; @@ -28,13 +27,13 @@ using SteamKit2; namespace ArchiSteamFarm.IPC.Integration { [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] [PublicAPI] - public sealed class SwaggerSteamIdentifierAttribute : ValidationAttribute { + public sealed class SwaggerSteamIdentifierAttribute : CustomSwaggerAttribute { public EAccountType AccountType { get; set; } = EAccountType.Individual; public uint MaximumAccountID { get; set; } = uint.MaxValue; public uint MinimumAccountID { get; set; } = 1; public EUniverse Universe { get; set; } = EUniverse.Public; - public void Apply(OpenApiSchema schema) { + public override void Apply(OpenApiSchema schema) { if (schema == null) { throw new ArgumentNullException(nameof(schema)); } diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs index 336c96ff9..d3bee9425 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs @@ -20,7 +20,6 @@ // limitations under the License. using System; -using System.ComponentModel.DataAnnotations; using System.Linq; using JetBrains.Annotations; using Microsoft.OpenApi.Any; @@ -30,11 +29,11 @@ using Microsoft.OpenApi.Models; namespace ArchiSteamFarm.IPC.Integration { [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] [PublicAPI] - public sealed class SwaggerValidValuesAttribute : ValidationAttribute { + public sealed class SwaggerValidValuesAttribute : CustomSwaggerAttribute { public int[]? ValidIntValues { get; set; } public string[]? ValidStringValues { get; set; } - public void Apply(OpenApiSchema schema) { + public override void Apply(OpenApiSchema schema) { if (schema == null) { throw new ArgumentNullException(nameof(schema)); }