Skip to content

Commit

Permalink
fix: Fixed keywords in parameter names.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 1, 2024
1 parent deb4e86 commit 2e6dc6b
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 105 deletions.
20 changes: 13 additions & 7 deletions src/libs/OpenApiGenerator.Core/Generation/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ public static (EquatableArray<ModelData> Models, EquatableArray<EndPoint> Method
!excludedModels.Contains(schema.Key))
.SelectMany(schema => schema.GetReferences())
.Select(reference => reference.Id));
Dictionary<string, ModelData> schemas = openApiDocument.Components.Schemas

var includedSchemas = openApiDocument.Components.Schemas
.Where(schema =>
(includedModels.Count == 0 ||
includedModels.Contains(schema.Key) ||
referencesOfIncludedModels.Contains(schema.Key)) &&
includedModels.Contains(schema.Key) ||
referencesOfIncludedModels.Contains(schema.Key)) &&
!excludedModels.Contains(schema.Key))
.ToArray();
Dictionary<string, ModelData> classes = includedSchemas
// .Where(schema =>
// schema.Value.AnyOf is not { Count: >0 } &&
// schema.Value.OneOf is not { Count: >0 } &&
// schema.Value.AllOf is not { Count: >0 })
.Select(schema => ModelData.FromSchema(schema, settings))
.SelectMany(model => model.WithAdditionalModels())
.GroupBy(x => x.ClassName)
Expand Down Expand Up @@ -181,7 +187,7 @@ .. includedTags.Select(x => PropertyData.Default with
..constructors,
];

