Skip to content

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

@robin-83

Description

@robin-83

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions