Skip to content

[BUG][ASPNETCORE] Abstract classes can't have virtual methids #23225

@MisinformedDNA

Description

@MisinformedDNA

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

The code comments say

// If class modifier is abstract then the methods need to be abstract too.

But this is not and has never been true. Virtual methods should indeed be allowed and it's confusing that it doesn't work with the correct settings. operationModifier is forced to be abstract when classModifier is abstract.

openapi-generator version

7.10.0 (not a regression)

Generation Details

java -jar .\openapi-generator-cli.jar generate -g aspnetcode -c config.json

{
  "classModifier": "abstract",
  "operationModifier": "virtual" // Also the default setting
}
Steps to reproduce

Just generate

Related issues/PRs

#7042

Suggest a fix

This code should be removed

// If class modifier is abstract then the methods need to be abstract too.
if ("abstract".equals(classModifier.getOptValue())) {
operationModifier.setOptValue(classModifier.getOptValue());
additionalProperties.put(OPERATION_MODIFIER, operationModifier.getOptValue());
LOGGER.warn("classModifier is {} so forcing operationModifier to {}", classModifier.getOptValue(), operationModifier.getOptValue());
}

This changes methods from abstract to virtual but is still technically a non-breaking change.

If this is an acceptable change, I can create a PR.

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