var allSchemas = settings.GenerateSdk || settings.GenerateModels ? schemas.Values.Concat(methods
var allSchemas = settings.GenerateSdk || settings.GenerateModels ? classes.Values.Concat(methods
.SelectMany(x => x.AdditionalModels))
.SelectMany(x => x.Schema.Value.Properties.Concat([x.Schema]).ToArray())
.Select(x => x.Value)
Expand Down Expand Up @@ -221,7 +227,7 @@ .. includedTags.Select(x => PropertyData.Default with
var types =
settings.GenerateJsonSerializerContextTypes &&
(settings.GenerateSdk || settings.GenerateModels)
? schemas.Values
? classes.Values
.SelectMany(model => model.Properties)
.Select(x => x.Type)
.Concat(methods.SelectMany(x => x.AdditionalTypes))
Expand All @@ -230,7 +236,7 @@ .. includedTags.Select(x => PropertyData.Default with
.Select(x => x.First())
.ToImmutableArray()
: [];
var models = settings.GenerateSdk || settings.GenerateModels ? schemas.Values
var models = settings.GenerateSdk || settings.GenerateModels ? classes.Values
.Select(model => model with
{
Schema = default,
Expand Down
80 changes: 78 additions & 2 deletions src/libs/OpenApiGenerator.Core/Models/PropertyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,85 @@ private static string HandleWordSeparators(string name)
public string ParameterName => Name
.Replace(".", string.Empty)
.ToParameterName()
.ReplaceIfEquals("ref", "@ref")

// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
.ReplaceIfEquals("abstract", "@abstract")
.ReplaceIfEquals("as", "@as")
.ReplaceIfEquals("base", "@base")
.ReplaceIfEquals("protected", "@protected");
.ReplaceIfEquals("bool", "@bool")
.ReplaceIfEquals("break", "@break")
.ReplaceIfEquals("byte", "@byte")
.ReplaceIfEquals("case", "@case")
.ReplaceIfEquals("catch", "@catch")
.ReplaceIfEquals("char", "@char")
.ReplaceIfEquals("checked", "@checked")
.ReplaceIfEquals("class", "@class")
.ReplaceIfEquals("const", "@const")
.ReplaceIfEquals("continue", "@continue")
.ReplaceIfEquals("decimal", "@decimal")
.ReplaceIfEquals("default", "@default")
.ReplaceIfEquals("delegate", "@delegate")
.ReplaceIfEquals("do", "@do")
.ReplaceIfEquals("double", "@double")
.ReplaceIfEquals("else", "@else")
.ReplaceIfEquals("enum", "@enum")
.ReplaceIfEquals("event", "@event")
.ReplaceIfEquals("explicit", "@explicit")
.ReplaceIfEquals("extern", "@extern")
.ReplaceIfEquals("false", "@false")
.ReplaceIfEquals("finally", "@finally")
.ReplaceIfEquals("fixed", "@fixed")
.ReplaceIfEquals("float", "@float")
.ReplaceIfEquals("for", "@for")
.ReplaceIfEquals("foreach", "@foreach")
.ReplaceIfEquals("goto", "@goto")
.ReplaceIfEquals("if", "@if")
.ReplaceIfEquals("implicit", "@implicit")
.ReplaceIfEquals("in", "@in")
.ReplaceIfEquals("int", "@int")
.ReplaceIfEquals("interface", "@interface")
.ReplaceIfEquals("internal", "@internal")
.ReplaceIfEquals("is", "@is")
.ReplaceIfEquals("lock", "@lock")
.ReplaceIfEquals("long", "@long")
.ReplaceIfEquals("namespace", "@namespace")
.ReplaceIfEquals("new", "@new")
.ReplaceIfEquals("null", "@null")
.ReplaceIfEquals("object", "@object")
.ReplaceIfEquals("operator", "@operator")
.ReplaceIfEquals("out", "@out")
.ReplaceIfEquals("override", "@override")
.ReplaceIfEquals("params", "@params")
.ReplaceIfEquals("private", "@private")
.ReplaceIfEquals("protected", "@protected")
.ReplaceIfEquals("public", "@public")
.ReplaceIfEquals("readonly", "@readonly")
.ReplaceIfEquals("ref", "@ref")
.ReplaceIfEquals("return", "@return")
.ReplaceIfEquals("sbyte", "@sbyte")
.ReplaceIfEquals("sealed", "@sealed")
.ReplaceIfEquals("short", "@short")
.ReplaceIfEquals("sizeof", "@sizeof")
.ReplaceIfEquals("stackalloc", "@stackalloc")
.ReplaceIfEquals("static", "@static")
.ReplaceIfEquals("string", "@string")
.ReplaceIfEquals("struct", "@struct")
.ReplaceIfEquals("switch", "@switch")
.ReplaceIfEquals("this", "@this")
.ReplaceIfEquals("throw", "@throw")
.ReplaceIfEquals("true", "@true")
.ReplaceIfEquals("try", "@try")
.ReplaceIfEquals("typeof", "@typeof")
.ReplaceIfEquals("uint", "@uint")
.ReplaceIfEquals("ulong", "@ulong")
.ReplaceIfEquals("unchecked", "@unchecked")
.ReplaceIfEquals("unsafe", "@unsafe")
.ReplaceIfEquals("ushort", "@ushort")
.ReplaceIfEquals("using", "@using")
.ReplaceIfEquals("virtual", "@virtual")
.ReplaceIfEquals("void", "@void")
.ReplaceIfEquals("volatile", "@volatile")
.ReplaceIfEquals("while", "@while");

public string ArgumentName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,8 +1224,8 @@
Summary:
<br/>Default Value: ,
ConverterType: ,
ParameterName: object,
ArgumentName: object,
ParameterName: @object,
ArgumentName: @object,
ParameterDefaultValue: ""
},
{
Expand Down Expand Up @@ -1670,8 +1670,8 @@
IsDeprecated: false,
Summary: ,
ConverterType: ,
ParameterName: object,
ArgumentName: object,
ParameterName: @object,
ArgumentName: @object,
ParameterDefaultValue: default
},
{
Expand Down
Loading

0 comments on commit 2e6dc6b

Please sign in to comment.