Skip to content

Commit 77e3326

Browse files
authored
Make all C# flavors support x-zero-based-enum and add tables to documentation (#21463)
* Make all C# flavors support x-zero-based-enum and add table to documentation * Add the documentation stuff properly
1 parent 36cea14 commit 77e3326

File tree

13 files changed

+44
-8
lines changed

13 files changed

+44
-8
lines changed

docs/generators/aspnet-fastendpoints.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3838
|useValidators|Enable request validators (https://fast-endpoints.com/docs/validation).| |false|
3939
|versioningPrefix|The versioning prefix for the API. Used only if useApiVersioning is true| |v|
4040

41+
## SUPPORTED VENDOR EXTENSIONS
42+
43+
| Extension name | Description | Applicable for | Default value |
44+
| -------------- | ----------- | -------------- | ------------- |
45+
|x-zero-based-enum|When used on an enum, the index will not be generated and the default numbering will be used, zero-based|MODEL|false
46+
47+
4148
## IMPORT MAPPING
4249

4350
| Type/Alias | Imports |

docs/generators/aspnetcore.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5656
|useSeparateModelProject|Create a separate project for models| |false|
5757
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |true|
5858

59+
## SUPPORTED VENDOR EXTENSIONS
60+
61+
| Extension name | Description | Applicable for | Default value |
62+
| -------------- | ----------- | -------------- | ------------- |
63+
|x-zero-based-enum|When used on an enum, the index will not be generated and the default numbering will be used, zero-based|MODEL|false
64+
65+
5966
## IMPORT MAPPING
6067

6168
| Type/Alias | Imports |

docs/generators/csharp-functions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4848
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
4949
|useNewtonsoft|Uses the Newtonsoft JSON library.| |true|
5050

51+
## SUPPORTED VENDOR EXTENSIONS
52+
53+
| Extension name | Description | Applicable for | Default value |
54+
| -------------- | ----------- | -------------- | ------------- |
55+
|x-zero-based-enum|When used on an enum, the index will not be generated and the default numbering will be used, zero-based|MODEL|false
56+
57+
5158
## IMPORT MAPPING
5259

5360
| Type/Alias | Imports |

docs/generators/csharp.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5757
|validatable|Generates self-validatable models.| |true|
5858
|zeroBasedEnums|Enumerations with string values will start from 0 when true, 1 when false. If not set, enumerations with string values will start from 0 if the first value is 'unknown', case insensitive.| |null|
5959

60+
## SUPPORTED VENDOR EXTENSIONS
61+
62+
| Extension name | Description | Applicable for | Default value |
63+
| -------------- | ----------- | -------------- | ------------- |
64+
|x-zero-based-enum|When used on an enum, the index will not be generated and the default numbering will be used, zero-based|MODEL|false
65+
66+
6067
## IMPORT MAPPING
6168

6269
| Type/Alias | Imports |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum VendorExtension {
2424
X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null),
2525
X_VERSION_PARAM("x-version-param", ExtensionLevel.OPERATION_PARAMETER, "Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false", null),
2626
X_PATTERN_MESSAGE("x-pattern-message", Arrays.asList(ExtensionLevel.FIELD, ExtensionLevel.OPERATION_PARAMETER), "Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable", null),
27+
X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false"),
2728
;
2829

2930
private final String name;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
105105
protected boolean supportNullable = Boolean.FALSE;
106106

107107
@Setter protected Boolean zeroBasedEnums = null;
108-
protected static final String zeroBasedEnumVendorExtension = "x-zero-based-enum";
108+
protected static final String zeroBasedEnumVendorExtension = VendorExtension.X_ZERO_BASED_ENUM.getName();
109109

110110
private final Logger LOGGER = LoggerFactory.getLogger(AbstractCSharpCodegen.class);
111111

@@ -2103,6 +2103,13 @@ protected Set<String> getNullableTypes() {
21032103
throw new RuntimeException("This method should no longer be used.");
21042104
}
21052105

2106+
@Override
2107+
public List<VendorExtension> getSupportedVendorExtensions() {
2108+
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
2109+
extensions.add(VendorExtension.X_ZERO_BASED_ENUM);
2110+
return extensions;
2111+
}
2112+
21062113
protected Set<String> getValueTypes() {
21072114
return new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateOnly", "DateTimeOffset", "Guid"));
21082115
}

modules/openapi-generator/src/main/resources/aspnet-fastendpoints/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
/// <summary>
1212
/// Enum {{name}} for {{{value}}}
1313
/// </summary>
14-
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
14+
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
1515
{{/-last}}{{/enumVars}}{{/allowableValues}}
1616
}

modules/openapi-generator/src/main/resources/aspnetcore/2.0/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
/// Enum {{name}} for {{{value}}}
1414
/// </summary>
1515
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
16-
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
16+
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
1717
{{/-last}}{{/enumVars}}{{/allowableValues}}
1818
}

modules/openapi-generator/src/main/resources/aspnetcore/2.1/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
/// Enum {{name}} for {{{value}}}
1515
/// </summary>
1616
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
17-
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
17+
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
1818
{{/-last}}{{/enumVars}}{{/allowableValues}}
1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
/// Enum {{name}} for {{{value}}}
1515
/// </summary>
1616
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
17-
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
17+
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
1818
{{/-last}}{{/enumVars}}{{/allowableValues}}
1919
}

0 commit comments

Comments
 (0)