-
Notifications
You must be signed in to change notification settings - Fork 59
Fix: CT parameter name uniqueness in CancellationToken overload generation #339
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 |
|---|---|---|
|
|
@@ -157,7 +157,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, | |
|
|
||
| List.append required optional | ||
|
|
||
| let providedParameters = | ||
| let usedNames, providedParameters = | ||
| ((Set.empty, []), orderedParameters) | ||
| ||> List.fold(fun (names, parameters) current -> | ||
| let names, paramName = uniqueParamName names current | ||
|
|
@@ -173,16 +173,21 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, | |
| ProvidedParameter(paramName, paramType, false, paramDefaultValue) | ||
|
|
||
| (names, providedParam :: parameters)) | ||
| |> snd | ||
| // because we built up our list in reverse order with the fold, | ||
| // reverse it again so that all required properties come first | ||
| |> List.rev | ||
| |> fun (names, ps) -> names, List.rev ps | ||
|
|
||
| let parameters = | ||
| if includeCancellationToken then | ||
| let ctParam = | ||
| ProvidedParameter("cancellationToken", typeof<Threading.CancellationToken>) | ||
| // Find a unique name for the CancellationToken parameter that doesn't | ||
| // conflict with any OpenAPI parameter already in use. | ||
| let ctParamName = | ||
| Seq.initInfinite(fun i -> | ||
| if i = 0 then | ||
| "cancellationToken" | ||
| else | ||
| $"cancellationToken{i}") | ||
| |> Seq.find(fun n -> not(Set.contains n usedNames)) | ||
|
|
||
| let ctParam = ProvidedParameter(ctParamName, typeof<Threading.CancellationToken>) | ||
| providedParameters @ [ ctParam ] | ||
|
Comment on lines
+180
to
191
|
||
| else | ||
| providedParameters | ||
|
|
||
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 introduces a second ad-hoc unique-name generator (
Seq.initInfinite+Set.contains) even though the codebase already hasUniqueNameGeneratorwith the same suffixing convention (and case-insensitive uniqueness). Consider factoring this into a shared helper (or reusingUniqueNameGeneratorby seeding it withusedNames) to avoid future divergence in how “unique names” are defined.