From 29a85d54a287dfae06fea83aa1c2ebc56f3ef702 Mon Sep 17 00:00:00 2001 From: james-beer <48411570+james-beer@users.noreply.github.com> Date: Thu, 18 Jul 2019 06:22:12 +0100 Subject: [PATCH] Adds default property values in ASP .NET Core models (#3369) * Fixes docker-entrypoint.sh * Adds default property values to C# model templates (#3359). --- docker-entrypoint.sh | 2 +- .../src/main/resources/aspnetcore/2.0/model.mustache | 4 ++-- .../src/main/resources/aspnetcore/2.1/model.mustache | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4decc3de6490..3b993a1be33e 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -19,7 +19,7 @@ if [[ -f "${codegen}" && -n "$(java ${JAVA_OPTS} -jar "${codegen}" completion | command=$1 shift exec java ${JAVA_OPTS} -jar "${codegen}" "${command}" "$@" -elif [[ -n "$(echo commands | tr ',' '\n' | grep "^$1\$" )" ]]; then +elif [[ -n "$(echo $commands | tr ',' '\n' | grep "^$1\$" )" ]]; then # If CLI jar does not exist, and $1 is a known CLI command, build the CLI jar and run that command. if [[ ! -f "${codegen}" ]]; then (cd "${GEN_DIR}" && exec mvn -am -pl "modules/openapi-generator-cli" -Duser.home=$(dirname $MAVEN_CONFIG) package) diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache index 8cbfaf0efdbb..101e95cbfc4d 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.0/model.mustache @@ -28,10 +28,10 @@ namespace {{packageName}}.Models {{/required}} [DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}})] {{#isEnum}} - public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; } + public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; }{{#defaultValue}} = {{{defaultValue}}};{{/defaultValue}} {{/isEnum}} {{^isEnum}} - public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } + public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }{{#defaultValue}} = {{{defaultValue}}};{{/defaultValue}} {{/isEnum}} {{#hasMore}} {{/hasMore}} diff --git a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache index e4be72baec87..e198e2447e78 100644 --- a/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache +++ b/modules/openapi-generator/src/main/resources/aspnetcore/2.1/model.mustache @@ -31,10 +31,10 @@ namespace {{modelPackage}} {{/pattern}} [DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}})] {{#isEnum}} - public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; } + public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; }{{#defaultValue}} = {{{defaultValue}}};{{/defaultValue}} {{/isEnum}} {{^isEnum}} - public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; } + public {{{dataType}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }{{#defaultValue}} = {{{defaultValue}}};{{/defaultValue}} {{/isEnum}} {{#hasMore}} {{/hasMore}}