Append flags format to flags enum types in swagger

This commit is contained in:
JustArchi
2020-06-25 15:40:04 +02:00
parent 5246b2b82d
commit f550d65897
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// |
// Copyright 2015-2020 Ł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;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace ArchiSteamFarm.IPC.Integration {
[UsedImplicitly]
internal sealed class EnumFlagsSchemaFilter : ISchemaFilter {
public void Apply([NotNull] OpenApiSchema schema, [NotNull] SchemaFilterContext context) {
if ((schema == null) || (context == null)) {
throw new ArgumentNullException(nameof(schema) + " || " + nameof(context));
}
if (!context.Type.IsEnum || !context.Type.IsDefined(typeof(FlagsAttribute), false)) {
return;
}
schema.Format = "flags";
}
}
}

View File

@@ -168,6 +168,7 @@ namespace ArchiSteamFarm.IPC {
);
options.EnableAnnotations(true);
options.SchemaFilter<EnumFlagsSchemaFilter>();
options.SwaggerDoc(
SharedInfo.ASF, new OpenApiInfo {