Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/generators/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sidebar_label: aspnetcore
|newtonsoftVersion|Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+| |3.0.0-preview5-19227-01|
|useDefaultRouting|Use default routing for the ASP.NET Core version. For 3.0 turn off default because it is not yet supported.| |true|
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|
|enumValueNameSuffix|Suffix that will be appended to all enum value names.| |Enum|
|enumValueSuffix|Suffix that will be appended to all enum values.| |Enum|
|classModifier|Class Modifier can be empty, abstract| ||
|operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual|
|buildTarget|Target to build an application or library| |program|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String ENUM_NAME_SUFFIX = "enumNameSuffix";
public static final String ENUM_NAME_SUFFIX_DESC = "Suffix that will be appended to all enum names.";

public static final String ENUM_VALUE_NAME_SUFFIX = "enumValueNameSuffix";
public static final String ENUM_VALUE_NAME_SUFFIX_DESC = "Suffix that will be appended to all enum value names.";
public static final String ENUM_VALUE_SUFFIX = "enumValueSuffix";
public static final String ENUM_VALUE_SUFFIX_DESC = "Suffix that will be appended to all enum values. Note: For clients this may impact serialization and deserialization of enum values.";

public static final String GIT_HOST = "gitHost";
public static final String GIT_HOST_DESC = "Git host, e.g. gitlab.com.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co

protected String interfacePrefix = "I";
protected String enumNameSuffix = "Enum";
protected String enumValueNameSuffix = "Enum";
protected String enumValueSuffix = "Enum";

protected String sourceFolder = "src";

Expand Down Expand Up @@ -367,8 +367,8 @@ public void processOpts() {
setEnumNameSuffix(additionalProperties.get(CodegenConstants.ENUM_NAME_SUFFIX).toString());
}

