This commit is contained in:
Deep Choudhery 2024-11-05 12:10:02 -08:00 коммит произвёл GitHub
Родитель 6649e87196
Коммит 0f6872da21
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
8 изменённых файлов: 36 добавлений и 188 удалений

Просмотреть файл

@ -401,7 +401,6 @@ namespace Microsoft.VisualStudio.Web.CodeGenerators.Mvc.MinimalApi
{
var openApiDependencies = new HashSet<string>()
{
"Swashbuckle.AspNetCore",
"Microsoft.AspNetCore.OpenApi"
};

Просмотреть файл

@ -19,24 +19,16 @@
"CodeChanges": [
{
"InsertAfter": "WebApplication.CreateBuilder.Services.AddControllers();",
"InsertBefore": [ "WebApplication.CreateBuilder.Services.AddSwaggerGen();", "var app = builder.Build();" ],
"Options": [ "OpenApi" ],
"Block": "WebApplication.CreateBuilder.Services.AddEndpointsApiExplorer()",
"LeadingTrivia": {
"Newline": true
}
},
{
"InsertAfter": "WebApplication.CreateBuilder.Services.AddEndpointsApiExplorer();",
"InsertBefore": [ "var app = builder.Build();" ],
"Options": [ "OpenApi" ],
"Block": "WebApplication.CreateBuilder.Services.AddSwaggerGen()",
"Block": "WebApplication.CreateBuilder.Services.AddOpenApi()",
"LeadingTrivia": {
"Newline": true
}
},
{
"Block": "if (app.Environment.IsDevelopment())\r\n{\r\n app.UseSwagger();\r\n app.UseSwaggerUI();\r\n}",
"CheckBlock": "if (!app.Environment.IsDevelopment())",
"Block": "if (app.Environment.IsDevelopment())\r\n{\r\n app.MapOpenApi();\r\n}",
"Options": [ "OpenApi" ],
"InsertAfter": "var app = WebApplication.CreateBuilder.Build();",
"InsertBefore": [ "app.UseHttpsRedirection();" ],

Просмотреть файл

@ -67,15 +67,6 @@ public static class @endPointsClassName
})
@{
string builderExtensions = $".WithName(\"{@getAllModels}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelList}>(StatusCodes.Status200OK)";
}
@:@builderExtensions;
}
@ -89,15 +80,6 @@ public static class @endPointsClassName
})
@{
builderExtensions = $".WithName(\"{@getModelById}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
@:@builderExtensions;
}
@ -139,16 +121,6 @@ public static class @endPointsClassName
}
@{
builderExtensions = $".WithName(\"{@updateModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status204NoContent)";
}
@:@builderExtensions;
}
@ -160,14 +132,6 @@ public static class @endPointsClassName
})
@{
builderExtensions = $".WithName(\"{@createModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status201Created)";
}
@:@builderExtensions;
}
@ -198,15 +162,6 @@ public static class @endPointsClassName
}
@{
builderExtensions = $".WithName(\"{@deleteModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
@:@builderExtensions;
}
}

Просмотреть файл

@ -56,14 +56,6 @@
})
@{
string builderExtensions = $".WithName(\"{@getAllModels}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelList}>(StatusCodes.Status200OK)";
}
@:@builderExtensions;
}
@ -78,15 +70,6 @@
})
@{
builderExtensions = $".WithName(\"{@getModelById}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
@:@builderExtensions;
}
@ -128,16 +111,6 @@
}
@{
builderExtensions = $".WithName(\"{@updateModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status204NoContent)";
}
@:@builderExtensions;
}
@ -149,14 +122,6 @@
})
@{
builderExtensions = $".WithName(\"{@createModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status201Created)";
}
@:@builderExtensions;
}
@ -187,15 +152,6 @@
}
@{
builderExtensions = $".WithName(\"{@deleteModel}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{@modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
@:@builderExtensions;
}
}

Просмотреть файл

@ -44,6 +44,37 @@
]
}
}
},
{
"FileName": "Program.cs",
"Usings": [],
"Options": [
"OpenApi"
],
"Methods": {
"Global": {
"CodeChanges": [
{
"InsertAfter": "WebApplication.CreateBuilder.Services.AddControllers();",
"InsertBefore": [ "var app = builder.Build();" ],
"Block": "WebApplication.CreateBuilder.Services.AddOpenApi()",
"LeadingTrivia": {
"Newline": true
}
},
{
"CheckBlock": "if (!app.Environment.IsDevelopment())",
"Block": "if (app.Environment.IsDevelopment())\r\n{\r\n app.MapOpenApi();\r\n}",
"Options": [ "OpenApi" ],
"InsertAfter": "var app = WebApplication.CreateBuilder.Build();",
"InsertBefore": [ "app.UseHttpsRedirection();" ],
"LeadingTrivia": {
"Newline": true
}
}
]
}
}
}
]
}

