OpenAPITools / OpenAPITools/openapi-generator

[BUG] aspnetcore server cannot be compiled with async and result Task option

Open
#14,389 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I created an ASP .NET Core server from CLI with the additonal options operationResultTask=true and operationIsAsync=true. I used the public PetStore Open API spec in the newest version (currently 1.0.17). When I try to build the solution with VS 2022 (17.4.1) an error occurs:

Schweregrad Code Beschreibung Projekt Datei Zeile Unterdrückungszustand
Fehler CS4016 Da es sich um eine asynchrone Methode handelt, muss der Rückgabeausdruck vom Typ "IActionResult" anstelle von "Task" sein. PetStore.Web C:\Users[robin-83]\PetStore.Web9\src\PetStore.Web\Controllers\PetApi.cs 60 Aktiv
openapi-generator version

6.2.1. I have not tested this in older versions.

OpenAPI declaration file content or url

https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml

Generation Details

openapi-generator-cli generate -i petstore.yaml -g aspnetcore -o PetStore.Web --package-name PetStore.Web --additional-properties=operationResultTask=true,operationIsAsync=true

Steps to reproduce
  1. Open the solution in VS 2022
  2. Rebuild
Related issues/PRs

Dont know any.

Suggest a fix

Original code:

return Task.FromResult<IActionResult>(new ObjectResult(example));

Possible fix:

return new ObjectResult(example);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the CLI generation using the PetStore OpenAPI URL and the stated operationResultTask=true,operationIsAsync=true options. Inspect the generated src/PetStore.Web/Controllers/PetApi.cs around line 60, then rebuild in Visual Studio; done means the generated ASP.NET Core solution compiles without CS4016.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.