Skip to content

Commit 8d82889

Browse files
Marking a class abstract should not mark the methods abstract as well
1 parent c1e0361 commit 8d82889

4 files changed

Lines changed: 97 additions & 16 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetServerCodegen.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,8 @@ private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
673673
}
674674

675675
private void setClassModifier() {
676-
// CHeck for class modifier if not present set the default value.
676+
// Check for class modifier if not present set the default value.
677677
setCliOption(classModifier);
678-
679-
// If class modifier is abstract then the methods need to be abstract too.
680-
if ("abstract".equals(classModifier.getOptValue())) {
681-
operationModifier.setOptValue(classModifier.getOptValue());
682-
additionalProperties.put(OPERATION_MODIFIER, operationModifier.getOptValue());
683-
LOGGER.warn("classModifier is {} so forcing operationModifier to {}", classModifier.getOptValue(), operationModifier.getOptValue());
684-
}
685678
}
686679

687680
private void setOperationModifier() {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpFunctionsServerCodegen.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,15 +539,8 @@ private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
539539
}
540540

541541
private void setClassModifier() {
542-
// CHeck for class modifier if not present set the default value.
542+
// Check for class modifier if not present set the default value.
543543
setCliOption(classModifier);
544-
545-
// If class modifier is abstract then the methods need to be abstract too.
546-
if ("abstract".equals(classModifier.getOptValue())) {
547-
operationModifier.setOptValue(classModifier.getOptValue());
548-
additionalProperties.put(OPERATION_MODIFIER, operationModifier.getOptValue());
549-
LOGGER.warn("classModifier is {} so forcing operationModifier to {}", classModifier.getOptValue(), operationModifier.getOptValue());
550-
}
551544
}
552545

553546
private void setOperationModifier() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2026 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.openapitools.codegen.csharpnetcore;
18+
19+
import org.openapitools.codegen.languages.AspNetServerCodegen;
20+
import org.testng.Assert;
21+
import org.testng.annotations.Test;
22+
23+
public class AspNetServerCodegenTest {
24+
25+
@Test
26+
public void abstractClassUsesDefaultVirtualOperations() {
27+
final AspNetServerCodegen codegen = new AspNetServerCodegen();
28+
codegen.additionalProperties().put("classModifier", "abstract");
29+
30+
codegen.processOpts();
31+
32+
Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
33+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
34+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
35+
}
36+
37+
@Test
38+
public void abstractOperationsDisableBodyGeneration() {
39+
final AspNetServerCodegen codegen = new AspNetServerCodegen();
40+
codegen.additionalProperties().put("classModifier", "abstract");
41+
codegen.additionalProperties().put("operationModifier", "abstract");
42+
43+
codegen.processOpts();
44+
45+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "abstract");
46+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.FALSE);
47+
}
48+
49+
@Test
50+
public void libraryBuildUsesDefaultVirtualOperations() {
51+
final AspNetServerCodegen codegen = new AspNetServerCodegen();
52+
codegen.additionalProperties().put("buildTarget", "library");
53+
54+
codegen.processOpts();
55+
56+
Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
57+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
58+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
59+
}
60+
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcorefunctions/CSharpFunctionsServerCodegenTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,39 @@ public void testToEnumVarName() throws Exception {
3737
// Assert.assertEquals(codegen.toEnumVarName("FOO-BAR", "string"), "FooBar");
3838
// Assert.assertEquals(codegen.toEnumVarName("FOO_BAR", "string"), "FooBar");
3939
}
40+
41+
@Test
42+
public void abstractClassUsesDefaultVirtualOperations() {
43+
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
44+
codegen.additionalProperties().put("classModifier", "abstract");
45+
46+
codegen.processOpts();
47+
48+
Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
49+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
50+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
51+
}
52+
53+
@Test
54+
public void abstractOperationsDisableBodyGeneration() {
55+
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
56+
codegen.additionalProperties().put("classModifier", "abstract");
57+
codegen.additionalProperties().put("operationModifier", "abstract");
58+
59+
codegen.processOpts();
60+
61+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "abstract");
62+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.FALSE);
63+
}
64+
65+
@Test
66+
public void libraryBuildUsesDefaultVirtualOperations() {
67+
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
68+
codegen.additionalProperties().put("buildTarget", "library");
69+
70+
codegen.processOpts();
71+
72+
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
73+
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
74+
}
4075
}

0 commit comments

Comments
 (0)