OpenAPITools / OpenAPITools/openapi-generator
AspNetCore Controller with CancellationToken parameter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating the server as a library, the Task methods don't have the CancellationToken parameter.
This is because the template currently renders the CancellationToken only if the options operationResultTask and operationIsAsync are set to true. But operationIsAsync is always false in the case of a library output.
This fix intends to render the CancellationToken only under the operationResultTask option.
openapi-generator version
Latest. Not a regression as the CancellationToken generation has been introduced in Jan 2023 and has been working as described above since then.
OpenAPI declaration file content or url
openapi: 3.0.2
info:
version: '1.0'
title: Thing manager
servers:
- url: http://localhost:5010
paths:
/:
get:
summary: Hello
operationId: hello
tags:
- thing
responses:
'200':
description: Success
Command line used for generation
docker run --rm -v C:\Users\xxx\source\repos\OpenAPI_aspnetcore_CancellationTokenTest\repro:/src openapitools/openapi-generator-cli:latest generate -i /src/spec/combined_openapi.yaml -g aspnetcore -o /src/gen -c /src/generator/generator-config.yaml
Content of the generator-config.yaml:
additionalProperties:
aspnetCoreVersion: 6.0
buildTarget: library
enumValueSuffix: ""
operationResultTask: true
packageName: ThingManager.Generated
sourceFolder: ""
useSwashbuckle: false
useNewtonsoft: true
templateDir: . # relative to location of generator-config.yml
Steps to reproduce
No CancellationToken generator in the controller method
Related issues/PRs
Introduction of CancellationToken:
https://github.com/OpenAPITools/openapi-generator/pull/14326
operationIsAsync explicitly hard coded to false in the library output case:
https://github.com/OpenAPITools/openapi-generator/pull/2629
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the aspnetcore generator output from the provided OpenAPI declaration and generator-config.yaml, focusing on how operationResultTask and operationIsAsync control the controller method signature. Reproduce the Docker generation command and verify that a library build with operationResultTask enabled includes a CancellationToken parameter in generated Task methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100