if (additionalProperties().containsKey(CodegenConstants.ENUM_VALUE_NAME_SUFFIX)) {
setEnumValueNameSuffix(additionalProperties.get(CodegenConstants.ENUM_VALUE_NAME_SUFFIX).toString());
if (additionalProperties().containsKey(CodegenConstants.ENUM_VALUE_SUFFIX)) {
setEnumValueSuffix(additionalProperties.get(CodegenConstants.ENUM_VALUE_SUFFIX).toString());
}

// This either updates additionalProperties with the above fixes, or sets the default if the option was not specified.
Expand Down Expand Up @@ -1017,8 +1017,8 @@ public void setEnumNameSuffix(final String enumNameSuffix) {
this.enumNameSuffix = enumNameSuffix;
}

public void setEnumValueNameSuffix(final String enumValueNameSuffix) {
this.enumValueNameSuffix = enumValueNameSuffix;
public void setEnumValueSuffix(final String enumValueSuffix) {
this.enumValueSuffix = enumValueSuffix;
}

public boolean isSupportNullable() {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ public String toEnumVarName(String name, String datatype) {
enumName = enumName.replaceFirst("^_", "");
enumName = enumName.replaceFirst("_$", "");

enumName = camelize(enumName) + this.enumValueNameSuffix;
enumName = camelize(enumName) + this.enumValueSuffix;

if (enumName.matches("\\d.*")) { // starts with number
return "_" + enumName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public AspNetCoreServerCodegen() {
CodegenConstants.ENUM_NAME_SUFFIX_DESC,
enumNameSuffix);

addOption(CodegenConstants.ENUM_VALUE_NAME_SUFFIX,
CodegenConstants.ENUM_VALUE_NAME_SUFFIX_DESC,
enumValueNameSuffix);
addOption(CodegenConstants.ENUM_VALUE_SUFFIX,
"Suffix that will be appended to all enum values.",
enumValueSuffix);

classModifier.addEnum("", "Keep class default with no modifier");
classModifier.addEnum("abstract", "Make class abstract");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

package org.openapitools.codegen.csharp;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
Expand All @@ -30,7 +31,6 @@

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CsharpModelEnumTest {
Expand Down Expand Up @@ -93,6 +93,25 @@ public void overrideEnumTest() {
*/
}

@Test(description = "use custom suffixes for enums")
public void useCustomEnumSuffixes() {
final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen();
codegen.setEnumNameSuffix("EnumName");
codegen.setEnumValueSuffix("EnumValue");

OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml");
codegen.setOpenAPI(openAPI);

final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet");
final CodegenModel cm = codegen.fromModel("Pet", petSchema);
final CodegenProperty statusProperty = cm.vars.get(5);
Assert.assertEquals(statusProperty.name, "Status");
Assert.assertTrue(statusProperty.isEnum);
Assert.assertEquals(statusProperty.datatypeWithEnum, "StatusEnumName");

Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "AaaaEnumValue");
}

@Test(description = "use default suffixes for enums")
public void useDefaultEnumSuffixes() {
final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen();
Expand All @@ -110,11 +129,11 @@ public void useDefaultEnumSuffixes() {
Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "AaaaEnum");
}

@Test(description = "use custom suffixes for enums")
public void useCustomEnumSuffixes() {
@Test(description = "support empty suffixes for enums")
public void useEmptyEnumSuffixes() {
final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen();
codegen.setEnumNameSuffix("EnumName");
codegen.setEnumValueNameSuffix("EnumValue");
codegen.setEnumNameSuffix("");
codegen.setEnumValueSuffix("");

OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/petstore.yaml");
codegen.setOpenAPI(openAPI);
Expand All @@ -124,8 +143,9 @@ public void useCustomEnumSuffixes() {
final CodegenProperty statusProperty = cm.vars.get(5);
Assert.assertEquals(statusProperty.name, "Status");
Assert.assertTrue(statusProperty.isEnum);
Assert.assertEquals(statusProperty.datatypeWithEnum, "StatusEnumName");
Assert.assertEquals(statusProperty.datatypeWithEnum, "Status");

Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "AaaaEnumValue");
Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "Aaaa");
}

}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.0-SNAPSHOT
4.2.3-SNAPSHOT
2 changes: 2 additions & 0 deletions samples/client/petstore/csharp/OpenAPIClientNet35/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Class | Method | HTTP request | Description
- [Model.ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [Model.ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [Model.ArrayTest](docs/ArrayTest.md)
- [Model.BigCat](docs/BigCat.md)
- [Model.BigCatAllOf](docs/BigCatAllOf.md)
- [Model.Capitalization](docs/Capitalization.md)
- [Model.Cat](docs/Cat.md)
- [Model.CatAllOf](docs/CatAllOf.md)
Expand Down
14 changes: 14 additions & 0 deletions samples/client/petstore/csharp/OpenAPIClientNet35/docs/BigCat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Org.OpenAPITools.Model.BigCat

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Declawed** | **bool** | | [optional]
**Kind** | **string** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models)
[[Back to API list]](../README.md#documentation-for-api-endpoints)
[[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# Org.OpenAPITools.Model.BigCatAllOf

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Kind** | **string** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models)
[[Back to API list]](../README.md#documentation-for-api-endpoints)
[[Back to README]](../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using NUnit.Framework;

using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;

namespace Org.OpenAPITools.Test
{
/// <summary>
/// Class for testing BigCatAllOf
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class BigCatAllOfTests
{
// TODO uncomment below to declare an instance variable for BigCatAllOf
//private BigCatAllOf instance;

/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
// TODO uncomment below to create an instance of BigCatAllOf
//instance = new BigCatAllOf();
}

/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{

}

/// <summary>
/// Test an instance of BigCatAllOf
/// </summary>
[Test]
public void BigCatAllOfInstanceTest()
{
// TODO uncomment below to test "IsInstanceOf" BigCatAllOf
//Assert.IsInstanceOf(typeof(BigCatAllOf), instance);
}


/// <summary>
/// Test the property 'Kind'
/// </summary>
[Test]
public void KindTest()
{
// TODO unit test for the property 'Kind'
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://github.com/openapitools/openapi-generator.git
*/


using NUnit.Framework;

using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using Org.OpenAPITools.Client;
using System.Reflection;
using Newtonsoft.Json;

namespace Org.OpenAPITools.Test
{
/// <summary>
/// Class for testing BigCat
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the model.
/// </remarks>
public class BigCatTests
{
// TODO uncomment below to declare an instance variable for BigCat
//private BigCat instance;

/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
// TODO uncomment below to create an instance of BigCat
//instance = new BigCat();
}

/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{

}

/// <summary>
/// Test an instance of BigCat
/// </summary>
[Test]
public void BigCatInstanceTest()
{
// TODO uncomment below to test "IsInstanceOf" BigCat
//Assert.IsInstanceOf(typeof(BigCat), instance);
}


/// <summary>
/// Test the property 'Kind'
/// </summary>
[Test]
public void KindTest()
{
// TODO unit test for the property 'Kind'
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Org.OpenAPITools.Model
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
[JsonSubtypes.KnownSubType(typeof(Dog), "Dog")]
[JsonSubtypes.KnownSubType(typeof(Cat), "Cat")]
[JsonSubtypes.KnownSubType(typeof(BigCat), "BigCat")]
public partial class Animal : IEquatable<Animal>
{
/// <summary>
Expand Down
Loading