[ASP.NET Core] minor format fix, better null check (#2778)

* aspnet core format fix, better null check

* minor wording change

* update doc
This commit is contained in:
William Cheng 2019-05-02 04:55:14 +08:00 committed by Jim Schubert
parent 40759a57fb
commit 05053f5b8a
14 changed files with 40 additions and 25 deletions

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/aspnetcore --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} $@" ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/2.1/ -o samples/server/petstore/aspnetcore --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} $@"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -28,6 +28,6 @@ sidebar_label: aspnetcore
|operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual| |operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual|
|buildTarget|Target to build an application or library| |program| |buildTarget|Target to build an application or library| |program|
|generateBody|Generates method body.| |true| |generateBody|Generates method body.| |true|
|operationIsAsync|Set methods to async or sync.| |false| |operationIsAsync|Set methods to async or sync (default).| |false|
|operationResultTask|Set methods result to Task<>.| |false| |operationResultTask|Set methods result to Task<>.| |false|
|modelClassModifier|Model Class Modifier can be nothing or partial| |partial| |modelClassModifier|Model Class Modifier can be nothing or partial| |partial|

View File

@ -142,9 +142,9 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
addOption(COMPATIBILITY_VERSION, "ASP.Net Core CompatibilityVersion", compatibilityVersion); addOption(COMPATIBILITY_VERSION, "ASP.Net Core CompatibilityVersion", compatibilityVersion);
aspnetCoreVersion.addEnum("2.0", "ASP.NET COre V2.0"); aspnetCoreVersion.addEnum("2.0", "ASP.NET COre 2.0");
aspnetCoreVersion.addEnum("2.1", "ASP.NET COre V2.1"); aspnetCoreVersion.addEnum("2.1", "ASP.NET Core 2.1");
aspnetCoreVersion.addEnum("2.2", "ASP.NET COre V2.2"); aspnetCoreVersion.addEnum("2.2", "ASP.NET Core 2.2");
aspnetCoreVersion.setDefault("2.2"); aspnetCoreVersion.setDefault("2.2");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault()); aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue()); addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());
@ -180,13 +180,13 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
classModifier.setOptValue(classModifier.getDefault()); classModifier.setOptValue(classModifier.getDefault());
addOption(classModifier.getOpt(), classModifier.getDescription(), classModifier.getOptValue()); addOption(classModifier.getOpt(), classModifier.getDescription(), classModifier.getOptValue());
operationModifier.addEnum("virtual", "Keep method virtual "); operationModifier.addEnum("virtual", "Keep method virtual");
operationModifier.addEnum("abstract", "Make method abstract"); operationModifier.addEnum("abstract", "Make method abstract");
operationModifier.setDefault("virtual"); operationModifier.setDefault("virtual");
operationModifier.setOptValue(operationModifier.getDefault()); operationModifier.setOptValue(operationModifier.getDefault());
addOption(operationModifier.getOpt(), operationModifier.getDescription(), operationModifier.getOptValue()); addOption(operationModifier.getOpt(), operationModifier.getDescription(), operationModifier.getOptValue());
buildTarget.addEnum("program", "Generate code for standalone server"); buildTarget.addEnum("program", "Generate code for a standalone server");
buildTarget.addEnum("library", "Generate code for a server abstract class lbrary"); buildTarget.addEnum("library", "Generate code for a server abstract class lbrary");
buildTarget.setDefault("program"); buildTarget.setDefault("program");
buildTarget.setOptValue(buildTarget.getDefault()); buildTarget.setOptValue(buildTarget.getDefault());
@ -197,7 +197,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
generateBody); generateBody);
addSwitch(OPERATION_IS_ASYNC, addSwitch(OPERATION_IS_ASYNC,
"Set methods to async or sync.", "Set methods to async or sync (default).",
operationIsAsync); operationIsAsync);
addSwitch(OPERATION_RESULT_TASK, addSwitch(OPERATION_RESULT_TASK,

View File

@ -1,8 +1,10 @@
{{>partial_header}} {{>partial_header}}
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;{{#useSwashbuckle}} using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.SwaggerGen;{{/useSwashbuckle}} {{#useSwashbuckle}}
using Swashbuckle.AspNetCore.SwaggerGen;
{{/useSwashbuckle}}
using Newtonsoft.Json; using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using {{packageName}}.Attributes; using {{packageName}}.Attributes;

View File

@ -92,6 +92,7 @@ namespace {{packageName}}.Models
( (
{{name}} == other.{{name}} || {{name}} == other.{{name}} ||
{{name}} != null && {{name}} != null &&
other.{{name}} != null &&
{{name}}.SequenceEqual(other.{{name}}) {{name}}.SequenceEqual(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}}; ){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
} }

View File

@ -44,7 +44,7 @@ namespace {{packageName}}
services services
.AddMvc() .AddMvc()
{{#compatibilityVersion}} {{#compatibilityVersion}}
.SetCompatibilityVersion (CompatibilityVersion.{{compatibilityVersion}}) .SetCompatibilityVersion(CompatibilityVersion.{{compatibilityVersion}})
{{/compatibilityVersion}} {{/compatibilityVersion}}
.AddJsonOptions(opts => .AddJsonOptions(opts =>
{ {
@ -53,7 +53,8 @@ namespace {{packageName}}
{ {
CamelCaseText = true CamelCaseText = true
}); });
});{{#useSwashbuckle}} });
{{#useSwashbuckle}}
services services
.AddSwaggerGen(c => .AddSwaggerGen(c =>
@ -82,7 +83,8 @@ namespace {{packageName}}
// Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..) // Include DataAnnotation attributes on Controller Action parameters as Swagger validation rules (e.g required, pattern, ..)
// Use [ValidateModelState] on Actions to actually validate it in C# as well! // Use [ValidateModelState] on Actions to actually validate it in C# as well!
c.OperationFilter<GeneratePathParamsValidationFilter>(); c.OperationFilter<GeneratePathParamsValidationFilter>();
});{{/useSwashbuckle}} });
{{/useSwashbuckle}}
} }
/// <summary> /// <summary>
@ -109,7 +111,7 @@ namespace {{packageName}}
// c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original"); // c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original");
}){{/useSwashbuckle}}; }){{/useSwashbuckle}};
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }

