Skip to content

Commit

Permalink
fix: add lost code
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnkwlp committed Jul 29, 2023
1 parent 1679be0 commit 5cece02
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/SwaggerExtensions/SwaggerExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwaggerExtensions", "SwaggerExtensions\SwaggerExtensions.csproj", "{73F14ECB-AD2C-48F4-A178-8E5C92104BF6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwaggerExtensions", "SwaggerExtensions\SwaggerExtensions.csproj", "{73F14ECB-AD2C-48F4-A178-8E5C92104BF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
14 changes: 13 additions & 1 deletion src/SwaggerExtensions/SwaggerExtensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
namespace Swashbuckle.AspNetCore.SwaggerGen
namespace Swashbuckle.AspNetCore.SwaggerGen
{
internal static class Extensions
{
public static string RemovePostFix(this string value, string postfix)
{
if (string.IsNullOrWhiteSpace(value))
return value;

if (value.EndsWith(postfix))
return value.Substring(0, value.Length - postfix.Length);

return value;
}

public static string RemovePreFix(this string value, string prefix)
{
if (string.IsNullOrWhiteSpace(value))
return value;

if (value.StartsWith(prefix))
return value.Substring(prefix.Length);

return value;
}
}
Expand Down
28 changes: 21 additions & 7 deletions src/SwaggerExtensions/SwaggerExtensions/SwaggerEnumDescriptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
Expand All @@ -15,20 +15,34 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
var names = Enum.GetNames(type);

var values2 = new OpenApiArray();
//schema.Enum.Clear();
//foreach (var item in names)
//{
// schema.Enum.Add(new OpenApiInteger(Convert.ToInt32(Enum.Parse(type, item))));
//}

values2.AddRange(names.Select(x => new OpenApiObject
var enumKeyValue = new OpenApiArray();

enumKeyValue.AddRange(names.Select(x => new OpenApiObject
{
["name"] = new OpenApiString(Convert.ToInt32(Enum.Parse(type, x)).ToString()),
["value"] = new OpenApiString(x),
}));

var values1 = new OpenApiArray();
values1.AddRange(names.Select(x => new OpenApiString(x)));
var enumNames = new OpenApiArray();
enumNames.AddRange(names.Select(x => new OpenApiString(x)));

var enumValues = new OpenApiArray();
enumValues.AddRange(names.Select(x => new OpenApiInteger(Convert.ToInt32(Enum.Parse(type, x)))));

schema.Extensions.Add(
"x-enumNames",
values1
enumNames
);

schema.Extensions.Add(
"x-enumValues",
enumValues
);

schema.Extensions.Add(
Expand All @@ -37,7 +51,7 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
["name"] = new OpenApiString(type.Name),
["modelAsString"] = new OpenApiBoolean(true),
["values"] = values2,
["values"] = enumKeyValue,
}
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Swashbuckle.AspNetCore.SwaggerGen</RootNamespace>
<PackageId>Passingwind.$(AssemblyName)</PackageId>
<Authors>Passingwind</Authors>
<PackageProjectUrl>https://github.com/jxnkwlp/Passingwind.CommonLibs</PackageProjectUrl>
<RepositoryUrl>https://github.com/jxnkwlp/Passingwind.CommonLibs</RepositoryUrl>
<RepositoryType>github</RepositoryType>
<PackageVersion>0.1.0</PackageVersion>
<PackageVersion>0.2.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 5cece02

Please sign in to comment.