Skip to content

Commit 00b6dbe

Browse files
authored
Add Microsoft.AspNetCore.OpenApi to the webapiaot template (#60337)
* Add basic set up for the new flag with translations by Copilot * Add conditional logic to use OpenAPI * Add OpenAPI test to WebAPIAOT template tests * Fix tests * Add missing endif in the csproj * Add more metadata to get 404 not found in the openapi doc correctly * Also add the 404 metadata to the other file * Change elif to else * Remove unnecessary 118n changes * Add english translation back * Keep the semicolon on the same line as requested by PR review * Use TypedResults instead of extension methods and reduce the if else statements * Add template strings back after running `bash build.sh -test -configuration Release`. I assume this is part of the natural process of creating a PR and thus should be committed. * Add usings for TypedResults and Results/NotFound/Ok etc.. * Add OpenAPI services to Program.Main.cs * Remove http using because thats already part of the implicit usings * TEMP COMMIT - Removing EnableOpenAPI flags to find out why tests fail * Revert "TEMP COMMIT - Removing EnableOpenAPI flags to find out why tests fail" This reverts commit 63cf302. * Fix assertions where we expected OpenAPI to be enabled for published apps, which is not the case * Added consistent indentation in test methods * Fix build errors
1 parent 2dadec3 commit 00b6dbe

21 files changed

+175
-17
lines changed

src/ProjectTemplates/Web.ProjectTemplates/WebApiAot-CSharp.csproj.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@
1010
<PublishAot>true</PublishAot>
1111
</PropertyGroup>
1212

13+
<!--#if (EnableOpenAPI) -->
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="${MicrosoftAspNetCoreOpenApiVersion}" Condition="'$(EnableOpenAPI)' == 'True'" />
16+
</ItemGroup>
17+
<!--#endif -->
18+
1319
</Project>

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/dotnetcli.host.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
"UseProgramMain": {
2222
"longName": "use-program-main",
2323
"shortName": ""
24+
},
25+
"DisableOpenAPI": {
26+
"longName": "no-openapi",
27+
"shortName": ""
2428
}
2529
},
2630
"usageExamples": [
2731
""
2832
]
29-
}
33+
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/ide.host.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
"isVisible": true,
1010
"persistenceScope": "shared",
1111
"persistenceScopeName": "Microsoft"
12+
},
13+
{
14+
"id": "DisableOpenAPI",
15+
"name": {
16+
"text": "Enable _OpenAPI support",
17+
"overrideDefaultText": true
18+
},
19+
"description": {
20+
"text": "Enables OpenAPI (Swagger) support",
21+
"overrideDefaultText": true
22+
},
23+
"invertBoolean": true,
24+
"isVisible": true,
25+
"defaultValue": "true",
26+
"persistenceScope": "templateGroup"
1227
}
1328
]
14-
}
29+
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.cs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "Pokud se tato možnost zadá, přeskočí automatické obnovení projektu při vytvoření.",
1111
"symbols/UseProgramMain/displayName": "Nepoužívat _příkazy nejvyšší úrovně",
1212
"symbols/UseProgramMain/description": "Určuje, jestli se má místo příkazů nejvyšší úrovně generovat explicitní třída Program a metoda Main.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "Obnoví balíčky NuGet vyžadované tímto projektem.",
1415
"postActions/restore/manualInstructions/default/text": "Spustit dotnet restore"
1516
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "Wenn angegeben, wird die automatische Wiederherstellung des Projekts beim Erstellen übersprungen.",
1111
"symbols/UseProgramMain/displayName": "Keine Anweisungen_der obersten Ebene verwenden",
1212
"symbols/UseProgramMain/description": "Gibt an, ob anstelle von Anweisungen der obersten Ebene eine explizite Programmklasse und eine Main-Methode generiert werden soll.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "„NuGet-Pakete“ wiederherstellen, die für dieses Projekt erforderlich sind.",
1415
"postActions/restore/manualInstructions/default/text": "„dotnet restore“ ausführen"
1516
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Microsoft",
33
"name": "ASP.NET Core Web API (native AOT)",
4-
"description": "A project template for creating a RESTful Web API using ASP.NET Core minimal APIs published as native AOT.",
4+
"description": "A project template for creating a RESTful Web API using ASP.NET Core minimal APIs published as native AOT, with optional support for OpenAPI.",
55
"symbols/ExcludeLaunchSettings/description": "Whether to exclude launchSettings.json from the generated template.",
66
"symbols/kestrelHttpPort/description": "Port number to use for the HTTP endpoint in launchSettings.json.",
77
"symbols/iisHttpPort/description": "Port number to use for the IIS Express HTTP endpoint in launchSettings.json.",
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "If specified, skips the automatic restore of the project on create.",
1111
"symbols/UseProgramMain/displayName": "Do not use _top-level statements",
1212
"symbols/UseProgramMain/description": "Whether to generate an explicit Program class and Main method instead of top-level statements.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "Restore NuGet packages required by this project.",
1415
"postActions/restore/manualInstructions/default/text": "Run 'dotnet restore'"
1516
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "Si se especifica, se omite la restauración automática del proyecto durante la creación.",
1111
"symbols/UseProgramMain/displayName": "No usar instrucciones de _nivel superior",
1212
"symbols/UseProgramMain/description": "Indica si se debe generar una clase Program explícita y un método Main en lugar de instrucciones de nivel superior.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "Restaure los paquetes NuGet necesarios para este proyecto.",
1415
"postActions/restore/manualInstructions/default/text": "Ejecutar \"dotnet restore\""
1516
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "S’il est spécifié, ignore la restauration automatique du projet lors de la création.",
1111
"symbols/UseProgramMain/displayName": "N’utilisez pas _d’instructions de niveau supérieur.",
1212
"symbols/UseProgramMain/description": "Indique s’il faut générer une classe Programme explicite et une méthode Main au lieu d’instructions de niveau supérieur.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "Restaurez les packages NuGet requis par ce projet.",
1415
"postActions/restore/manualInstructions/default/text": "Exécuter « dotnet restore »"
1516
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.it.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "Se specificato, ignora il ripristino automatico del progetto durante la creazione.",
1111
"symbols/UseProgramMain/displayName": "Non usare_istruzioni di primo livello",
1212
"symbols/UseProgramMain/description": "Indica se generare una classe Program esplicita e un metodo Main anziché istruzioni di primo livello.",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "Ripristina i pacchetti NuGet richiesti da questo progetto.",
1415
"postActions/restore/manualInstructions/default/text": "Esegui 'dotnet restore'"
1516
}

src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp/.template.config/localize/templatestrings.ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"symbols/skipRestore/description": "指定した場合、作成時にプロジェクトの自動復元がスキップされます。",
1111
"symbols/UseProgramMain/displayName": "最上位レベルのステートメントを使用しない(_T)",
1212
"symbols/UseProgramMain/description": "最上位レベルのステートメントではなく、明示的な Program クラスと Main メソッドを生成するかどうか。",
13+
"symbols/DisableOpenAPI/description": "Disable OpenAPI (Swagger) support",
1314
"postActions/restore/description": "このプロジェクトに必要な NuGet パッケージを復元します。",
1415
"postActions/restore/manualInstructions/default/text": "'dotnet restore' を実行する"
1516
}

0 commit comments

Comments
 (0)