Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 2d82cc1

Browse files
Remove obsolete generation
1 parent 488176f commit 2d82cc1

16 files changed

Lines changed: 35 additions & 256 deletions

ReQuesty.Builder/Configuration/GenerationConfiguration.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ public bool UsesBackingStore
6161
{
6262
get; set;
6363
}
64-
public bool ExcludeBackwardCompatible
65-
{
66-
get; set;
67-
}
68-
public bool IncludeBackwardCompatible
69-
{
70-
get => !ExcludeBackwardCompatible;
71-
}
7264
public bool IncludeAdditionalData { get; set; } = true;
7365
public HashSet<string> Serializers
7466
{
@@ -141,7 +133,6 @@ public object Clone()
141133
{
142134
return new GenerationConfiguration
143135
{
144-
ExcludeBackwardCompatible = ExcludeBackwardCompatible,
145136
OpenAPIFilePath = OpenAPIFilePath,
146137
OutputPath = OutputPath,
147138
ClientClassName = ClientClassName,

ReQuesty.Builder/Lock/ReQuestyLock.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public void UpdateGenerationConfigurationFromLock(GenerationConfiguration config
116116
}
117117

118118
config.UsesBackingStore = UsesBackingStore;
119-
config.ExcludeBackwardCompatible = ExcludeBackwardCompatible;
120119
config.IncludeAdditionalData = IncludeAdditionalData;
121120
config.Serializers = Serializers.ToHashSet(StringComparer.OrdinalIgnoreCase);
122121
config.Deserializers = Deserializers.ToHashSet(StringComparer.OrdinalIgnoreCase);
@@ -145,7 +144,6 @@ public ReQuestyLock(GenerationConfiguration config)
145144
TypeAccessModifier = config.TypeAccessModifier.ToString();
146145
ClientNamespaceName = config.ClientNamespaceName;
147146
UsesBackingStore = config.UsesBackingStore;
148-
ExcludeBackwardCompatible = config.ExcludeBackwardCompatible;
149147
IncludeAdditionalData = config.IncludeAdditionalData;
150148
Serializers = config.Serializers.ToHashSet(StringComparer.OrdinalIgnoreCase);
151149
Deserializers = config.Deserializers.ToHashSet(StringComparer.OrdinalIgnoreCase);

ReQuesty.Builder/ReQuestyBuilder.cs

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ public async Task ApplyLanguageRefinementAsync(GenerationConfiguration config, C
685685

686686
public async Task CreateLanguageSourceFilesAsync(GenerationLanguage language, CodeNamespace generatedCode, CancellationToken cancellationToken)
687687
{
688-
LanguageWriter languageWriter = LanguageWriter.GetLanguageWriter(language, config.OutputPath, config.ClientNamespaceName, config.UsesBackingStore, config.ExcludeBackwardCompatible);
688+
LanguageWriter languageWriter = LanguageWriter.GetLanguageWriter(language, config.OutputPath, config.ClientNamespaceName, config.UsesBackingStore);
689689
Stopwatch stopwatch = new();
690690
stopwatch.Start();
691691
CodeRenderer codeRenderer = CodeRenderer.GetCodeRender(config);
@@ -1375,52 +1375,11 @@ private void AddErrorMappingToExecutorMethod(OpenApiUrlTreeNode currentNode, Ope
13751375
{
13761376
string suffix = $"{operationType.Method.ToLowerInvariant().ToFirstCharacterUpperCase()}Response";
13771377
CodeTypeBase? modelType = CreateModelDeclarations(currentNode, schema, operation, parentClass, suffix);
1378-
if (modelType is not null && config.IncludeBackwardCompatible && config.Language is GenerationLanguage.CSharp && modelType.Name.EndsWith(suffix, StringComparison.Ordinal))
1379-
{ //TODO remove for v2
1380-
string obsoleteTypeName = modelType.Name[..^suffix.Length] + "Response";
1381-
if (modelType is CodeType codeType &&
1382-
codeType.TypeDefinition is CodeClass codeClass)
1383-
{
1384-
CodeClass obsoleteClassDefinition = new()
1385-
{
1386-
Kind = CodeClassKind.Model,
1387-
Name = obsoleteTypeName,
1388-
Deprecation = new("This class is obsolete. Use {TypeName} instead.", IsDeprecated: true, TypeReferences: new() { { "TypeName", codeType } }),
1389-
Documentation = (CodeDocumentation)codeClass.Documentation.Clone()
1390-
};
1391-
CodeMethod originalFactoryMethod = codeClass.Methods.First(static x => x.Kind is CodeMethodKind.Factory);
1392-
CodeMethod obsoleteFactoryMethod = (CodeMethod)originalFactoryMethod.Clone();
1393-
obsoleteFactoryMethod.ReturnType = new CodeType { Name = obsoleteTypeName, TypeDefinition = obsoleteClassDefinition };
1394-
obsoleteClassDefinition.AddMethod(obsoleteFactoryMethod);
1395-
obsoleteClassDefinition.StartBlock.Inherits = (CodeType)codeType.Clone();
1396-
CodeClass obsoleteClass = codeClass.Parent switch
1397-
{
1398-
CodeClass modelParentClass => modelParentClass.AddInnerClass(obsoleteClassDefinition).First(),
1399-
CodeNamespace modelParentNamespace => modelParentNamespace.AddClass(obsoleteClassDefinition).First(),
1400-
_ => throw new InvalidOperationException("Could not find a valid parent for the obsolete class")
1401-
};
1402-
return (modelType, new CodeType
1403-
{
1404-
TypeDefinition = obsoleteClass,
1405-
});
1406-
}
1407-
else if (modelType is CodeComposedTypeBase codeComposedTypeBase)
1408-
{
1409-
CodeComposedTypeBase obsoleteComposedType = codeComposedTypeBase switch
1410-
{
1411-
CodeUnionType u => (CodeComposedTypeBase)u.Clone(),
1412-
CodeIntersectionType i => (CodeComposedTypeBase)i.Clone(),
1413-
_ => throw new InvalidOperationException("Could not create an obsolete composed type"),
1414-
};
1415-
obsoleteComposedType.Name = obsoleteTypeName;
1416-
obsoleteComposedType.Deprecation = new("This class is obsolete. Use {TypeName} instead.", IsDeprecated: true, TypeReferences: new() { { "TypeName", modelType } });
1417-
return (modelType, obsoleteComposedType);
1418-
}
1419-
}
1420-
else if (modelType is null)
1378+
if (modelType is null)
14211379
{
14221380
return (GetExecutorMethodDefaultReturnType(operation), null);
14231381
}
1382+
14241383
return (modelType, null);
14251384
}
14261385
else
@@ -1516,16 +1475,6 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, NetHttpMetho
15161475
};
15171476
executorMethod.AddParameter(cancellationParam);// Add cancellation token parameter
15181477

1519-
if (returnTypes.Item2 is not null && config.IncludeBackwardCompatible)
1520-
{ //TODO remove for v2
1521-
CodeMethod additionalExecutorMethod = (CodeMethod)executorMethod.Clone();
1522-
additionalExecutorMethod.ReturnType = returnTypes.Item2;
1523-
additionalExecutorMethod.OriginalMethod = executorMethod;
1524-
string newName = $"{executorMethod.Name}As{executorMethod.ReturnType.Name.ToFirstCharacterUpperCase()}";
1525-
additionalExecutorMethod.Deprecation = new("This method is obsolete. Use {TypeName} instead.", IsDeprecated: true, TypeReferences: new() { { "TypeName", new CodeType { TypeDefinition = executorMethod, IsExternal = false } } });
1526-
parentClass.RenameChildElement(executorMethod.Name, newName);
1527-
parentClass.AddMethod(additionalExecutorMethod);
1528-
}
15291478
logger.LogTrace("Creating method {Name} of {Type}", executorMethod.Name, executorMethod.ReturnType);
15301479

15311480
CodeMethod generatorMethod = new()
@@ -2736,7 +2685,6 @@ internal static void AddSerializationMembers(CodeClass model, bool includeAdditi
27362685
private void AddPropertyForQueryParameter(OpenApiUrlTreeNode node, NetHttpMethod operationType, IOpenApiParameter parameter, CodeClass parameterClass)
27372686
{
27382687
CodeType? resultType = default;
2739-
bool addBackwardCompatibleParameter = false;
27402688

27412689
if (parameter.Schema is not null && (parameter.Schema.IsEnum() || (parameter.Schema.IsArray() && parameter.Schema.Items.IsEnum())))
27422690
{
@@ -2760,7 +2708,6 @@ private void AddPropertyForQueryParameter(OpenApiUrlTreeNode node, NetHttpMethod
27602708
TypeDefinition = enumDeclaration,
27612709
IsNullable = !parameter.Schema.IsArray()
27622710
};
2763-
addBackwardCompatibleParameter = true;
27642711
}
27652712
}
27662713
resultType ??= GetPrimitiveType(parameter.Schema) ?? new CodeType()
@@ -2796,20 +2743,7 @@ private void AddPropertyForQueryParameter(OpenApiUrlTreeNode node, NetHttpMethod
27962743

27972744
if (!parameterClass.ContainsPropertyWithWireName(prop.WireName))
27982745
{
2799-
if (addBackwardCompatibleParameter && config.IncludeBackwardCompatible && config.Language is GenerationLanguage.CSharp)
2800-
{ //TODO remove for v2
2801-
CodeProperty modernProp = (CodeProperty)prop.Clone();
2802-
modernProp.Name = $"{prop.Name}As{modernProp.Type.Name.ToFirstCharacterUpperCase()}";
2803-
modernProp.SerializationName = prop.WireName;
2804-
prop.Deprecation = new("This property is deprecated, use {TypeName} instead", IsDeprecated: true, TypeReferences: new() { { "TypeName", new CodeType { TypeDefinition = modernProp, IsExternal = false } } });
2805-
prop.Type = GetDefaultQueryParameterType();
2806-
prop.Type.CollectionKind = modernProp.Type.CollectionKind;
2807-
parameterClass.AddProperty(modernProp, prop);
2808-
}
2809-
else
2810-
{
2811-
parameterClass.AddProperty(prop);
2812-
}
2746+
parameterClass.AddProperty(prop);
28132747
}
28142748
else
28152749
{

ReQuesty.Builder/Refiners/CSharpRefiner.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
4242
{
4343
Name = "DefaultQueryParameters",
4444
IsExternal = true,
45-
},
46-
!_configuration.ExcludeBackwardCompatible,//TODO remove the condition for v2
47-
!_configuration.ExcludeBackwardCompatible);
45+
});
4846
AddDefaultImports(generatedCode, defaultUsingEvaluators);
4947
MoveClassesWithNamespaceNamesUnderNamespace(generatedCode);
5048
ConvertUnionTypesToWrapper(generatedCode,

ReQuesty.Builder/Refiners/CommonLanguageRefiner.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,19 +1652,14 @@ protected static void RemoveUntypedNodeTypeValues(CodeElement currentElement)
16521652
}
16531653
CrawlTree(currentElement, RemoveUntypedNodeTypeValues);
16541654
}
1655-
protected static void RemoveRequestConfigurationClasses(CodeElement currentElement, CodeUsing? configurationParameterTypeUsing = null, CodeType? defaultValueForGenericTypeParam = null, bool keepRequestConfigurationClass = false, bool addDeprecation = false, CodeUsing? usingForDefaultGenericParameter = null)
1655+
1656+
protected static void RemoveRequestConfigurationClasses(CodeElement currentElement, CodeUsing? configurationParameterTypeUsing = null, CodeType? defaultValueForGenericTypeParam = null, CodeUsing? usingForDefaultGenericParameter = null)
16561657
{
1657-
if (currentElement is CodeClass currentClass && currentClass.IsOfKind(CodeClassKind.RequestConfiguration) &&
1658-
currentClass.Parent is CodeClass parentClass)
1658+
if (currentElement is CodeClass currentClass
1659+
&& currentClass.IsOfKind(CodeClassKind.RequestConfiguration)
1660+
&& currentClass.Parent is CodeClass parentClass)
16591661
{
1660-
if (addDeprecation && keepRequestConfigurationClass)
1661-
{
1662-
currentClass.Deprecation = new DeprecationInformation("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.");
1663-
}
1664-
else if (!keepRequestConfigurationClass)
1665-
{
1666-
parentClass.RemoveChildElement(currentClass);
1667-
}
1662+
parentClass.RemoveChildElement(currentClass);
16681663

16691664
CodeParameter[] configurationParameters = parentClass.Methods
16701665
.SelectMany(static x => x.Parameters)
@@ -1684,11 +1679,7 @@ protected static void RemoveRequestConfigurationClasses(CodeElement currentEleme
16841679
Name = configurationParameterTypeUsing.Name,
16851680
IsExternal = true,
16861681
};
1687-
if (addDeprecation && keepRequestConfigurationClass)
1688-
{
1689-
currentClass.RemovePropertiesOfKind(CodePropertyKind.Headers, CodePropertyKind.Options, CodePropertyKind.QueryParameters);
1690-
currentClass.StartBlock.Inherits = GetGenericTypeForRequestConfiguration(configurationParameterType, genericTypeParamValue);
1691-
}
1682+
16921683
foreach (CodeParameter? configurationParameter in configurationParameters)
16931684
{
16941685
CodeType newType = GetGenericTypeForRequestConfiguration(configurationParameterType, genericTypeParamValue);
@@ -1698,8 +1689,9 @@ protected static void RemoveRequestConfigurationClasses(CodeElement currentEleme
16981689
}
16991690
}
17001691

1701-
CrawlTree(currentElement, x => RemoveRequestConfigurationClasses(x, configurationParameterTypeUsing, defaultValueForGenericTypeParam, keepRequestConfigurationClass, addDeprecation, usingForDefaultGenericParameter));
1692+
CrawlTree(currentElement, x => RemoveRequestConfigurationClasses(x, configurationParameterTypeUsing, defaultValueForGenericTypeParam, usingForDefaultGenericParameter));
17021693
}
1694+
17031695
private static CodeType GetGenericTypeForRequestConfiguration(CodeType configurationParameterType, CodeType genericTypeParamValue)
17041696
{
17051697
CodeType newType = (CodeType)configurationParameterType.Clone();

ReQuesty.Builder/WorkspaceManagement/ApiClientConfiguration.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ public bool IncludeAdditionalData
4040
get; set;
4141
}
4242
/// <summary>
43-
/// Whether backward compatible code was excluded for this client.
44-
/// </summary>
45-
public bool ExcludeBackwardCompatible
46-
{
47-
get; set;
48-
}
49-
/// <summary>
5043
/// The OpenAPI validation rules to disable during the generation.
5144
/// </summary>
5245
public HashSet<string> DisabledValidationRules { get; set; } = new(StringComparer.OrdinalIgnoreCase);
@@ -68,7 +61,6 @@ public ApiClientConfiguration(GenerationConfiguration config) : base(config)
6861
TypeAccessModifier = config.TypeAccessModifier.ToString();
6962
ClientNamespaceName = config.ClientNamespaceName;
7063
UsesBackingStore = config.UsesBackingStore;
71-
ExcludeBackwardCompatible = config.ExcludeBackwardCompatible;
7264
IncludeAdditionalData = config.IncludeAdditionalData;
7365
StructuredMimeTypes = config.StructuredMimeTypes.ToList();
7466
DisabledValidationRules = config.DisabledValidationRules.ToHashSet(StringComparer.OrdinalIgnoreCase);
@@ -95,7 +87,6 @@ public void UpdateGenerationConfigurationFromApiClientConfiguration(GenerationCo
9587
}
9688

9789
config.UsesBackingStore = UsesBackingStore;
98-
config.ExcludeBackwardCompatible = ExcludeBackwardCompatible;
9990
config.IncludeAdditionalData = IncludeAdditionalData;
10091
config.StructuredMimeTypes = new(StructuredMimeTypes);
10192
config.DisabledValidationRules = DisabledValidationRules.ToHashSet(StringComparer.OrdinalIgnoreCase);
@@ -112,7 +103,6 @@ public object Clone()
112103
ClientNamespaceName = ClientNamespaceName,
113104
UsesBackingStore = UsesBackingStore,
114105
IncludeAdditionalData = IncludeAdditionalData,
115-
ExcludeBackwardCompatible = ExcludeBackwardCompatible,
116106
DisabledValidationRules = new(DisabledValidationRules, StringComparer.OrdinalIgnoreCase),
117107
};
118108
CloneBase(result);

ReQuesty.Builder/WorkspaceManagement/ApiClientConfigurationComparer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ public override bool Equals(ApiClientConfiguration? x, ApiClientConfiguration? y
2525
return object.Equals(x, y);
2626
}
2727

28-
if (x.ExcludeBackwardCompatible != y.ExcludeBackwardCompatible)
29-
{
30-
return false;
31-
}
32-
3328
if (x.UsesBackingStore != y.UsesBackingStore)
3429
{
3530
return false;
@@ -73,7 +68,6 @@ public override int GetHashCode([DisallowNull] ApiClientConfiguration obj)
7368
hash.Add(obj.ClientNamespaceName, _stringComparer);
7469
hash.Add(obj.Language, _stringComparer);
7570
hash.Add(obj.TypeAccessModifier, _stringComparer);
76-
hash.Add(obj.ExcludeBackwardCompatible);
7771
hash.Add(obj.UsesBackingStore);
7872
hash.Add(obj.IncludeAdditionalData);
7973
hash.Add(obj.StructuredMimeTypes, _stringIEnumerableDeepComparer);

ReQuesty.Builder/Writers/LanguageWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected void AddOrReplaceCodeElementWriter<T>(ICodeElementWriter<T> writer) wh
177177
}
178178
}
179179
private readonly Dictionary<Type, object> Writers = []; // we have to type as object because dotnet doesn't have type capture i.e eq for `? extends CodeElement`
180-
public static LanguageWriter GetLanguageWriter(GenerationLanguage language, string outputPath, string clientNamespaceName, bool usesBackingStore = false, bool excludeBackwardCompatible = false)
180+
public static LanguageWriter GetLanguageWriter(GenerationLanguage language, string outputPath, string clientNamespaceName, bool usesBackingStore = false)
181181
{
182182
return language switch
183183
{

ReQuesty/Consts/CommandLineOptions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ public static class CommandLineOptions
3333
public const string DisableValidationRulesOption = "--disable-validation-rules";
3434
public const string DisableValidationRulesShortOption = "--dvr";
3535

36-
public const string ExcludeBackwardCompatibleOption = "--exclude-backward-compatible";
37-
public const string ExcludeBackwardCompatibleShortOption = "--ebc";
38-
3936
public const string ExcludePathOption = "--exclude-path";
4037
public const string ExcludePathShortOption = "-e";
4138

ReQuesty/Handlers/ReQuestyGenerateCommandHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public override async Task<int> InvokeAsync(ParseResult context, CancellationTok
2121
string? openapi = context.GetValue<string?>(CommandLineOptions.DescriptionOption);
2222
string? manifest = context.GetValue<string?>(CommandLineOptions.ManifestOption);
2323
bool backingStore = context.GetValue<bool>(CommandLineOptions.BackingStoreOption);
24-
bool excludeBackwardCompatible = context.GetValue<bool>(CommandLineOptions.ExcludeBackwardCompatibleOption);
2524
bool clearCache = context.GetValue<bool>(CommandLineOptions.ClearCacheOption);
2625
bool disableSSLValidation = context.GetValue<bool>(CommandLineOptions.DisableSSLValidationOption);
2726
bool includeAdditionalData = context.GetValue<bool>(CommandLineOptions.AdditionalDataOption);
@@ -48,7 +47,6 @@ public override async Task<int> InvokeAsync(ParseResult context, CancellationTok
4847
AssignIfNotNullOrEmpty(namespaceName, (c, s) => c.ClientNamespaceName = s);
4948
Configuration.Generation.TypeAccessModifier = typeAccessModifier;
5049
Configuration.Generation.UsesBackingStore = backingStore;
51-
Configuration.Generation.ExcludeBackwardCompatible = excludeBackwardCompatible;
5250
Configuration.Generation.IncludeAdditionalData = includeAdditionalData;
5351
Configuration.Generation.Language = GenerationLanguage.CSharp;
5452

0 commit comments

Comments
 (0)