Просмотреть файл

@ -219,7 +219,8 @@ internal class ValidateMinimalApiStep : ScaffoldStep
{
scaffoldingModel.ProjectInfo.CodeChangeOptions =
[
scaffoldingModel.DbContextInfo.EfScenario ? "EfScenario" : string.Empty
scaffoldingModel.DbContextInfo.EfScenario ? "EfScenario" : string.Empty,
settings.OpenApi ? "OpenApi" : string.Empty
];
}

Просмотреть файл

@ -96,14 +96,6 @@ namespace Microsoft.DotNet.Tools.Scaffold.AspNet.Templates.MinimalApi
this.Write(";\r\n })");
string builderExtensions = $".WithName(\"{getAllModels}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{modelList}>(StatusCodes.Status200OK)";
}
this.Write("\r\n ");
this.Write(this.ToStringHelper.ToStringWithCulture(builderExtensions));
@ -130,15 +122,6 @@ namespace Microsoft.DotNet.Tools.Scaffold.AspNet.Templates.MinimalApi
this.Write(";\r\n })");
builderExtensions = $".WithName(\"{getModelById}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{Model.ModelInfo.ModelTypeName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n .Produces(StatusCodes.Status404NotFound)";
}
this.Write("\r\n ");
this.Write(this.ToStringHelper.ToStringWithCulture(builderExtensions));
@ -214,15 +197,6 @@ namespace Microsoft.DotNet.Tools.Scaffold.AspNet.Templates.MinimalApi
}
builderExtensions = $".WithName(\"{updateModel}\")";
if (Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status204NoContent)";
}
this.Write(" ");
@ -240,14 +214,6 @@ namespace Microsoft.DotNet.Tools.Scaffold.AspNet.Templates.MinimalApi
this.Write(";\r\n })\r\n ");
builderExtensions = $".WithName(\"{createModel}\")";
if(Model.OpenAPI)
{
builderExtensions+= $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{Model.ModelInfo.ModelTypeName}>(StatusCodes.Status201Created)";
}
this.Write(this.ToStringHelper.ToStringWithCulture(builderExtensions));
this.Write(";\r\n\r\n ");
@ -304,15 +270,6 @@ namespace Microsoft.DotNet.Tools.Scaffold.AspNet.Templates.MinimalApi
}
builderExtensions = $".WithName(\"{deleteModel}\")";
if (Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
this.Write(this.ToStringHelper.ToStringWithCulture(builderExtensions));
this.Write(";\r\n }\r\n}\r\n");

Просмотреть файл

@ -69,14 +69,6 @@ public static class <#= Model.EndpointsClassName #>
return await db.<#= modelToList #>;
})<#
string builderExtensions = $".WithName(\"{getAllModels}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{modelList}>(StatusCodes.Status200OK)";
}
#>
<#= builderExtensions #>;
@ -90,15 +82,6 @@ public static class <#= Model.EndpointsClassName #>
: <#= resultsNotFound #>;
})<#
builderExtensions = $".WithName(\"{getModelById}\")";
if(Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if(!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{Model.ModelInfo.ModelTypeName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n .Produces(StatusCodes.Status404NotFound)";
}
#>
<#= builderExtensions #>;
@ -149,15 +132,6 @@ public static class <#= Model.EndpointsClassName #>
}
builderExtensions = $".WithName(\"{updateModel}\")";
if (Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status204NoContent)";
}
#>
<#= builderExtensions #>;
@ -170,14 +144,6 @@ public static class <#= Model.EndpointsClassName #>
})
<#
builderExtensions = $".WithName(\"{createModel}\")";
if(Model.OpenAPI)
{
builderExtensions+= $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n .Produces<{Model.ModelInfo.ModelTypeName}>(StatusCodes.Status201Created)";
}
#>
<#= builderExtensions #>;
@ -213,15 +179,6 @@ group.MapDelete("/{id}", async <#= typedTaskOkNotFound #> (<#= primaryKeyShortTy
}
builderExtensions = $".WithName(\"{deleteModel}\")";
if (Model.OpenAPI)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.WithOpenApi()";
}
if (!Model.UseTypedResults)
{
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces<{modelName}>(StatusCodes.Status200OK)";
builderExtensions += $"\r\n{builderExtensionSpaces}.Produces(StatusCodes.Status404NotFound)";
}
#>
<#=builderExtensions #>;
}