Skip to content

AspNetCore Controller with CancellationToken parameter #16334

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

Open
FredCni opened this issue Aug 16, 2023 · 3 comments
Open

AspNetCore Controller with CancellationToken parameter #16334

FredCni opened this issue Aug 16, 2023 · 3 comments

Comments

@FredCni
Copy link

FredCni commented Aug 16, 2023

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:
#14326
operationIsAsync explicitly hard coded to false in the library output case:
#2629

@DavidVollmers
Copy link

Having the same issue here. I tried to look into setting up a PR but this repository is just too huge for my smol brain.

@uhorn
Copy link

uhorn commented Nov 28, 2023

I also faced this issue. I even wonder why the library output setting is changing the operationIsAsync flag to false.

Is there any plan to fix this issue?

@andycnguyen
Copy link

Same issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants