{
"runtime": "Net60",
"defaultVariables": null,
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project": "AaaSubSystem.Web.csproj", // プロジェクト名を指定
"msBuildProjectExtensionsPath": null,
"configuration": "$(Configuration)",
"runtime": null,
"targetFramework": null,
"noBuild": true,
"msBuildOutputPath": null,
"verbose": true,
"workingDirectory": null,
"requireParametersWithoutDefault": true,
"apiGroupNames": null,
"defaultPropertyNameHandling": "Default",
"defaultReferenceTypeNullHandling": "Null",
"defaultDictionaryValueReferenceTypeNullHandling": "NotNull",
"defaultResponseReferenceTypeNullHandling": "NotNull",
"generateOriginalParameterNames": true,
"defaultEnumHandling": "Integer",
"flattenInheritanceHierarchy": false,
"generateKnownTypes": true,
"generateEnumMappingDescription": false,
"generateXmlObjects": false,
"generateAbstractProperties": false,
"generateAbstractSchemas": true,
"ignoreObsoleteProperties": false,
"allowReferencesWithProperties": false,
"useXmlDocumentation": true,
"resolveExternalXmlDocumentation": true,
"excludedTypeNames": [],
"serviceHost": "localhost:5001", // vite のホスト指定を推奨
"serviceBasePath": null,
"serviceSchemes": [
"https"
],
"infoTitle": "Xxx Web API",
"infoDescription": "Xxx の Web API 仕様",
"infoVersion": "1.0.0",
"documentTemplate": null,
"documentProcessorTypes": [],
"operationProcessorTypes": [],
"typeNameGeneratorType": null,
"schemaNameGeneratorType": null,
"contractResolverType": null,
"serializerSettingsType": null,
"useDocumentProvider": false,
"documentName": "v1",
"aspNetCoreEnvironment": "Development",
"createWebHostBuilderMethod": null,
"startupType": null,
"allowNullableBodyParameters": true,
"useHttpAttributeNameAsOperationId": false,
"output": "XXXXXXXXX-api.json", // 出力するファイル名を指定
"outputType": "OpenApi3",
"newLineBehavior": "Auto",
"assemblyPaths": [],
"assemblyConfig": null,
"referencePaths": [],
"useNuGetCache": false
}
},
"codeGenerators": {}
}
目次案
.NET編
事前準備
ソシューション構造の作成
リポジトリとディレクトリ構造の作成
ここでは単一のソリューション内の構造を示す
ソリューション構造へのリンク(おおまかなプロジェクトの構成は「Maris OSS 版のアプリケーションアーキテクチャ概要編」に以下のように書かれている。詳しい構造化については書かれていないので、ここで示す)
概要編の記載もあわせて見直す。
ソリューションフォルダーを使って物理的なファイル配置とソリューション内の構造を一致させる
src(プロダクションコードを配置)、tests(テストで使用するコードを配置)ソリューションフォルダーでまず大きく分ける(多くの場合コード分析ルールの厳しさが異なるので、分けておいた方がよい。editorconfigをtests直下に置くと、テスト用のコード分析ルールを作成できる)
srcフォルダー内は原則フラットに並べるが、プロジェクト数が多くなる場合は適宜ソリューションフォルダーを使って整理する(srcフォルダー内のプロジェクトが30を超える場合はソリューションフォルダーを用いて整理することを推奨)。
testsフォルダー内はテストの目的(単体機能確認、結合機能確認、性能、E2Eなど)に応じてテストプロジェクトを分割する。
プロジェクトの作成
プロジェクトの共通設定
プロジェクトファイルの設定
静的コード分析用パッケージと設定ファイルの導入
editorconfig
StyleCop Analyzers
メッセージリソースファイルの作成
プロジェクト構造の作成
ASP.NET Core Web API プロジェクトの構成
Open API 仕様書の出力設定
UIとOpen API仕様書を生成できるようにする。
NSwag.AspNetCoreとNSwag.MSBuild、Microsoft.AspNetCore.Mvc.NewtonsoftJsonのNuGetパッケージを追加
nswag.jsonをプロジェクトルートに追加。
コードの生成は行わないので、ドキュメント生成の設定のみ実施。詳細は以下に飛ばす。
https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document
以下nswag.jsonの設定例
{ "runtime": "Net60", "defaultVariables": null, "documentGenerator": { "aspNetCoreToOpenApi": { "project": "AaaSubSystem.Web.csproj", // プロジェクト名を指定 "msBuildProjectExtensionsPath": null, "configuration": "$(Configuration)", "runtime": null, "targetFramework": null, "noBuild": true, "msBuildOutputPath": null, "verbose": true, "workingDirectory": null, "requireParametersWithoutDefault": true, "apiGroupNames": null, "defaultPropertyNameHandling": "Default", "defaultReferenceTypeNullHandling": "Null", "defaultDictionaryValueReferenceTypeNullHandling": "NotNull", "defaultResponseReferenceTypeNullHandling": "NotNull", "generateOriginalParameterNames": true, "defaultEnumHandling": "Integer", "flattenInheritanceHierarchy": false, "generateKnownTypes": true, "generateEnumMappingDescription": false, "generateXmlObjects": false, "generateAbstractProperties": false, "generateAbstractSchemas": true, "ignoreObsoleteProperties": false, "allowReferencesWithProperties": false, "useXmlDocumentation": true, "resolveExternalXmlDocumentation": true, "excludedTypeNames": [], "serviceHost": "localhost:5001", // vite のホスト指定を推奨 "serviceBasePath": null, "serviceSchemes": [ "https" ], "infoTitle": "Xxx Web API", "infoDescription": "Xxx の Web API 仕様", "infoVersion": "1.0.0", "documentTemplate": null, "documentProcessorTypes": [], "operationProcessorTypes": [], "typeNameGeneratorType": null, "schemaNameGeneratorType": null, "contractResolverType": null, "serializerSettingsType": null, "useDocumentProvider": false, "documentName": "v1", "aspNetCoreEnvironment": "Development", "createWebHostBuilderMethod": null, "startupType": null, "allowNullableBodyParameters": true, "useHttpAttributeNameAsOperationId": false, "output": "XXXXXXXXX-api.json", // 出力するファイル名を指定 "outputType": "OpenApi3", "newLineBehavior": "Auto", "assemblyPaths": [], "assemblyConfig": null, "referencePaths": [], "useNuGetCache": false } }, "codeGenerators": {} }Open API 仕様がビルド時に生成されるように設定
詳細は以下を参照。
https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild
.NET6の場合は以下のように設定するなる。
swaggerの設定を変更(Program.cs)
https://github.com/RicoSuter/NSwag/wiki/AspNetCore-Middleware
ドキュメント出力の設定例
swaggerのUIを開発環境でのみ有効化(Program.cs)
例外ハンドリングの設定
Bad Request返却時のログ出力設定(これ以外ないかも)
ASP.NET Core with Vite プロジェクトの構成
ASP.NET Core Web API プロジェクトの設定を行ったうえで以下を実施する。
SpaRoot プロパティにフロントエンドアプリケーションのルートディレクトリを設定。
テンプレートの構成だとプロジェクト内にフロントエンドアプリケーションを配置することになるが、Maris OSS版としてはソリューション外のディレクトリ(以下の例だとfrontendディレクトリ)に配置することを推奨。
ClientAppディレクトリを削除または移動(上記SpaRootにもともと設定されているディレクトリを消す、または設定したfrontendディレクトリに移動する)。
frontendディレクトリ内に配置するアプリケーションの構築についてはVue.js編を参照。
プロジェクトファイル内の以下の要素を削除。
プロジェクト内からSpaRootに設定されているディレクトリがすべて消えるので、以下の設定は不要になる。
SpaProxyLaunchCommand プロパティにフロンエンドアプリケーションの起動コマンドを設定。
フロントエンドアプリケーションの起動コマンドは、構築したアプリケーションによって異なるので注意。
xUnit テストプロジェクトの設定(いらないかも)
Moq NuGetパッケージを追加
ImplicitUsing に XunitとMoqを追加