-
-
Notifications
You must be signed in to change notification settings - Fork 63
Fix #672: MultipleInterfaces ByTag method naming scoped per-interface #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ namespace Refitter.Core; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal class RefitMultipleInterfaceByTagGenerator : RefitInterfaceGenerator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly HashSet<string> knownIdentifiers = new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Dictionary<string, HashSet<string>>? _methodIdentifiersByInterface; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal RefitMultipleInterfaceByTagGenerator( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RefitGeneratorSettings settings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,6 +30,8 @@ public override IEnumerable<GeneratedCode> GenerateCode() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dictionary<string, StringBuilder> interfacesByGroup = new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dictionary<string, string> interfacesNamesByGroup = new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _methodIdentifiersByInterface = new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var kv in byGroup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,6 +62,10 @@ public override IEnumerable<GeneratedCode> GenerateCode() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interfacesNamesByGroup[kv.Key] = interfaceName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interfaceName = interfacesNamesByGroup[kv.Key]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var operationName = GetOperationName(interfaceName, op.PathItem.Key, operations.Key, operation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var dynamicQuerystringParameterType = operationName + "QueryParams"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -155,8 +162,19 @@ private string GetOperationName( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string verb, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OpenApiOperation operation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generatedName = IdentifierUtils.Counted(knownIdentifiers, GenerateOperationName(name, verb, operation, capitalizeFirstCharacter: true), parent: interfaceName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| knownIdentifiers.Add($"{interfaceName}.{generatedName}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize per-interface tracking if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!_methodIdentifiersByInterface!.ContainsKey(interfaceName)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _methodIdentifiersByInterface[interfaceName] = new HashSet<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var interfaceIdentifiers = _methodIdentifiersByInterface[interfaceName]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generatedName = IdentifierUtils.Counted( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interfaceIdentifiers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GenerateOperationName(name, verb, operation, capitalizeFirstCharacter: true), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parent: interfaceName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interfaceIdentifiers.Add(generatedName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+165
to
+177
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method-collision detection is broken by mismatched identifier keys. At Line 172, 🐛 Proposed fix- var generatedName = IdentifierUtils.Counted(
- interfaceIdentifiers,
- GenerateOperationName(name, verb, operation, capitalizeFirstCharacter: true),
- parent: interfaceName);
+ var generatedName = IdentifierUtils.Counted(
+ interfaceIdentifiers,
+ GenerateOperationName(name, verb, operation, capitalizeFirstCharacter: true));This keeps collision checks and stored identifiers in the same format. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interfaceIdentifiers.Add(generatedName); | |
| interfaceIdentifiers.Add($"{interfaceName}.{generatedName}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change silently overrides the user's
GenerateOptionalPropertiesAsNullablesetting wheneverGenerateNullableReferenceTypesis enabled, with no way for the user to opt out. SinceMapCSharpGeneratorSettingsskips properties that match the default value (false), a user who explicitly wantsGenerateOptionalPropertiesAsNullable = falsewhile usingGenerateNullableReferenceTypes = truecannot prevent this override. This is a breaking behavioral change for existing users who haveGenerateNullableReferenceTypes = true. The PR description does not mention this change at all — it only describes the ByTag method naming fix — making it even harder for users to anticipate this new behavior. This change should either be reverted if unintentional, or at minimum, it should only apply when the user has not explicitly setGenerateOptionalPropertiesAsNullablein their settings.