Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/configs/aspnetcore-8.0-abstract-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-abstract-class
inputSpec: modules/openapi-generator/src/test/resources/3_0/aspnetcore/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/aspnetcore/3.0
additionalProperties:
packageGuid: '{3C799344-F285-4669-8FD5-7ED9B795D5C5}'
aspnetCoreVersion: "8.0"
userSecretsGuid: 'cb87e868-8646-48ef-9bb6-344b537d0d37'
classModifier: abstract
6 changes: 6 additions & 0 deletions bin/configs/csharp-functions-abstract-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: csharp-functions
outputDir: samples/server/petstore/csharp-functions-abstract-class
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/csharp-functions
additionalProperties:
classModifier: abstract
2 changes: 1 addition & 1 deletion bin/configs/csharp-functions-latest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generatorName: csharp-functions
outputDir: samples/client/petstore/csharp-functions
outputDir: samples/server/petstore/csharp-functions
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/csharp-functions
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,8 @@ private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
}

private void setClassModifier() {
// CHeck for class modifier if not present set the default value.
// Check for class modifier if not present set the default value.
setCliOption(classModifier);

// 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());
}
}

private void setOperationModifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,8 @@ private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
}

private void setClassModifier() {
// CHeck for class modifier if not present set the default value.
// Check for class modifier if not present set the default value.
setCliOption(classModifier);

// 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());
}
}

private void setOperationModifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ using Microsoft.AspNetCore.Http;
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
{{/useSwashbuckle}}
{{^isLibrary}}
{{#generateBody}}
{{#useNewtonsoft}}
using Newtonsoft.Json;
{{/useNewtonsoft}}
{{^useNewtonsoft}}
using System.Text.Json;
{{/useNewtonsoft}}
{{/isLibrary}}
{{/generateBody}}
using {{packageName}}.Attributes;
using {{modelPackage}};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2026 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.codegen.csharpnetcore;

import org.openapitools.codegen.languages.AspNetServerCodegen;
import org.testng.Assert;
import org.testng.annotations.Test;

public class AspNetServerCodegenTest {

@Test
public void abstractClassUsesDefaultVirtualOperations() {
final AspNetServerCodegen codegen = new AspNetServerCodegen();
codegen.additionalProperties().put("classModifier", "abstract");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
}

@Test
public void abstractOperationsDisableBodyGeneration() {
final AspNetServerCodegen codegen = new AspNetServerCodegen();
codegen.additionalProperties().put("classModifier", "abstract");
codegen.additionalProperties().put("operationModifier", "abstract");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "abstract");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.FALSE);
}

@Test
public void libraryBuildUsesDefaultVirtualOperations() {
final AspNetServerCodegen codegen = new AspNetServerCodegen();
codegen.additionalProperties().put("buildTarget", "library");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,39 @@ public void testToEnumVarName() throws Exception {
// Assert.assertEquals(codegen.toEnumVarName("FOO-BAR", "string"), "FooBar");
// Assert.assertEquals(codegen.toEnumVarName("FOO_BAR", "string"), "FooBar");
}

@Test
public void abstractClassUsesDefaultVirtualOperations() {
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
codegen.additionalProperties().put("classModifier", "abstract");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("classModifier"), "abstract");
Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
}

@Test
public void abstractOperationsDisableBodyGeneration() {
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
codegen.additionalProperties().put("classModifier", "abstract");
codegen.additionalProperties().put("operationModifier", "abstract");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "abstract");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.FALSE);
}

@Test
public void libraryBuildUsesDefaultVirtualOperations() {
final CSharpFunctionsServerCodegen codegen = new CSharpFunctionsServerCodegen();
codegen.additionalProperties().put("buildTarget", "library");

codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get("operationModifier"), "virtual");
Assert.assertEquals(codegen.additionalProperties().get("generateBody"), Boolean.TRUE);
}
}
9 changes: 0 additions & 9 deletions samples/client/petstore/csharp-functions/appveyor.yml

This file was deleted.

Loading