[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.
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

View File

@ -28,6 +28,6 @@ sidebar_label: aspnetcore
|operationModifier|Operation Modifier can be virtual, abstract or partial| |virtual|
|buildTarget|Target to build an application or library| |program|
|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|
|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);
aspnetCoreVersion.addEnum("2.0", "ASP.NET COre V2.0");
aspnetCoreVersion.addEnum("2.1", "ASP.NET COre V2.1");
aspnetCoreVersion.addEnum("2.2", "ASP.NET COre V2.2");
aspnetCoreVersion.addEnum("2.0", "ASP.NET COre 2.0");
aspnetCoreVersion.addEnum("2.1", "ASP.NET Core 2.1");
aspnetCoreVersion.addEnum("2.2", "ASP.NET Core 2.2");
aspnetCoreVersion.setDefault("2.2");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());
@ -180,13 +180,13 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
classModifier.setOptValue(classModifier.getDefault());
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.setDefault("virtual");
operationModifier.setOptValue(operationModifier.getDefault());
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.setDefault("program");
buildTarget.setOptValue(buildTarget.getDefault());
@ -197,7 +197,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
generateBody);
addSwitch(OPERATION_IS_ASYNC,
"Set methods to async or sync.",
"Set methods to async or sync (default).",
operationIsAsync);
addSwitch(OPERATION_RESULT_TASK,

View File

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

View File

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

View File

@ -44,7 +44,7 @@ namespace {{packageName}}
services
.AddMvc()
{{#compatibilityVersion}}
.SetCompatibilityVersion (CompatibilityVersion.{{compatibilityVersion}})
.SetCompatibilityVersion(CompatibilityVersion.{{compatibilityVersion}})
{{/compatibilityVersion}}
.AddJsonOptions(opts =>
{
@ -53,7 +53,8 @@ namespace {{packageName}}
{
CamelCaseText = true
});
});{{#useSwashbuckle}}
});
{{#useSwashbuckle}}
services
.AddSwaggerGen(c =>
@ -82,7 +83,8 @@ namespace {{packageName}}
// 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!
c.OperationFilter<GeneratePathParamsValidationFilter>();
});{{/useSwashbuckle}}
});
{{/useSwashbuckle}}
}
/// <summary>
@ -109,7 +111,7 @@ namespace {{packageName}}
// c.SwaggerEndpoint("/openapi-original.json", "{{#appName}}{{{appName}}}{{/appName}}{{^appName}}{{packageName}}{{/appName}} Original");
}){{/useSwashbuckle}};
if (env.IsDevelopment())
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

View File

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

View File

@ -15,7 +15,7 @@ namespace {{modelPackage}}
/// {{description}}
/// </summary>
[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}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
@ -92,6 +92,7 @@ namespace {{modelPackage}}
(
{{name}} == other.{{name}} ||
{{name}} != null &&
other.{{name}} != null &&
{{name}}.SequenceEqual(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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