Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ If you want to join the committee, please kindly apply by sending an email to te
| Android | @jaz-ah (2017/09) |
| Apex | |
| Bash | @frol (2017/07) @bkryza (2017/08) @kenjones-cisco (2017/09) |
| C | @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03) |
| C | @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03) @eafer (2024/12) |
| C++ | @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @martindelille (2018/03) @muttleyxd (2019/08) |
| C# | @mandrean (2017/08) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @iBicha (2023/07) |
| Clojure | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: aspnetcore
outputDir: samples/server/petstore/aspnetcore-8.0-use-centralized-package-version-management
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'
centralizedPackageVersionManagement: "jghfj"
2 changes: 2 additions & 0 deletions docs/generators/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ------ | ----------- | ------ | ------- |
|aspnetCoreVersion|ASP.NET Core version: 6.0, 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)|<dl><dt>**2.0**</dt><dd>ASP.NET Core 2.0</dd><dt>**2.1**</dt><dd>ASP.NET Core 2.1</dd><dt>**2.2**</dt><dd>ASP.NET Core 2.2</dd><dt>**3.0**</dt><dd>ASP.NET Core 3.0</dd><dt>**3.1**</dt><dd>ASP.NET Core 3.1</dd><dt>**5.0**</dt><dd>ASP.NET Core 5.0</dd><dt>**6.0**</dt><dd>ASP.NET Core 6.0</dd><dt>**7.0**</dt><dd>ASP.NET Core 7.0</dd><dt>**8.0**</dt><dd>ASP.NET Core 8.0</dd></dl>|8.0|
|buildTarget|Target to build an application or library|<dl><dt>**program**</dt><dd>Generate code for a standalone server</dd><dt>**library**</dt><dd>Generate code for a server abstract class library</dd></dl>|program|
|centralizedPackageVersionManagementOptOut|Opt out of centralized package version management. Set this if you have a Directory.Packages.pros file but want this project to ignore it. https://devblogs.microsoft.com/nuget/introducing-central-package-management/#disabling-central-package-management| |false|
|classModifier|Class Modifier for controller classes: Empty string or abstract.| ||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_2|
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|
Expand All @@ -46,6 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src|
|swashbuckleVersion|Swashbuckle version: 3.0.0 (deprecated), 4.0.0 (deprecated), 5.0.0 (deprecated), 6.4.0|<dl><dt>**3.0.0**</dt><dd>Swashbuckle 3.0.0</dd><dt>**4.0.0**</dt><dd>Swashbuckle 4.0.0</dd><dt>**5.0.0**</dt><dd>Swashbuckle 5.0.0</dd><dt>**6.4.0**</dt><dd>Swashbuckle 6.4.0</dd></dl>|6.4.0|
|useCentralizedPackageVersionManagement|Uses centralized package version management. https://devblogs.microsoft.com/nuget/introducing-central-package-management/#disabling-central-package-management| |false|
|useCollection|Deserialize array types to Collection&lt;T&gt; instead of List&lt;T&gt;.| |false|
|useDateTimeForDate|Use DateTime to model date properties even if DateOnly supported. (.net 6.0+ only)| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6524,6 +6524,9 @@ public String sanitizeName(final String name, String removeCharRegEx, ArrayList<
// input.name => input_name
modifiable = this.sanitizeValue(modifiable, "\\.", "_", exceptions);

// input:name => input_name
modifiable = this.sanitizeValue(modifiable, ":", "_", exceptions);

// input-name => input_name
modifiable = this.sanitizeValue(modifiable, "-", "_", exceptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import lombok.Getter;
import lombok.Setter;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.*;
Expand Down Expand Up @@ -64,8 +65,11 @@ public class AspNetServerCodegen extends AbstractCSharpCodegen {
public static final String USE_NEWTONSOFT = "useNewtonsoft";
public static final String USE_DEFAULT_ROUTING = "useDefaultRouting";
public static final String NEWTONSOFT_VERSION = "newtonsoftVersion";
public static final String CENTRALIZED_PACKAGE_VERSION_MANAGEMENT = "centralizedPackageVersionManagement";
public static final String USE_PACKAGE_VERSIONS = "usePackageVersions";

@Setter private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
@Setter
private String packageGuid = "{" + randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
private String userSecretsGuid = randomUUID().toString();

protected final Logger LOGGER = LoggerFactory.getLogger(AspNetServerCodegen.class);
Expand All @@ -91,6 +95,27 @@ public class AspNetServerCodegen extends AbstractCSharpCodegen {
private boolean useNewtonsoft = true;
private boolean useDefaultRouting = true;
private String newtonsoftVersion = "3.0.0";
protected CliOption centralizedPackageVersionManagement = new CliOption(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT,"Option to control the usage of centralized package version management. https://devblogs.microsoft.com/nuget/introducing-central-package-management/#disabling-central-package-management");


@Getter
private enum CentralizedPackageVersionOptions {
Default("default","Property in project wont be used"),
Use("use","Centralized package version management will be used"),
OptOut("optout","Opt out of centralized package version management. Set this if you have a Directory.Packages.pros file but want this project to ignore it. https://devblogs.microsoft.com/nuget/introducing-central-package-management/#disabling-central-package-management");

private final String Value;
private final String Description;

CentralizedPackageVersionOptions(String Value,String Description) {
this.Value = Value;
this.Description = Description;
}

public String GetDescription(){
return this.Description;
}
}

public AspNetServerCodegen() {
super();
Expand Down Expand Up @@ -249,6 +274,8 @@ public AspNetServerCodegen() {
"Uses the Newtonsoft JSON library.",
useNewtonsoft);

addCentralizedPackageVersionManagementOption();

addOption(NEWTONSOFT_VERSION,
"Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+",
newtonsoftVersion);
Expand Down Expand Up @@ -303,11 +330,21 @@ public AspNetServerCodegen() {
addOption(modelClassModifier.getOpt(), modelClassModifier.getDescription(), modelClassModifier.getOptValue());
}

private void addCentralizedPackageVersionManagementOption(){
centralizedPackageVersionManagement.setType("String");
for (CentralizedPackageVersionOptions option : CentralizedPackageVersionOptions.values() ) {
centralizedPackageVersionManagement.addEnum(option.Value, option.GetDescription());
}
centralizedPackageVersionManagement.setDefault(CentralizedPackageVersionOptions.Default.Value);
centralizedPackageVersionManagement.setOptValue(centralizedPackageVersionManagement.getDefault());
cliOptions.add(centralizedPackageVersionManagement);
}

@Deprecated
@Override
protected Set<String> getNullableTypes() {
return new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double",
"DateTime", "DateOnly", "DateTimeOffset", "Guid"));
"DateTime", "DateOnly", "DateTimeOffset", "Guid"));
}

@Override
Expand Down Expand Up @@ -378,6 +415,8 @@ public void processOpts() {
newtonsoftVersion = (String) additionalProperties.get(NEWTONSOFT_VERSION);
}

setCentralizedPackageVersionManagementSettings();

// Check for the modifiers etc.
// The order of the checks is important.
setBuildTarget();
Expand Down Expand Up @@ -680,6 +719,29 @@ private void setBuildTarget() {
additionalProperties.put(IS_LIBRARY, isLibrary);
}

/**
* This method sets both the USE_CENTRALIZED_PACKAGE_VERSION_MANAGEMENT and CENTRALIZED_PACKAGE_VERSION_MANAGEMENT_OPT_OUT setting
*/
private void setCentralizedPackageVersionManagementSettings() {

additionalProperties.put(USE_PACKAGE_VERSIONS, true);

if(additionalProperties.containsKey(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT)) {
var chosenOption = additionalProperties.get(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT);

if (chosenOption == CentralizedPackageVersionOptions.Default) {
additionalProperties.remove(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT);
}
if (chosenOption == CentralizedPackageVersionOptions.Use) {
additionalProperties.replace(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT,"true");
additionalProperties.put(USE_PACKAGE_VERSIONS, false);
}
if (chosenOption == CentralizedPackageVersionOptions.OptOut) {
additionalProperties.replace(CENTRALIZED_PACKAGE_VERSION_MANAGEMENT,"false");
}
}
}

private void setAspnetCoreVersion(String packageFolder) {
setCliOption(aspnetCoreVersion);

Expand Down Expand Up @@ -808,10 +870,10 @@ private void setIsFramework() {
}

private void setAddititonalPropertyForFramework() {
String targetFramework = ((String)additionalProperties.get(TARGET_FRAMEWORK));
String targetFramework = ((String) additionalProperties.get(TARGET_FRAMEWORK));
if (targetFramework.startsWith("net6.0") ||
targetFramework.startsWith("net7.0") ||
targetFramework.startsWith("net8.0")) {
targetFramework.startsWith("net7.0") ||
targetFramework.startsWith("net8.0")) {
additionalProperties.put(NET_60_OR_LATER, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public String sanitizeModelName(String modelName) {
String[] parts = modelName.split("::");
ArrayList<String> new_parts = new ArrayList<String>();
for (String part : parts) {
new_parts.add(sanitizeName(part));
new_parts.add(sanitizeName(part, "\\W", new ArrayList<>(List.of(":"))));
}
return String.join("::", new_parts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public void processOpts() {
convertPropertyToStringAndWriteBack(RESOURCE_FOLDER, this::setResourceFolder);

typeMapping.put("file", "org.springframework.core.io.Resource");
importMapping.put("Nullable", "org.springframework.lang.Nullable");
importMapping.put("org.springframework.core.io.Resource", "org.springframework.core.io.Resource");
importMapping.put("DateTimeFormat", "org.springframework.format.annotation.DateTimeFormat");
importMapping.put("ApiIgnore", "springfox.documentation.annotations.ApiIgnore");
Expand Down Expand Up @@ -952,6 +953,11 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
if (model.getVendorExtensions().containsKey("x-jackson-optional-nullable-helpers")) {
model.imports.add("Arrays");
}

// to prevent inheritors (JavaCamelServerCodegen etc.) mistakenly use it
if (getName().contains("spring")) {
model.imports.add("Nullable");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam
{{/isContainer}}
{{/vars}}

{{classname}}_t *{{classname}}_create(
static {{classname}}_t *{{classname}}_create_internal(
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
Expand Down Expand Up @@ -205,14 +205,103 @@ char* {{classname}}_{{name}}_ToString({{projectName}}_{{classVarName}}_{{enumNam
{{classname}}_local_var->{{{name}}} = {{{name}}};
{{/vars}}

{{classname}}_local_var->_library_owned = 1;
return {{classname}}_local_var;
}

__attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{^isEnum}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isModel}}
{{^isModel}}
{{^isFreeFormObject}}
{{^isEnum}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{#isEnum}}
{{projectName}}_{{dataType}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isFreeFormObject}}
{{/isModel}}
{{#isUuid}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isUuid}}
{{#isEmail}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isEmail}}
{{#isFreeFormObject}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isByteArray}}
{{#isBinary}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBinary}}
{{#isDate}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDate}}
{{#isDateTime}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isMap}}
{{/isContainer}}
{{/vars}}
) {
return {{classname}}_create_internal (
{{#vars}}
{{name}}{{^-last}},{{/-last}}
{{/vars}}
);
}

void {{classname}}_free({{classname}}_t *{{classname}}) {
if(NULL == {{classname}}){
return ;
}
if({{classname}}->_library_owned != 1){
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "{{classname}}_free");
return ;
}
listEntry_t *listEntry;
{{#vars}}
{{^isContainer}}
Expand Down Expand Up @@ -859,7 +948,7 @@ fail:

{{/vars}}

{{classname}}_local_var = {{classname}}_create (
{{classname}}_local_var = {{classname}}_create_internal (
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ typedef struct {{classname}}_t {
{{/isContainer}}
{{/vars}}

int _library_owned; // Is the library responsible for freeing this object?
} {{classname}}_t;

{{classname}}_t *{{classname}}_create(
__attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^required}}{{^defaultValue}}{{^useOptional}}{{#openApiNullable}}{{^isNullable}}@Nullable {{/isNullable}}{{/openApiNullable}}{{^openApiNullable}}@Nullable {{/openApiNullable}}{{/useOptional}}{{/defaultValue}}{{#defaultValue}}{{^openApiNullable}}{{#isNullable}}@Nullable {{/isNullable}}{{/openApiNullable}}{{/defaultValue}}{{/required}}
Loading