-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpful limitations on properties for JustArchiNET/ASF-ui#1445
Monologue explaining how it works: https://ptb.discord.com/channels/267292556709068800/332735075315744768/859854787634004049 (eventually also on wiki)
- Loading branch information
Showing
5 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// _ _ _ ____ _ _____ | ||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ | ||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ | ||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | | ||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| | ||
// | | ||
// 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 System.Linq; | ||
using ArchiSteamFarm.Steam.Storage; | ||
using JetBrains.Annotations; | ||
using Microsoft.OpenApi.Any; | ||
using Microsoft.OpenApi.Extensions; | ||
using Microsoft.OpenApi.Models; | ||
using SteamKit2; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace ArchiSteamFarm.IPC.Integration { | ||
[UsedImplicitly] | ||
internal sealed class BotConfigSchemaFilter : ISchemaFilter { | ||
public void Apply(OpenApiSchema schema, SchemaFilterContext context) { | ||
if (schema == null) { | ||
throw new ArgumentNullException(nameof(schema)); | ||
} | ||
|
||
if (context == null) { | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (context.MemberInfo?.DeclaringType != typeof(BotConfig)) { | ||
return; | ||
} | ||
|
||
OpenApiArray validValues; | ||
|
||
switch (context.MemberInfo.Name) { | ||
case nameof(BotConfig.CompleteTypesToSend): | ||
validValues = new OpenApiArray(); | ||
|
||
validValues.AddRange(BotConfig.AllowedCompleteTypesToSend.Select(type => new OpenApiInteger((int) type))); | ||
|
||
// Note, we'd love to add this to schema.Items, but since items are ref to the enum, it's not possible to add it that way | ||
schema.AddExtension("x-valid-values", validValues); | ||
|
||
break; | ||
case nameof(BotConfig.GamesPlayedWhileIdle): | ||
schema.Items.Minimum = 1; | ||
schema.Items.Maximum = uint.MaxValue; | ||
|
||
break; | ||
case nameof(BotConfig.SteamMasterClanID): | ||
schema.Maximum = new SteamID(uint.MaxValue, EUniverse.Public, EAccountType.Clan); | ||
schema.Minimum = new SteamID(1, EUniverse.Public, EAccountType.Clan); | ||
|
||
validValues = new OpenApiArray(); | ||
|
||
validValues.Add(new OpenApiInteger(0)); | ||
|
||
schema.AddExtension("x-valid-values", validValues); | ||
|
||
break; | ||
case nameof(BotConfig.SteamParentalCode): | ||
validValues = new OpenApiArray(); | ||
|
||
validValues.Add(new OpenApiString("0")); | ||
|
||
schema.AddExtension("x-valid-values", validValues); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
ArchiSteamFarm/IPC/Integration/GlobalConfigSchemaFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// _ _ _ ____ _ _____ | ||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ | ||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ | ||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | | ||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| | ||
// | | ||
// 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 ArchiSteamFarm.Storage; | ||
using JetBrains.Annotations; | ||
using Microsoft.OpenApi.Any; | ||
using Microsoft.OpenApi.Extensions; | ||
using Microsoft.OpenApi.Models; | ||
using SteamKit2; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace ArchiSteamFarm.IPC.Integration { | ||
[UsedImplicitly] | ||
internal sealed class GlobalConfigSchemaFilter : ISchemaFilter { | ||
public void Apply(OpenApiSchema schema, SchemaFilterContext context) { | ||
if (schema == null) { | ||
throw new ArgumentNullException(nameof(schema)); | ||
} | ||
|
||
if (context == null) { | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (context.MemberInfo?.DeclaringType != typeof(GlobalConfig)) { | ||
return; | ||
} | ||
|
||
switch (context.MemberInfo.Name) { | ||
case nameof(GlobalConfig.Blacklist): | ||
schema.Items.Minimum = 1; | ||
schema.Items.Maximum = uint.MaxValue; | ||
|
||
break; | ||
case nameof(GlobalConfig.SteamOwnerID): | ||
schema.Maximum = new SteamID(uint.MaxValue, EUniverse.Public, EAccountType.Individual); | ||
schema.Minimum = new SteamID(1, EUniverse.Public, EAccountType.Individual); | ||
|
||
OpenApiArray validValues = new(); | ||
|
||
validValues.Add(new OpenApiInteger(0)); | ||
|
||
schema.AddExtension("x-valid-values", validValues); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters