-
Notifications
You must be signed in to change notification settings - Fork 59
fix: replace optional struct CancellationToken parameter with method overloads #337
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "10.0.200", | ||
| "version": "10.0.102", | ||
| "rollForward": "latestMinor" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ type PayloadType = | |
|
|
||
| /// Object for compiling operations. | ||
| type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, ignoreControllerPrefix, ignoreOperationId, asAsync: bool) = | ||
| let compileOperation (providedMethodName: string) (apiCall: ApiCall) = | ||
| let compileOperation (providedMethodName: string) (apiCall: ApiCall) (includeCancellationToken: bool) = | ||
| let path, pathItem, opTy = apiCall | ||
| let operation = pathItem.Operations[opTy] | ||
|
|
||
|
|
@@ -178,10 +178,16 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, | |
| // reverse it again so that all required properties come first | ||
| |> List.rev | ||
|
|
||
| let ctParam = | ||
| ProvidedParameter("cancellationToken", typeof<Threading.CancellationToken>, optionalValue = box Threading.CancellationToken.None) | ||
| let parameters = | ||
| if includeCancellationToken then | ||
| let ctParam = | ||
| ProvidedParameter("cancellationToken", typeof<Threading.CancellationToken>) | ||
|
|
||
| payloadTy.ToMediaType(), providedParameters @ [ ctParam ] | ||
| providedParameters @ [ ctParam ] | ||
| else | ||
| providedParameters | ||
|
|
||
| payloadTy.ToMediaType(), parameters | ||
|
|
||
| // find the inner type value | ||
| let retMimeAndTy = | ||
|
|
@@ -608,13 +614,19 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, | |
| let methodNameScope = UniqueNameGenerator() | ||
|
|
||
| operations | ||
| |> List.map(fun op -> | ||
| |> List.collect(fun op -> | ||
| let skipLength = | ||
| if String.IsNullOrEmpty clientName then | ||
| 0 | ||
| else | ||
| clientName.Length + 1 | ||
|
|
||
| let name = OperationCompiler.GetMethodNameCandidate op skipLength ignoreOperationId | ||
| compileOperation (methodNameScope.MakeUnique name) op) | ||
| let uniqueName = methodNameScope.MakeUnique name | ||
| // Generate two overloads: one without CancellationToken (backward compatible) | ||
| // and one with an explicit CancellationToken parameter. | ||
| // We cannot use an optional struct parameter with a default value because | ||
| // struct values (e.g., CancellationToken.None) cannot be stored in DefaultParameterValue | ||
| // custom attributes. | ||
| [ compileOperation uniqueName op false; compileOperation uniqueName op true ]) | ||
|
Comment on lines
616
to
+631
|
||
| |> ty.AddMembers) | ||
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.
The added CancellationToken parameter is always named "cancellationToken" without checking whether an OpenAPI parameter/body field already normalizes to the same name. That can (1) create duplicate parameter names when includeCancellationToken=true, and (2) when includeCancellationToken=false, cause a real OpenAPI parameter named "cancellationToken" to be misinterpreted as the special token in invokeCode and be omitted from the request. Make the CancellationToken parameter name unique against the existing providedParameters (or adjust the invokeCode matching so it only treats the argument as a CT when it doesn’t correspond to an OpenAPI parameter).