Skip to content

Commit 5d0bfc2

Browse files
Marking a class abstract should not mark the methods abstract as well (#23291)
* Marking a class abstract should not mark the methods abstract as well * Generated samples without the changes * Generated samples post-changes * More samples changes * Add appropriate using * Regen samples * Generate samples for all aspnetcore * Generate sample for csharp-functions
1 parent 05dd7fb commit 5d0bfc2

139 files changed

Lines changed: 7094 additions & 6129 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: aspnetcore
2+
outputDir: samples/server/petstore/aspnetcore-8.0-abstract-class
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
5+
additionalProperties:
6+
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
7+
aspnetCoreVersion: "8.0"
8+
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
9+
classModifier: abstract
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: csharp-functions
2+
outputDir: samples/server/petstore/csharp-functions-abstract-class
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/csharp-functions
5+
additionalProperties:
6+
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
7+
userSecretsGuid: "76e9e993-9159-441c-9c5b-fe95e7f4f020"
8+
classModifier: abstract

bin/configs/csharp-functions-latest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generatorName: csharp-functions
2-
outputDir: samples/client/petstore/csharp-functions
2+
outputDir: samples/server/petstore/csharp-functions
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/csharp-functions
55
additionalProperties:

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() {

modules/openapi-generator/src/main/resources/aspnetcore/3.0/controller.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ using Microsoft.AspNetCore.Http;
1313
using Swashbuckle.AspNetCore.Annotations;
1414
using Swashbuckle.AspNetCore.SwaggerGen;
1515
{{/useSwashbuckle}}
16-
{{^isLibrary}}
16+
{{#generateBody}}
1717
{{#useNewtonsoft}}
1818
using Newtonsoft.Json;
1919
{{/useNewtonsoft}}
2020
{{^useNewtonsoft}}
2121
using System.Text.Json;
2222
{{/useNewtonsoft}}
23-
{{/isLibrary}}
23+
{{/generateBody}}
2424
using {{packageName}}.Attributes;
2525
using {{modelPackage}};
2626

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
}

samples/client/petstore/csharp-functions/appveyor.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)