OpenAPITools / OpenAPITools/openapi-generator

[BUG][aspnetcore] Virtual and abstract not used correctly

Open
#7,042 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: C-Sharp
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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

In the server generated code for aspnetcore:

  1. When using the 'generateBody' option to false, we get a virtual method with no body. It should be an abstract method if the method have no body, and the class should also be made abstract in this case.

  2. When using the 'operationModifier', we get abstract methods, but not an abstract class. The class should also be abstract for it to work.

Also, unless I am mistaken, it seems that these two options (generateBody and operationModifier) have the same purpose

openapi-generator version

4.3.1

OpenAPI declaration file content or url

can be reproduced with the petstore file

Command line used for generation

openapi-generator generate -g aspnetcore -i petstore.json -c config.json -o src
and one of the following config.json files can be used depending on the case (1 or 2)

{
	"aspnetCoreVersion":"3.1",
	"operationModifier": "abstract"
}

or

{
	"aspnetCoreVersion":"3.1",
	"generateBody": false
}
Steps to reproduce

just running the command is enough to see the results

Related issues/PRs
Suggest a fix

changing virtual with abstract when relevant and adding abstract to the class when methods are abstract

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

Run the stated openapi-generator command with the petstore file and each config.json variant, focusing on the aspnetcore server generator output. Compare generated methods and their containing class with the expected abstract or virtual behavior; done means no-body methods and abstract methods compile with the appropriate class modifier, while checking whether generateBody and operationModifier differ.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.