View File

@ -1,12 +1,17 @@
{{>partial_header}} {{>partial_header}}
using System; using System;
using System.Collections.Generic;{{#operationResultTask}} using System.Collections.Generic;
{{#operationResultTask}}
using System.Threading.Tasks; using System.Threading.Tasks;
{{/operationResultTask}} {{/operationResultTask}}
using Microsoft.AspNetCore.Mvc;{{#useSwashbuckle}} using Microsoft.AspNetCore.Mvc;
{{#useSwashbuckle}}
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;{{/useSwashbuckle}}{{^isLibrary}} using Swashbuckle.AspNetCore.SwaggerGen;
using Newtonsoft.Json;{{/isLibrary}} {{/useSwashbuckle}}
{{^isLibrary}}
using Newtonsoft.Json;
{{/isLibrary}}
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using {{packageName}}.Attributes; using {{packageName}}.Attributes;
using {{modelPackage}}; using {{modelPackage}};

View File

@ -15,7 +15,7 @@ namespace {{modelPackage}}
/// {{description}} /// {{description}}
/// </summary> /// </summary>
[DataContract] [DataContract]
public {{#modelClassModifier}}{{modelClassModifier}} {{/modelClassModifier}} class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}> public {{#modelClassModifier}}{{modelClassModifier}} {{/modelClassModifier}}class {{classname}} : {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>
{ {{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{>enumClass}}{{/items}}{{/items.isEnum}} { {{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}{{>enumClass}}{{/items}}{{/items.isEnum}}
/// <summary> /// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}} /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
@ -92,6 +92,7 @@ namespace {{modelPackage}}
( (
{{name}} == other.{{name}} || {{name}} == other.{{name}} ||
{{name}} != null && {{name}} != null &&
other.{{name}} != null &&
{{name}}.SequenceEqual(other.{{name}}) {{name}}.SequenceEqual(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}}; ){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
} }

View File

@ -15,7 +15,6 @@ Windows:
``` ```
build.bat build.bat
``` ```
## Run in Docker ## Run in Docker
``` ```

View File

@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class PetApiController : ControllerBase [ApiController]
public class PetApiController : ControllerBase
{ {
/// <summary> /// <summary>
/// Add a new pet to the store /// Add a new pet to the store

View File

@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class StoreApiController : ControllerBase [ApiController]
public class StoreApiController : ControllerBase
{ {
/// <summary> /// <summary>
/// Delete purchase order by ID /// Delete purchase order by ID

View File

@ -23,7 +23,8 @@ namespace Org.OpenAPITools.Controllers
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class UserApiController : ControllerBase [ApiController]
public class UserApiController : ControllerBase
{ {
/// <summary> /// <summary>
/// Create user /// Create user

View File

@ -158,11 +158,13 @@ namespace Org.OpenAPITools.Models
( (
PhotoUrls == other.PhotoUrls || PhotoUrls == other.PhotoUrls ||
PhotoUrls != null && PhotoUrls != null &&
other.PhotoUrls != null &&
PhotoUrls.SequenceEqual(other.PhotoUrls) PhotoUrls.SequenceEqual(other.PhotoUrls)
) && ) &&
( (
Tags == other.Tags || Tags == other.Tags ||
Tags != null && Tags != null &&
other.Tags != null &&
Tags.SequenceEqual(other.Tags) Tags.SequenceEqual(other.Tags)
) && ) &&
( (

View File

@ -112,8 +112,8 @@
"type" : "array", "type" : "array",
"items" : { "items" : {
"type" : "string", "type" : "string",
"enum" : [ "available", "pending", "sold" ], "default" : "available",
"default" : "available" "enum" : [ "available", "pending", "sold" ]
} }
} }
} ], } ],