{"id":3210,"date":"2024-02-25T11:38:55","date_gmt":"2024-02-25T02:38:55","guid":{"rendered":"https:\/\/took.jp\/?p=3210"},"modified":"2024-02-25T11:38:55","modified_gmt":"2024-02-25T02:38:55","slug":"openapi-generator-cli-unity","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/openapi-generator-cli-unity\/","title":{"rendered":"\u3010Unity\u3011OpenAPI(Swagger)\u304b\u3089openapi-generator-cli\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30fc\u30c9\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b"},"content":{"rendered":"<h2>\u3010Unity\u3011OpenAPI(Swagger)\u304b\u3089openapi-generator-cli\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30fc\u30c9\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b<\/h2>\n<p>Swagger\u3067\u5b9a\u7fa9\u3057\u305fAPI\u4ed5\u69d8\u66f8\u304b\u3089\u578b\u3084\u3001API Request\u51e6\u7406\u3092Unity\uff08C#\uff09\u306b\u81ea\u52d5\u751f\u6210\u3059\u308b\u624b\u9806\u3092\u5099\u5fd8\u9332\u3068\u3057\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u74b0\u5883<\/h3>\n<p>OS : Mac(M1) 14.3.1<\/p>\n<p>Unity : 2022.3.9f1<\/p>\n<p>&nbsp;<\/p>\n<h3>Swagger\u6e96\u5099<\/h3>\n<p>\u307e\u305a\u3001\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u4e0b\u8a18\u306e\u3088\u3046\u306b<strong><span class=\"sc_marker\">openapi.yaml\u3092\u4f5c\u6210<\/span><\/strong>\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">openapi: \"3.0.3\"\r\n\r\ninfo:\r\n  title: \"Sample API\"\r\n  version: \"1.0.0\"\r\n\r\npaths:\r\n  \/api\/v1\/hello-world:\r\n    get:\r\n      summary: \"hello world\"\r\n      responses:\r\n        200:\r\n          description: \"success\"\r\n          content:\r\n            application\/json:\r\n              schema:\r\n                type: string\r\n                example: \"hello world!\"<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u30b3\u30fc\u30c9\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b<\/h3>\n<p>openapi-generator-cli\u304c\u672a\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306e\u65b9\u306f\u3001\u4e0b\u8a18\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-other\">npm install @openapitools\/openapi-generator-cli -g<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3001\u751f\u6210\u30b3\u30fc\u30c9\u3092output_directory\u306b\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-other\">openapi-generator-cli generate -i .\/openapi.yaml -g csharp -o .\/output_directory<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u751f\u6210\u30b3\u30fc\u30c9\u306e\u300csrc\/Org.OpenAPITools\u300d\u306e\u307f\u304c\u6b32\u3057\u3044\u306e\u3067\u3001\u4e00\u6642\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u66f8\u304d\u51fa\u3057\u305f\u5f8c\u306b\u5fc5\u8981\u306a\u90e8\u5206\u306e\u307f\u3092\u66f8\u304d\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-other\">cp -r .\/output_dirctory\/src\/Org.OpenAPITools\/ \/path\/to\/unity-proj\/Assets\/Scripts\/Generated<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u30e2\u30c3\u30af\u30b5\u30fc\u30d0\u3092\u7acb\u3061\u4e0a\u3052\u308b<\/h3>\n<p>\u4eca\u56de\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\uff08Unity\uff09\u5074\u306eAPI\u306e\u81ea\u52d5\u751f\u6210\u3092\u3057\u3066\u3001API\u3092\u547c\u3073\u51fa\u3059\u308f\u3051\u3067\u3059\u304c\u3001\u305d\u306e\u305f\u3081\u306b\u547c\u3073\u51fa\u3055\u308c\u308bAPI\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u88c5\u3057\u3066\u3082\u554f\u984c\u306a\u3044\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u3001\u30e2\u30c3\u30af\u30b5\u30fc\u30d0\u3092\u7acb\u3061\u4e0a\u3052\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong><\/strong><span class=\"sc_marker\"><strong>docker-compose.yaml\u3092\u4f5c\u6210<\/strong><\/span>\u3057\u3001\u4e0b\u8a18\u306e\u5185\u5bb9\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">version: \"3\"\r\nservices:\r\n  swagger-mock:\r\n    image: stoplight\/prism:3\r\n    ports:\r\n      - \"4010:4010\"\r\n    command: mock -h 0.0.0.0 \/openapi.yaml\r\n    restart: on-failure\r\n    volumes:\r\n      - .\/openapi.yaml:\/openapi.yaml\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>docker-compose.yaml\u3092\u4f5c\u6210\u3057\u305f\u306e\u3068\u540c\u968e\u5c64\u3067\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3001\u30b3\u30f3\u30c6\u30ca\u3092\u7acb\u3061\u4e0a\u3052\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-other\">docker compose up -d<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u7acb\u3061\u4e0a\u304c\u3063\u305f\u306e\u3092\u78ba\u8a8d\u3057\u305f\u3089\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3067\u300chello world!\u300d\u304c\u8fd4\u3063\u3066\u304f\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-other\">curl --location 'http:\/\/localhost:4010\/api\/v1\/hello-world'<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u751f\u6210\u30b3\u30fc\u30c9\u304b\u3089API\u3092\u547c\u3073\u3060\u3059<\/h3>\n<p>\u307e\u305aunity\u306b\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><a data-analytics-event=\"{&quot;category&quot;:&quot;SiteHeaderComponent&quot;,&quot;action&quot;:&quot;context_region_crumb&quot;,&quot;label&quot;:&quot;NuGet-importer-for-Unity&quot;,&quot;screen_size&quot;:&quot;full&quot;}\" href=\"https:\/\/github.com\/kumaS-nu\/NuGet-importer-for-Unity\" data-view-component=\"true\" class=\"AppHeader-context-item\"><span class=\"AppHeader-context-item-label \">NuGet-importer-for-Unity<\/span><\/a><span class=\"AppHeader-context-item-label \"> \u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u3001manifest.json\u306e<\/span>dependencies\u30bb\u30af\u30b7\u30e7\u30f3\u306b\u4e0b\u8a18\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">{\r\n  \"dependencies\": {\r\n    ...\r\n    \"org.kumas.nuget-importer\": \"https:\/\/github.com\/kumaS-nu\/NuGet-importer-for-Unity.git?path=NuGetImporterForUnity\/Packages\/NuGet Importer\"\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u6b63\u5e38\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3068\u3001Header\u30e1\u30cb\u30e5\u30fc\u306bNuGet Impoter\u3068\u3044\u3046\u9805\u76ee\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u4e2d\u306e\u4e00\u756a\u4e0a\u3001Manager Importer\u3092\u958b\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/took.jp\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.02.34-265x300.png\" alt=\"\" width=\"265\" height=\"300\" class=\"alignnone size-medium wp-image-3216\" srcset=\"https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.02.34-265x300.png 265w, https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.02.34.png 380w\" sizes=\"(max-width: 265px) 100vw, 265px\" \/><\/p>\n<p>\u3053\u3053\u304b\u3089\u3001\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u9078\u629e\u3057\u3001install\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/took.jp\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.06.07.png\" alt=\"\" width=\"1024\" height=\"486\" class=\"alignnone wp-image-3217 size-full\" srcset=\"https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.06.07.png 1024w, https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.06.07-300x142.png 300w, https:\/\/took.jp\/tech-blog\/wp-content\/uploads\/2024\/02\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2024-02-25-11.06.07-768x365.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u5148\u307b\u3069\u3001\u30b3\u30fc\u30c9\u51fa\u529b\u3057\u305f\u30d5\u30a9\u30eb\u30c0\uff08output_directory\uff09\u306eREADME.md\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>version\u7b49\u306f\u3001\u4f7f\u7528\u3057\u3066\u3044\u308bopenapi-generator-cli\u306eversion\u306b\u4f9d\u5b58\u3059\u308b\u306e\u3067\u3001\u81ea\u8eab\u306e\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">&lt;a id=\"dependencies\"&gt;&lt;\/a&gt;\r\n## Dependencies\r\n\r\n- [RestSharp](https:\/\/www.nuget.org\/packages\/RestSharp) - 106.13.0 or later\r\n- [Json.NET](https:\/\/www.nuget.org\/packages\/Newtonsoft.Json\/) - 13.0.2 or later\r\n- [JsonSubTypes](https:\/\/www.nuget.org\/packages\/JsonSubTypes\/) - 1.8.0 or later\r\n- [System.ComponentModel.Annotations](https:\/\/www.nuget.org\/packages\/System.ComponentModel.Annotations) - 5.0.0 or later<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>unity\u5074\u306bAPI\u3092\u547c\u3073\u51fa\u3059\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\uff08\u52d5\u4f5c\u3057\u306a\u3044\u5834\u5408\u3001README.md\u306b\u3082example\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u305d\u3061\u3089\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff09<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">void Start(){\r\n    var host = \"http:\/\/localhost:4010\";\r\n    var apiInstance = new Org.OpenAPITools.Api.DefaultApi(host);\r\n    var res = apiInstance.ApiV1HelloWorldGet();\r\n    Debug.Log(res);\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Unity\u3092\u518d\u751f\u3057\u3001\u300chello world!\u300d\u304c\u8fd4\u5374\u3055\u308c\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Unity\u3011OpenAPI(Swagger)\u304b\u3089openapi-generator-cli\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30fc\u30c9\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b Swagger\u3067\u5b9a\u7fa9\u3057\u305fAPI\u4ed5\u69d8\u66f8\u304b\u3089\u578b\u3084\u3001API Request\u51e6\u7406\u3092Unity\uff08C#\uff09\u306b\u81ea\u52d5\u751f\u6210\u3059\u308b\u624b\u9806\u3092\u5099\u5fd8\u2026<\/p>\n","protected":false},"author":3,"featured_media":3218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"class_list":["post-3210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/3210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=3210"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/3210\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/3218"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=3210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=3210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=3210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}