mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-04-20 05:29:10 +00:00
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
This commit is contained in:
@@ -38,6 +38,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|useValidators|Enable request validators (https://fast-endpoints.com/docs/validation).| |false|
|
||||
|versioningPrefix|The versioning prefix for the API. Used only if useApiVersioning is true| |v|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|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
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
|
||||
@@ -56,6 +56,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|useSeparateModelProject|Create a separate project for models| |false|
|
||||
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |true|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|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
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
|
||||
@@ -48,6 +48,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
|
||||
|useNewtonsoft|Uses the Newtonsoft JSON library.| |true|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|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
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
|
||||
@@ -57,6 +57,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|validatable|Generates self-validatable models.| |true|
|
||||
|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|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|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
|
||||
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
| Type/Alias | Imports |
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum VendorExtension {
|
||||
X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null),
|
||||
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),
|
||||
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),
|
||||
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"),
|
||||
;
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -105,7 +105,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
protected boolean supportNullable = Boolean.FALSE;
|
||||
|
||||
@Setter protected Boolean zeroBasedEnums = null;
|
||||
protected static final String zeroBasedEnumVendorExtension = "x-zero-based-enum";
|
||||
protected static final String zeroBasedEnumVendorExtension = VendorExtension.X_ZERO_BASED_ENUM.getName();
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(AbstractCSharpCodegen.class);
|
||||
|
||||
@@ -2103,6 +2103,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
throw new RuntimeException("This method should no longer be used.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VendorExtension> getSupportedVendorExtensions() {
|
||||
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
|
||||
extensions.add(VendorExtension.X_ZERO_BASED_ENUM);
|
||||
return extensions;
|
||||
}
|
||||
|
||||
protected Set<String> getValueTypes() {
|
||||
return new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateOnly", "DateTimeOffset", "Guid"));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
/// <summary>
|
||||
/// Enum {{name}} for {{{value}}}
|
||||
/// </summary>
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
/// Enum {{name}} for {{{value}}}
|
||||
/// </summary>
|
||||
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
/// Enum {{name}} for {{{value}}}
|
||||
/// </summary>
|
||||
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
/// Enum {{name}} for {{{value}}}
|
||||
/// </summary>
|
||||
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
/// Enum {{name}} for {{{value}}}
|
||||
/// </summary>
|
||||
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
{{#isString}}
|
||||
[EnumMember(Value = "{{{value}}}")]
|
||||
{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},{{/-last}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},{{/-last}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
{{#isString}}
|
||||
[EnumMember(Value = "{{{value}}}")]
|
||||
{{/isString}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{-index}}{{/isString}}{{^-last}},{{/-last}}
|
||||
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},{{/-last}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
Reference in New Issue
Block a user