Import from internal git
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<Project Sdk="{{projectSdk}}">
|
||||
<PropertyGroup>
|
||||
<Description>{{packageDescription}}{{^packageDescription}}{{packageName}}{{/packageDescription}}</Description>
|
||||
<Copyright>{{packageCopyright}}</Copyright>
|
||||
<Authors>{{packageAuthors}}</Authors>
|
||||
<TargetFramework>{{targetFramework}}</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<Version>{{packageVersion}}</Version>
|
||||
{{#nullableReferenceTypes}}
|
||||
<Nullable>annotations</Nullable>
|
||||
{{/nullableReferenceTypes}}
|
||||
{{#isLibrary}}
|
||||
<OutputType>Library</OutputType>
|
||||
{{/isLibrary}}
|
||||
<AssemblyName>{{packageName}}</AssemblyName>
|
||||
<PackageId>{{packageName}}</PackageId>
|
||||
<UserSecretsId>{{userSecretsGuid}}</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>..\..</DockerfileContext>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
{{#useSeparateModelProject}}
|
||||
<ProjectReference Include="../{{modelPackage}}/{{modelPackage}}.csproj"/>
|
||||
{{/useSeparateModelProject}}
|
||||
{{#useFrameworkReference}}
|
||||
{{#isLibrary}}
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
{{/isLibrary}}
|
||||
{{/useFrameworkReference}}
|
||||
{{^useFrameworkReference}}
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
{{/useFrameworkReference}}
|
||||
{{^useSeparateModelProject}}
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="{{aspnetCoreVersion}}.0"/>
|
||||
{{/useSeparateModelProject}}
|
||||
{{#useSwashbuckle}}
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
|
||||
{{#useNewtonsoft}}
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="{{swashbuckleVersion}}"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="{{swashbuckleVersion}}"/>
|
||||
{{/useNewtonsoft}}
|
||||
{{^useNewtonsoft}}
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="{{swashbuckleVersion}}"/>
|
||||
{{/useNewtonsoft}}
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="{{swashbuckleVersion}}" />
|
||||
{{/useSwashbuckle}}
|
||||
{{^useSwashbuckle}}
|
||||
{{#useNewtonsoft}}
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="{{newtonsoftVersion}}" />
|
||||
{{/useNewtonsoft}}
|
||||
{{/useSwashbuckle}}
|
||||
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
|
||||
{{#packageReferences}}
|
||||
<PackageReference Include="{{include}}" Version="{{version}}" />
|
||||
{{/packageReferences}}
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!--<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="{{aspnetCoreVersion}}.0" />-->
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
100
architecture/api/templates/7.3.0/aspnetcore/controller.mustache
Normal file
100
architecture/api/templates/7.3.0/aspnetcore/controller.mustache
Normal file
@@ -0,0 +1,100 @@
|
||||
{{>partial_header}}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
{{#operationResultTask}}
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
{{/operationResultTask}}
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
{{#useSwashbuckle}}
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
{{/useSwashbuckle}}
|
||||
{{^isLibrary}}
|
||||
{{#useNewtonsoft}}
|
||||
using Newtonsoft.Json;
|
||||
{{/useNewtonsoft}}
|
||||
{{^useNewtonsoft}}
|
||||
using System.Text.Json;
|
||||
{{/useNewtonsoft}}
|
||||
{{/isLibrary}}
|
||||
using {{packageName}}.Attributes;
|
||||
{{^removeModelPackage}}
|
||||
using {{modelPackage}};
|
||||
{{/removeModelPackage}}
|
||||
{{#modelNamespaces}}
|
||||
using {{.}};
|
||||
{{/modelNamespaces}}
|
||||
|
||||
namespace {{apiPackage}}
|
||||
{ {{#operations}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>{{#description}}
|
||||
[Description("{{.}}")]{{/description}}
|
||||
[ApiController]
|
||||
public {{#classModifier}}{{.}} {{/classModifier}}class {{classname}}Controller : ControllerBase
|
||||
{ {{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>{{#notes}}
|
||||
/// <remarks>{{.}}</remarks>{{/notes}}{{#allParams}}
|
||||
/// <param name="{{paramName}}">{{description}}{{#isDeprecated}} (deprecated){{/isDeprecated}}</param>{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}
|
||||
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>{{/operationIsAsync}}{{/operationResultTask}}{{#responses}}
|
||||
/// <response code="{{code}}">{{message}}</response>{{/responses}}
|
||||
[{{httpMethod}}]
|
||||
[Route("{{{basePathWithoutHost}}}{{{path}}}")]
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
[Authorize(Policy = "{{name}}")]
|
||||
{{/isApiKey}}
|
||||
{{#isBasicBearer}}
|
||||
[Authorize{{#scopes}}{{#-first}}(Roles = "{{/-first}}{{scope}}{{^-last}},{{/-last}}{{#-last}}"){{/-last}}{{/scopes}}]
|
||||
{{/isBasicBearer}}
|
||||
{{/authMethods}}
|
||||
{{#vendorExtensions.x-aspnetcore-consumes}}
|
||||
[Consumes({{&vendorExtensions.x-aspnetcore-consumes}})]
|
||||
{{/vendorExtensions.x-aspnetcore-consumes}}
|
||||
[ValidateModelState]{{#useSwashbuckle}}
|
||||
[SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}}
|
||||
[SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{/responses}}{{/useSwashbuckle}}{{^useSwashbuckle}}{{#responses}}{{#dataType}}
|
||||
[ProducesResponseType(statusCode: {{code}}, type: typeof({{&dataType}}))]{{/dataType}}{{/responses}}{{/useSwashbuckle}}
|
||||
{{#isDeprecated}}
|
||||
[Obsolete]
|
||||
{{/isDeprecated}}
|
||||
public {{operationModifier}} {{#operationResultTask}}{{#operationIsAsync}}async {{/operationIsAsync}}Task<{{/operationResultTask}}{{#responses}}{{#-first}}{{#dataType}}ActionResult<{{&dataType}}>{{/dataType}}{{^dataType}}IActionResult{{/dataType}}{{/-first}}{{/responses}}{{#operationResultTask}}>{{/operationResultTask}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{^-last}}{{^isCookieParam}}, {{/isCookieParam}}{{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}}){{^generateBody}};{{/generateBody}}
|
||||
{{#generateBody}}
|
||||
{
|
||||
{{#cookieParams}}
|
||||
var {{paramName}} = Request.Cookies["{{paramName}}"];
|
||||
{{/cookieParams}}
|
||||
|
||||
{{#responses}}
|
||||
{{#dataType}}
|
||||
//TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode({{code}}, default({{&dataType}}));
|
||||
{{/dataType}}
|
||||
{{^dataType}}
|
||||
//TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode({{code}});
|
||||
{{/dataType}}
|
||||
{{/responses}}
|
||||
{{#returnType}}
|
||||
string exampleJson = null;
|
||||
{{#examples}}
|
||||
exampleJson = "{{{example}}}";
|
||||
{{/examples}}
|
||||
{{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMap}}{{>mapReturn}}{{/isMap}}{{^isMap}}{{>objectReturn}}{{/isMap}}{{/isListCollection}}
|
||||
{{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}}
|
||||
//TODO: Change the data returned
|
||||
return {{#operationResultTask}}{{#operationIsAsync}}await {{/operationIsAsync}}Task.FromResult<IActionResult>({{/operationResultTask}}new ObjectResult(example){{#operationResultTask}}){{/operationResultTask}};{{/returnType}}{{^returnType}}
|
||||
throw new NotImplementedException();{{/returnType}}
|
||||
}
|
||||
{{/generateBody}}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
}
|
||||
199
architecture/api/templates/7.3.0/aspnetcore/model.mustache
Normal file
199
architecture/api/templates/7.3.0/aspnetcore/model.mustache
Normal file
@@ -0,0 +1,199 @@
|
||||
{{>partial_header}}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
{{#useNewtonsoft}}
|
||||
using Newtonsoft.Json;
|
||||
{{/useNewtonsoft}}
|
||||
{{^useNewtonsoft}}
|
||||
using System.Text.Json;
|
||||
{{/useNewtonsoft}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#discriminator}}
|
||||
using JsonSubTypes;
|
||||
{{#useSwashbuckle}}
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
{{/useSwashbuckle}}
|
||||
{{/discriminator}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
using {{packageName}}.Converters;
|
||||
{{#modelNamespaces}}
|
||||
using {{.}};
|
||||
{{/modelNamespaces}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{modelPackage}}
|
||||
{ {{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
{{#discriminator}}
|
||||
{{#useNewtonsoft}}
|
||||
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
|
||||
{{/useNewtonsoft}}
|
||||
{{#useSwashbuckle}}
|
||||
[SwaggerDiscriminator("{{{discriminatorName}}}")]
|
||||
{{/useSwashbuckle}}
|
||||
{{#mappedModels}}
|
||||
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
|
||||
{{#useSwashbuckle}}
|
||||
[SwaggerSubType(typeof({{{modelName}}}), DiscriminatorValue = "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
|
||||
{{/useSwashbuckle}}
|
||||
{{/mappedModels}}
|
||||
{{/discriminator}}
|
||||
public {{#modelClassModifier}}{{.}} {{/modelClassModifier}}class {{classname}} {{#parent}}: {{{.}}}{{^pocoModels}}, {{/pocoModels}}{{/parent}}{{^pocoModels}}{{^parent}}: {{/parent}}IEquatable<{{classname}}>{{/pocoModels}}
|
||||
{
|
||||
{{#vars}}
|
||||
{{#items.isEnum}}
|
||||
{{#items}}
|
||||
{{^complexType}}
|
||||
{{>enumClass}}
|
||||
{{/complexType}}
|
||||
{{/items}}
|
||||
{{/items.isEnum}}
|
||||
{{#isEnum}}
|
||||
{{^complexType}}
|
||||
{{>enumClass}}
|
||||
{{/complexType}}
|
||||
{{/isEnum}}
|
||||
/// <summary>
|
||||
/// {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
/// </summary>{{#description}}
|
||||
/// <value>{{.}}</value>{{/description}}{{#example}}
|
||||
/// <example>{{.}}</example>{{/example}}{{#required}}
|
||||
[Required]{{/required}}{{#pattern}}
|
||||
[RegularExpression("{{{.}}}")]{{/pattern}}{{#minLength}}{{#maxLength}}
|
||||
[StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
|
||||
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
|
||||
[MaxLength({{.}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
|
||||
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#vendorExtensions.x-is-value-type}}true{{/vendorExtensions.x-is-value-type}}{{^vendorExtensions.x-is-value-type}}false{{/vendorExtensions.x-is-value-type}}{{/isNullable}})]
|
||||
{{#isEnum}}
|
||||
public {{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
public {{{dataType}}} {{name}} { get; set; }{{#defaultValue}} = {{{.}}};{{/defaultValue}}
|
||||
{{/isEnum}}
|
||||
{{^-last}}
|
||||
|
||||
{{/-last}}
|
||||
{{/vars}}
|
||||
|
||||
{{^pocoModels}}
|
||||
/// <summary>
|
||||
/// Returns the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{/vars}}
|
||||
sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public {{#parent}}{{^isMap}}{{^isArray}}new {{/isArray}}{{/isMap}}{{/parent}}string ToJson()
|
||||
{
|
||||
{{#useNewtonsoft}}
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
{{/useNewtonsoft}}
|
||||
{{^useNewtonsoft}}
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
{{/useNewtonsoft}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals(({{classname}})obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if {{classname}} instances are equal
|
||||
/// </summary>
|
||||
/// <param name="other">Instance of {{classname}} to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals({{classname}} other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return {{#vars}}{{^isContainer}}
|
||||
(
|
||||
{{name}} == other.{{name}} ||
|
||||
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&{{/vendorExtensions.x-is-value-type}}
|
||||
{{name}}.Equals(other.{{name}})
|
||||
){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
|
||||
(
|
||||
{{name}} == other.{{name}} ||
|
||||
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&
|
||||
other.{{name}} != null &&
|
||||
{{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(other.{{name}})
|
||||
){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
{{#vars}}
|
||||
{{^vendorExtensions.x-is-value-type}}if ({{name}} != null){{/vendorExtensions.x-is-value-type}}
|
||||
hashCode = hashCode * 59 + {{name}}.GetHashCode();
|
||||
{{/vars}}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==({{classname}} left, {{classname}} right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=({{classname}} left, {{classname}} right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
{{/pocoModels}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
||||
22
architecture/api/templates/7.3.0/aspnetcore/readme.txt
Normal file
22
architecture/api/templates/7.3.0/aspnetcore/readme.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
Ce répertoire doit exister même si il ne contient aucun template modifiés.
|
||||
Il ne doit contenir que les templates modifiés pour cette version du générateur.
|
||||
|
||||
----------------------------
|
||||
controller.mustache
|
||||
----------------------------
|
||||
- Retourner IActionResult uniquement pour les méthodes qui n'ont pas de contenu dans leur première réponse.
|
||||
Sinon, retourner un ActionResult<T> avec le dataType de la première des réponses du endpoint.
|
||||
|
||||
- Ajout de l'option "useModelPackage" pour pouvoir supprimer le using des models si il n'y a plus aucun modèle dans l'api.
|
||||
|
||||
- Ajout automatique des référence vers les package de modèles externes via modelNamespaces
|
||||
|
||||
----------------------------
|
||||
model.mustache
|
||||
----------------------------
|
||||
Ajout automatique des référence vers les package de modèles externes via modelNamespaces
|
||||
|
||||
----------------------------
|
||||
Project.csproj.mustache
|
||||
----------------------------
|
||||
Ajout automatique des références via packageReferences (tableau de couple include/version).
|
||||
Reference in New Issue
Block a user