@seamapi/nextlove-sdk-generator 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/LICENSE.txt +20 -0
  2. package/README.md +16 -0
  3. package/index.d.ts +6 -0
  4. package/index.js +7 -0
  5. package/index.js.map +1 -0
  6. package/lib/cli.d.ts +2 -0
  7. package/lib/cli.js +53 -0
  8. package/lib/cli.js.map +1 -0
  9. package/lib/fs-util/index.d.ts +2 -0
  10. package/lib/fs-util/index.js +3 -0
  11. package/lib/fs-util/index.js.map +1 -0
  12. package/lib/fs-util/populate-fs.d.ts +1 -0
  13. package/lib/fs-util/populate-fs.js +11 -0
  14. package/lib/fs-util/populate-fs.js.map +1 -0
  15. package/lib/fs-util/write-fs.d.ts +1 -0
  16. package/lib/fs-util/write-fs.js +10 -0
  17. package/lib/fs-util/write-fs.js.map +1 -0
  18. package/lib/generate-csharp-sdk/codegen.d.ts +235 -0
  19. package/lib/generate-csharp-sdk/codegen.js +432 -0
  20. package/lib/generate-csharp-sdk/codegen.js.map +1 -0
  21. package/lib/generate-csharp-sdk/constants.d.ts +1 -0
  22. package/lib/generate-csharp-sdk/constants.js +2 -0
  23. package/lib/generate-csharp-sdk/constants.js.map +1 -0
  24. package/lib/generate-csharp-sdk/generate-csharp-sdk.d.ts +1 -0
  25. package/lib/generate-csharp-sdk/generate-csharp-sdk.js +81 -0
  26. package/lib/generate-csharp-sdk/generate-csharp-sdk.js.map +1 -0
  27. package/lib/generate-csharp-sdk/generate-csproj.d.ts +1 -0
  28. package/lib/generate-csharp-sdk/generate-csproj.js +45 -0
  29. package/lib/generate-csharp-sdk/generate-csproj.js.map +1 -0
  30. package/lib/generate-csharp-sdk/templates/dataclass.d.ts +24 -0
  31. package/lib/generate-csharp-sdk/templates/dataclass.js +468 -0
  32. package/lib/generate-csharp-sdk/templates/dataclass.js.map +1 -0
  33. package/lib/generate-csharp-sdk/templates/fs/csharp-testing.sln +34 -0
  34. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ApiResponse.cs +159 -0
  35. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ClientUtils.cs +280 -0
  36. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ExceptionFactory.cs +12 -0
  37. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/GlobalSeamRequestConfiguration.cs +60 -0
  38. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/HttpMethod.cs +29 -0
  39. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/IAsynchronousSeam.cs +142 -0
  40. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/IReadableSeamRequestConfiguration.cs +68 -0
  41. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ISynchronousSeam.cs +103 -0
  42. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/Multimap.cs +286 -0
  43. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/RequestOptions.cs +74 -0
  44. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/RetryConfiguration.cs +21 -0
  45. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/Seam.cs +1070 -0
  46. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/SeamException.cs +64 -0
  47. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/SeamRequestConfiguration.cs +662 -0
  48. package/lib/generate-csharp-sdk/templates/fs/src/Seam/Model/AsbtractModelSchema.cs +62 -0
  49. package/lib/generate-php-sdk/generate-php-sdk.d.ts +1 -0
  50. package/lib/generate-php-sdk/generate-php-sdk.js +127 -0
  51. package/lib/generate-php-sdk/generate-php-sdk.js.map +1 -0
  52. package/lib/generate-php-sdk/index.d.ts +1 -0
  53. package/lib/generate-php-sdk/index.js +2 -0
  54. package/lib/generate-php-sdk/index.js.map +1 -0
  55. package/lib/generate-php-sdk/templates/composer.json.template.d.ts +2 -0
  56. package/lib/generate-php-sdk/templates/composer.json.template.js +25 -0
  57. package/lib/generate-php-sdk/templates/composer.json.template.js.map +1 -0
  58. package/lib/generate-php-sdk/templates/env.example.template.d.ts +2 -0
  59. package/lib/generate-php-sdk/templates/env.example.template.js +4 -0
  60. package/lib/generate-php-sdk/templates/env.example.template.js.map +1 -0
  61. package/lib/generate-php-sdk/templates/gitignore.template.d.ts +2 -0
  62. package/lib/generate-php-sdk/templates/gitignore.template.js +6 -0
  63. package/lib/generate-php-sdk/templates/gitignore.template.js.map +1 -0
  64. package/lib/generate-php-sdk/templates/package.json.template.d.ts +2 -0
  65. package/lib/generate-php-sdk/templates/package.json.template.js +12 -0
  66. package/lib/generate-php-sdk/templates/package.json.template.js.map +1 -0
  67. package/lib/generate-php-sdk/templates/readme.md.template.d.ts +2 -0
  68. package/lib/generate-php-sdk/templates/readme.md.template.js +86 -0
  69. package/lib/generate-php-sdk/templates/readme.md.template.js.map +1 -0
  70. package/lib/generate-php-sdk/templates/smoke-test.template.d.ts +2 -0
  71. package/lib/generate-php-sdk/templates/smoke-test.template.js +30 -0
  72. package/lib/generate-php-sdk/templates/smoke-test.template.js.map +1 -0
  73. package/lib/generate-php-sdk/templates/test-fixture.template.d.ts +2 -0
  74. package/lib/generate-php-sdk/templates/test-fixture.template.js +21 -0
  75. package/lib/generate-php-sdk/templates/test-fixture.template.js.map +1 -0
  76. package/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.d.ts +16 -0
  77. package/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.js +97 -0
  78. package/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.js.map +1 -0
  79. package/lib/generate-php-sdk/utils/deep-flatten-one-of-and-all-of-schema.d.ts +2 -0
  80. package/lib/generate-php-sdk/utils/deep-flatten-one-of-and-all-of-schema.js +95 -0
  81. package/lib/generate-php-sdk/utils/deep-flatten-one-of-and-all-of-schema.js.map +1 -0
  82. package/lib/generate-php-sdk/utils/generate-resource-object-class.d.ts +8 -0
  83. package/lib/generate-php-sdk/utils/generate-resource-object-class.js +73 -0
  84. package/lib/generate-php-sdk/utils/generate-resource-object-class.js.map +1 -0
  85. package/lib/generate-php-sdk/utils/generate-seam-client.d.ts +7 -0
  86. package/lib/generate-php-sdk/utils/generate-seam-client.js +103 -0
  87. package/lib/generate-php-sdk/utils/generate-seam-client.js.map +1 -0
  88. package/lib/generate-php-sdk/utils/get-php-type.d.ts +1 -0
  89. package/lib/generate-php-sdk/utils/get-php-type.js +17 -0
  90. package/lib/generate-php-sdk/utils/get-php-type.js.map +1 -0
  91. package/lib/generate-php-sdk/utils/php-client.d.ts +31 -0
  92. package/lib/generate-php-sdk/utils/php-client.js +130 -0
  93. package/lib/generate-php-sdk/utils/php-client.js.map +1 -0
  94. package/lib/generate-python-sdk/class-file.d.ts +20 -0
  95. package/lib/generate-python-sdk/class-file.js +75 -0
  96. package/lib/generate-python-sdk/class-file.js.map +1 -0
  97. package/lib/generate-python-sdk/generate-python-sdk.d.ts +1 -0
  98. package/lib/generate-python-sdk/generate-python-sdk.js +117 -0
  99. package/lib/generate-python-sdk/generate-python-sdk.js.map +1 -0
  100. package/lib/generate-python-sdk/index.d.ts +1 -0
  101. package/lib/generate-python-sdk/index.js +2 -0
  102. package/lib/generate-python-sdk/index.js.map +1 -0
  103. package/lib/generate-python-sdk/map-python-type.d.ts +2 -0
  104. package/lib/generate-python-sdk/map-python-type.js +26 -0
  105. package/lib/generate-python-sdk/map-python-type.js.map +1 -0
  106. package/lib/generate-python-sdk/templates/conftest.py.template.d.ts +2 -0
  107. package/lib/generate-python-sdk/templates/conftest.py.template.js +12 -0
  108. package/lib/generate-python-sdk/templates/conftest.py.template.js.map +1 -0
  109. package/lib/generate-python-sdk/templates/pyproject.toml.template.d.ts +2 -0
  110. package/lib/generate-python-sdk/templates/pyproject.toml.template.js +21 -0
  111. package/lib/generate-python-sdk/templates/pyproject.toml.template.js.map +1 -0
  112. package/lib/generate-python-sdk/templates/readme.md.template.d.ts +2 -0
  113. package/lib/generate-python-sdk/templates/readme.md.template.js +48 -0
  114. package/lib/generate-python-sdk/templates/readme.md.template.js.map +1 -0
  115. package/lib/generate-python-sdk/templates/routes.py.template.d.ts +2 -0
  116. package/lib/generate-python-sdk/templates/routes.py.template.js +13 -0
  117. package/lib/generate-python-sdk/templates/routes.py.template.js.map +1 -0
  118. package/lib/generate-python-sdk/templates/seam.py.template.d.ts +2 -0
  119. package/lib/generate-python-sdk/templates/seam.py.template.js +74 -0
  120. package/lib/generate-python-sdk/templates/seam.py.template.js.map +1 -0
  121. package/lib/generate-python-sdk/templates/snippets/abstract-routes.template.d.ts +2 -0
  122. package/lib/generate-python-sdk/templates/snippets/abstract-routes.template.js +9 -0
  123. package/lib/generate-python-sdk/templates/snippets/abstract-routes.template.js.map +1 -0
  124. package/lib/generate-python-sdk/templates/snippets/abstract-seam.template.d.ts +2 -0
  125. package/lib/generate-python-sdk/templates/snippets/abstract-seam.template.js +9 -0
  126. package/lib/generate-python-sdk/templates/snippets/abstract-seam.template.js.map +1 -0
  127. package/lib/generate-python-sdk/templates/snippets/resource-dataclass.template.d.ts +5 -0
  128. package/lib/generate-python-sdk/templates/snippets/resource-dataclass.template.js +10 -0
  129. package/lib/generate-python-sdk/templates/snippets/resource-dataclass.template.js.map +1 -0
  130. package/lib/generate-python-sdk/templates/test_smoke.py.template.d.ts +2 -0
  131. package/lib/generate-python-sdk/templates/test_smoke.py.template.js +13 -0
  132. package/lib/generate-python-sdk/templates/test_smoke.py.template.js.map +1 -0
  133. package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.d.ts +2 -0
  134. package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.js +28 -0
  135. package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.js.map +1 -0
  136. package/lib/generate-ruby-sdk/generate-ruby-sdk.d.ts +1 -0
  137. package/lib/generate-ruby-sdk/generate-ruby-sdk.js +132 -0
  138. package/lib/generate-ruby-sdk/generate-ruby-sdk.js.map +1 -0
  139. package/lib/generate-ruby-sdk/index.d.ts +1 -0
  140. package/lib/generate-ruby-sdk/index.js +2 -0
  141. package/lib/generate-ruby-sdk/index.js.map +1 -0
  142. package/lib/generate-ruby-sdk/request.rb.template.d.ts +1 -0
  143. package/lib/generate-ruby-sdk/request.rb.template.js +2 -0
  144. package/lib/generate-ruby-sdk/request.rb.template.js.map +1 -0
  145. package/lib/generate-ruby-sdk/ruby-client.d.ts +35 -0
  146. package/lib/generate-ruby-sdk/ruby-client.js +59 -0
  147. package/lib/generate-ruby-sdk/ruby-client.js.map +1 -0
  148. package/lib/generate-ruby-sdk/templates/base_client.rb.template.d.ts +2 -0
  149. package/lib/generate-ruby-sdk/templates/base_client.rb.template.js +22 -0
  150. package/lib/generate-ruby-sdk/templates/base_client.rb.template.js.map +1 -0
  151. package/lib/generate-ruby-sdk/templates/base_resource.rb.template.d.ts +2 -0
  152. package/lib/generate-ruby-sdk/templates/base_resource.rb.template.js +59 -0
  153. package/lib/generate-ruby-sdk/templates/base_resource.rb.template.js.map +1 -0
  154. package/lib/generate-ruby-sdk/templates/client.rb.template.d.ts +2 -0
  155. package/lib/generate-ruby-sdk/templates/client.rb.template.js +74 -0
  156. package/lib/generate-ruby-sdk/templates/client.rb.template.js.map +1 -0
  157. package/lib/generate-ruby-sdk/templates/gemfile.template.d.ts +2 -0
  158. package/lib/generate-ruby-sdk/templates/gemfile.template.js +7 -0
  159. package/lib/generate-ruby-sdk/templates/gemfile.template.js.map +1 -0
  160. package/lib/generate-ruby-sdk/templates/logger.rb.template.d.ts +2 -0
  161. package/lib/generate-ruby-sdk/templates/logger.rb.template.js +13 -0
  162. package/lib/generate-ruby-sdk/templates/logger.rb.template.js.map +1 -0
  163. package/lib/generate-ruby-sdk/templates/rakefile.template.d.ts +2 -0
  164. package/lib/generate-ruby-sdk/templates/rakefile.template.js +23 -0
  165. package/lib/generate-ruby-sdk/templates/rakefile.template.js.map +1 -0
  166. package/lib/generate-ruby-sdk/templates/readme.md.template.d.ts +2 -0
  167. package/lib/generate-ruby-sdk/templates/readme.md.template.js +184 -0
  168. package/lib/generate-ruby-sdk/templates/readme.md.template.js.map +1 -0
  169. package/lib/generate-ruby-sdk/templates/request.rb.template.d.ts +2 -0
  170. package/lib/generate-ruby-sdk/templates/request.rb.template.js +71 -0
  171. package/lib/generate-ruby-sdk/templates/request.rb.template.js.map +1 -0
  172. package/lib/generate-ruby-sdk/templates/resource_error.rb.template.d.ts +2 -0
  173. package/lib/generate-ruby-sdk/templates/resource_error.rb.template.js +8 -0
  174. package/lib/generate-ruby-sdk/templates/resource_error.rb.template.js.map +1 -0
  175. package/lib/generate-ruby-sdk/templates/resource_errors_support.rb.template.d.ts +2 -0
  176. package/lib/generate-ruby-sdk/templates/resource_errors_support.rb.template.js +10 -0
  177. package/lib/generate-ruby-sdk/templates/resource_errors_support.rb.template.js.map +1 -0
  178. package/lib/generate-ruby-sdk/templates/resource_warning.rb.template.d.ts +2 -0
  179. package/lib/generate-ruby-sdk/templates/resource_warning.rb.template.js +8 -0
  180. package/lib/generate-ruby-sdk/templates/resource_warning.rb.template.js.map +1 -0
  181. package/lib/generate-ruby-sdk/templates/resource_warnings_support.rb.template.d.ts +2 -0
  182. package/lib/generate-ruby-sdk/templates/resource_warnings_support.rb.template.js +10 -0
  183. package/lib/generate-ruby-sdk/templates/resource_warnings_support.rb.template.js.map +1 -0
  184. package/lib/generate-ruby-sdk/templates/seamapi.gemspec.template.d.ts +2 -0
  185. package/lib/generate-ruby-sdk/templates/seamapi.gemspec.template.js +41 -0
  186. package/lib/generate-ruby-sdk/templates/seamapi.gemspec.template.js.map +1 -0
  187. package/lib/generate-ruby-sdk/templates/snippets/resource.rb.template.d.ts +6 -0
  188. package/lib/generate-ruby-sdk/templates/snippets/resource.rb.template.js +15 -0
  189. package/lib/generate-ruby-sdk/templates/snippets/resource.rb.template.js.map +1 -0
  190. package/lib/generate-ruby-sdk/templates/version.rb.template.d.ts +2 -0
  191. package/lib/generate-ruby-sdk/templates/version.rb.template.js +6 -0
  192. package/lib/generate-ruby-sdk/templates/version.rb.template.js.map +1 -0
  193. package/lib/index.d.ts +2 -0
  194. package/lib/index.js +3 -0
  195. package/lib/index.js.map +1 -0
  196. package/lib/openapi/flatten-obj-schema.d.ts +5 -0
  197. package/lib/openapi/flatten-obj-schema.js +86 -0
  198. package/lib/openapi/flatten-obj-schema.js.map +1 -0
  199. package/lib/openapi/get-parameter-and-response-schema.d.ts +20 -0
  200. package/lib/openapi/get-parameter-and-response-schema.js +42 -0
  201. package/lib/openapi/get-parameter-and-response-schema.js.map +1 -0
  202. package/lib/openapi/index.d.ts +2 -0
  203. package/lib/openapi/index.js +3 -0
  204. package/lib/openapi/index.js.map +1 -0
  205. package/lib/types.d.ts +91 -0
  206. package/lib/types.js +2 -0
  207. package/lib/types.js.map +1 -0
  208. package/package.json +95 -0
  209. package/src/index.ts +6 -0
  210. package/src/lib/cli.ts +71 -0
  211. package/src/lib/fs-util/index.ts +2 -0
  212. package/src/lib/fs-util/populate-fs.ts +14 -0
  213. package/src/lib/fs-util/write-fs.ts +10 -0
  214. package/src/lib/generate-csharp-sdk/codegen.ts +648 -0
  215. package/src/lib/generate-csharp-sdk/constants.ts +1 -0
  216. package/src/lib/generate-csharp-sdk/generate-csharp-sdk.ts +126 -0
  217. package/src/lib/generate-csharp-sdk/generate-csproj.ts +45 -0
  218. package/src/lib/generate-csharp-sdk/templates/dataclass.ts +973 -0
  219. package/src/lib/generate-csharp-sdk/templates/fs/csharp-testing.sln +34 -0
  220. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ApiResponse.cs +159 -0
  221. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ClientUtils.cs +280 -0
  222. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ExceptionFactory.cs +12 -0
  223. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/GlobalSeamRequestConfiguration.cs +60 -0
  224. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/HttpMethod.cs +29 -0
  225. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/IAsynchronousSeam.cs +142 -0
  226. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/IReadableSeamRequestConfiguration.cs +68 -0
  227. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/ISynchronousSeam.cs +103 -0
  228. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/Multimap.cs +286 -0
  229. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/RequestOptions.cs +74 -0
  230. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/RetryConfiguration.cs +21 -0
  231. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/Seam.cs +1070 -0
  232. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/SeamException.cs +64 -0
  233. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Client/SeamRequestConfiguration.cs +662 -0
  234. package/src/lib/generate-csharp-sdk/templates/fs/src/Seam/Model/AsbtractModelSchema.cs +62 -0
  235. package/src/lib/generate-php-sdk/generate-php-sdk.ts +176 -0
  236. package/src/lib/generate-php-sdk/index.ts +1 -0
  237. package/src/lib/generate-php-sdk/templates/composer.json.template.ts +24 -0
  238. package/src/lib/generate-php-sdk/templates/env.example.template.ts +3 -0
  239. package/src/lib/generate-php-sdk/templates/gitignore.template.ts +5 -0
  240. package/src/lib/generate-php-sdk/templates/package.json.template.ts +11 -0
  241. package/src/lib/generate-php-sdk/templates/readme.md.template.ts +85 -0
  242. package/src/lib/generate-php-sdk/templates/smoke-test.template.ts +29 -0
  243. package/src/lib/generate-php-sdk/templates/test-fixture.template.ts +20 -0
  244. package/src/lib/generate-php-sdk/utils/deep-extract-resource-object-schemas.ts +160 -0
  245. package/src/lib/generate-php-sdk/utils/deep-flatten-one-of-and-all-of-schema.ts +128 -0
  246. package/src/lib/generate-php-sdk/utils/generate-resource-object-class.ts +105 -0
  247. package/src/lib/generate-php-sdk/utils/generate-seam-client.ts +115 -0
  248. package/src/lib/generate-php-sdk/utils/get-php-type.ts +21 -0
  249. package/src/lib/generate-php-sdk/utils/php-client.ts +189 -0
  250. package/src/lib/generate-python-sdk/class-file.ts +114 -0
  251. package/src/lib/generate-python-sdk/generate-python-sdk.ts +147 -0
  252. package/src/lib/generate-python-sdk/index.ts +1 -0
  253. package/src/lib/generate-python-sdk/map-python-type.ts +29 -0
  254. package/src/lib/generate-python-sdk/templates/conftest.py.template.ts +11 -0
  255. package/src/lib/generate-python-sdk/templates/pyproject.toml.template.ts +20 -0
  256. package/src/lib/generate-python-sdk/templates/readme.md.template.ts +47 -0
  257. package/src/lib/generate-python-sdk/templates/routes.py.template.ts +13 -0
  258. package/src/lib/generate-python-sdk/templates/seam.py.template.ts +73 -0
  259. package/src/lib/generate-python-sdk/templates/snippets/abstract-routes.template.ts +9 -0
  260. package/src/lib/generate-python-sdk/templates/snippets/abstract-seam.template.ts +8 -0
  261. package/src/lib/generate-python-sdk/templates/snippets/resource-dataclass.template.ts +15 -0
  262. package/src/lib/generate-python-sdk/templates/test_smoke.py.template.ts +12 -0
  263. package/src/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.ts +27 -0
  264. package/src/lib/generate-ruby-sdk/generate-ruby-sdk.ts +153 -0
  265. package/src/lib/generate-ruby-sdk/index.ts +1 -0
  266. package/src/lib/generate-ruby-sdk/request.rb.template.ts +0 -0
  267. package/src/lib/generate-ruby-sdk/ruby-client.ts +81 -0
  268. package/src/lib/generate-ruby-sdk/templates/base_client.rb.template.ts +21 -0
  269. package/src/lib/generate-ruby-sdk/templates/base_resource.rb.template.ts +58 -0
  270. package/src/lib/generate-ruby-sdk/templates/client.rb.template.ts +73 -0
  271. package/src/lib/generate-ruby-sdk/templates/gemfile.template.ts +6 -0
  272. package/src/lib/generate-ruby-sdk/templates/logger.rb.template.ts +12 -0
  273. package/src/lib/generate-ruby-sdk/templates/rakefile.template.ts +22 -0
  274. package/src/lib/generate-ruby-sdk/templates/readme.md.template.ts +183 -0
  275. package/src/lib/generate-ruby-sdk/templates/request.rb.template.ts +70 -0
  276. package/src/lib/generate-ruby-sdk/templates/resource_error.rb.template.ts +7 -0
  277. package/src/lib/generate-ruby-sdk/templates/resource_errors_support.rb.template.ts +9 -0
  278. package/src/lib/generate-ruby-sdk/templates/resource_warning.rb.template.ts +7 -0
  279. package/src/lib/generate-ruby-sdk/templates/resource_warnings_support.rb.template.ts +9 -0
  280. package/src/lib/generate-ruby-sdk/templates/seamapi.gemspec.template.ts +40 -0
  281. package/src/lib/generate-ruby-sdk/templates/snippets/resource.rb.template.ts +24 -0
  282. package/src/lib/generate-ruby-sdk/templates/version.rb.template.ts +5 -0
  283. package/src/lib/index.ts +2 -0
  284. package/src/lib/openapi/flatten-obj-schema.ts +124 -0
  285. package/src/lib/openapi/get-parameter-and-response-schema.ts +59 -0
  286. package/src/lib/openapi/index.ts +2 -0
  287. package/src/lib/types.ts +96 -0
@@ -0,0 +1,1070 @@
1
+ /*
2
+ * Seam Connect
3
+ *
4
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+ *
6
+ * The version of the OpenAPI document: 1.0.0
7
+ * Generated by: https://github.com/openapitools/openapi-generator.git
8
+ */
9
+
10
+
11
+ using System;
12
+ using System.Collections;
13
+ using System.Collections.Generic;
14
+ using System.Globalization;
15
+ using System.IO;
16
+ using System.Linq;
17
+ using System.Net;
18
+ using System.Reflection;
19
+ using System.Runtime.Serialization;
20
+ using System.Runtime.Serialization.Formatters;
21
+ using System.Text;
22
+ using System.Threading;
23
+ using System.Text.RegularExpressions;
24
+ using System.Threading.Tasks;
25
+ using System.Web;
26
+ using Newtonsoft.Json;
27
+ using Newtonsoft.Json.Serialization;
28
+ using RestSharp;
29
+ using RestSharp.Serializers;
30
+ using RestSharpMethod = RestSharp.Method;
31
+ using Polly;
32
+ using Seam.Model;
33
+
34
+ namespace Seam.Client
35
+ {
36
+ /// <summary>
37
+ /// Allows RestSharp to Serialize/Deserialize JSON using our custom logic, but only when ContentType is JSON.
38
+ /// </summary>
39
+ internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer
40
+ {
41
+ private readonly IReadableSeamRequestConfiguration _configuration;
42
+ private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
43
+ {
44
+ // OpenAPI generated types generally hide default constructors.
45
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
46
+ ContractResolver = new DefaultContractResolver
47
+ {
48
+ NamingStrategy = new CamelCaseNamingStrategy { OverrideSpecifiedNames = false }
49
+ }
50
+ };
51
+
52
+ public CustomJsonCodec(IReadableSeamRequestConfiguration configuration)
53
+ {
54
+ _configuration = configuration;
55
+ }
56
+
57
+ public CustomJsonCodec(
58
+ JsonSerializerSettings serializerSettings,
59
+ IReadableSeamRequestConfiguration configuration
60
+ )
61
+ {
62
+ _serializerSettings = serializerSettings;
63
+ _configuration = configuration;
64
+ }
65
+
66
+ /// <summary>
67
+ /// Serialize the object into a JSON string.
68
+ /// </summary>
69
+ /// <param name="obj">Object to be serialized.</param>
70
+ /// <returns>A JSON string.</returns>
71
+ public string Serialize(object obj)
72
+ {
73
+ return JsonConvert.SerializeObject(obj, _serializerSettings);
74
+ }
75
+
76
+ public string Serialize(Parameter bodyParameter) => Serialize(bodyParameter.Value);
77
+
78
+ public T Deserialize<T>(RestResponse response)
79
+ {
80
+ var result = (T)Deserialize(response, typeof(T));
81
+ return result;
82
+ }
83
+
84
+ /// <summary>
85
+ /// Deserialize the JSON string into a proper object.
86
+ /// </summary>
87
+ /// <param name="response">The HTTP response.</param>
88
+ /// <param name="type">Object type.</param>
89
+ /// <returns>Object representation of the JSON string.</returns>
90
+ internal object Deserialize(RestResponse response, Type type)
91
+ {
92
+ if (type == typeof(byte[])) // return byte array
93
+ {
94
+ return response.RawBytes;
95
+ }
96
+
97
+ // TODO: ? if (type.IsAssignableFrom(typeof(Stream)))
98
+ if (type == typeof(Stream))
99
+ {
100
+ var bytes = response.RawBytes;
101
+ if (response.Headers != null)
102
+ {
103
+ var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
104
+ ? Path.GetTempPath()
105
+ : _configuration.TempFolderPath;
106
+ var regex = new Regex(
107
+ @"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$"
108
+ );
109
+ foreach (var header in response.Headers)
110
+ {
111
+ var match = regex.Match(header.ToString());
112
+ if (match.Success)
113
+ {
114
+ string fileName =
115
+ filePath
116
+ + ClientUtils.SanitizeFilename(
117
+ match.Groups[1].Value.Replace("\"", "").Replace("'", "")
118
+ );
119
+ File.WriteAllBytes(fileName, bytes);
120
+ return new FileStream(fileName, FileMode.Open);
121
+ }
122
+ }
123
+ }
124
+ var stream = new MemoryStream(bytes);
125
+ return stream;
126
+ }
127
+
128
+ if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
129
+ {
130
+ return DateTime.Parse(
131
+ response.Content,
132
+ null,
133
+ System.Globalization.DateTimeStyles.RoundtripKind
134
+ );
135
+ }
136
+
137
+ if (type == typeof(string) || type.Name.StartsWith("System.Nullable")) // return primitive type
138
+ {
139
+ return Convert.ChangeType(response.Content, type);
140
+ }
141
+
142
+ // at this point, it must be a model (json)
143
+ try
144
+ {
145
+ return JsonConvert.DeserializeObject(response.Content, type, _serializerSettings);
146
+ }
147
+ catch (Exception e)
148
+ {
149
+ throw new SeamException(500, e.Message, response.Content);
150
+ }
151
+ }
152
+
153
+ public ISerializer Serializer => this;
154
+ public IDeserializer Deserializer => this;
155
+
156
+ public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept;
157
+
158
+ public SupportsContentType SupportsContentType =>
159
+ contentType =>
160
+ contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase)
161
+ || contentType.Value.EndsWith(
162
+ "javascript",
163
+ StringComparison.InvariantCultureIgnoreCase
164
+ );
165
+
166
+ public ContentType ContentType { get; set; } = RestSharp.ContentType.Json;
167
+
168
+ public DataFormat DataFormat => DataFormat.Json;
169
+ }
170
+
171
+ public partial interface ISeamClient : ISynchronousSeam, IAsynchronousSeam, IDisposable { }
172
+
173
+ /// <summary>
174
+ /// Provides a default implementation of an Api client (both synchronous and asynchronous implementations),
175
+ /// encapsulating general REST accessor use cases.
176
+ /// </summary>
177
+ public partial class SeamClient : ISeamClient
178
+ {
179
+ private readonly string _baseUrl;
180
+ private readonly string _apiToken;
181
+
182
+ /// <summary>
183
+ /// Specifies the settings on a <see cref="JsonSerializer" /> object.
184
+ /// These settings can be adjusted to accommodate custom serialization rules.
185
+ /// </summary>
186
+ public JsonSerializerSettings SerializerSettings { get; set; } =
187
+ new JsonSerializerSettings
188
+ {
189
+ // OpenAPI generated types generally hide default constructors.
190
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
191
+ ContractResolver = new DefaultContractResolver
192
+ {
193
+ NamingStrategy = new CamelCaseNamingStrategy { OverrideSpecifiedNames = false }
194
+ }
195
+ };
196
+
197
+ /// <summary>
198
+ /// Allows for extending request processing for <see cref="ApiClient"/> generated code.
199
+ /// </summary>
200
+ /// <param name="request">The RestSharp request object</param>
201
+ partial void InterceptRequest(RestRequest request);
202
+
203
+ /// <summary>
204
+ /// Allows for extending response processing for <see cref="ApiClient"/> generated code.
205
+ /// </summary>
206
+ /// <param name="request">The RestSharp request object</param>
207
+ /// <param name="response">The RestSharp response object</param>
208
+ partial void InterceptResponse(RestRequest request, RestResponse response);
209
+
210
+ /// <summary>
211
+ /// Initializes a new instance of the <see cref="ApiClient" />
212
+ /// </summary>
213
+ /// <param name="basePath">The target service's base path in URL format.</param>
214
+ /// <param name="apiToken">The target service's API Token.</param>
215
+ /// <exception cref="ArgumentException"></exception>
216
+ public SeamClient(string apiToken)
217
+ : this(GlobalSeamRequestConfiguration.Instance.BasePath, apiToken) { }
218
+
219
+ /// <summary>
220
+ /// Initializes a new instance of the <see cref="ApiClient" />
221
+ /// </summary>
222
+ /// <param name="basePath">The target service's base path in URL format.</param>
223
+ /// <param name="apiToken">The target service's API Token.</param>
224
+ /// <exception cref="ArgumentException"></exception>
225
+ public SeamClient(string basePath, string apiToken)
226
+ {
227
+ if (string.IsNullOrEmpty(basePath))
228
+ throw new ArgumentException("basePath cannot be empty");
229
+
230
+ if (string.IsNullOrEmpty(apiToken))
231
+ throw new ArgumentException("apiToken cannot be empty");
232
+
233
+ _baseUrl = basePath;
234
+ _apiToken = apiToken;
235
+ }
236
+
237
+ /// <summary>
238
+ /// Constructs the RestSharp version of an http method
239
+ /// </summary>
240
+ /// <param name="method">Swagger Client Custom HttpMethod</param>
241
+ /// <returns>RestSharp's HttpMethod instance.</returns>
242
+ /// <exception cref="ArgumentOutOfRangeException"></exception>
243
+ private RestSharpMethod Method(HttpMethod method)
244
+ {
245
+ RestSharpMethod other;
246
+ switch (method)
247
+ {
248
+ case HttpMethod.Get:
249
+ other = RestSharpMethod.Get;
250
+ break;
251
+ case HttpMethod.Post:
252
+ other = RestSharpMethod.Post;
253
+ break;
254
+ case HttpMethod.Put:
255
+ other = RestSharpMethod.Put;
256
+ break;
257
+ case HttpMethod.Delete:
258
+ other = RestSharpMethod.Delete;
259
+ break;
260
+ case HttpMethod.Head:
261
+ other = RestSharpMethod.Head;
262
+ break;
263
+ case HttpMethod.Options:
264
+ other = RestSharpMethod.Options;
265
+ break;
266
+ case HttpMethod.Patch:
267
+ other = RestSharpMethod.Patch;
268
+ break;
269
+ default:
270
+ throw new ArgumentOutOfRangeException("method", method, null);
271
+ }
272
+
273
+ return other;
274
+ }
275
+
276
+ /// <summary>
277
+ /// Provides all logic for constructing a new RestSharp <see cref="RestRequest"/>.
278
+ /// At this point, all information for querying the service is known. Here, it is simply
279
+ /// mapped into the RestSharp request.
280
+ /// </summary>
281
+ /// <param name="method">The http verb.</param>
282
+ /// <param name="path">The target path (or resource).</param>
283
+ /// <param name="options">The additional request options.</param>
284
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
285
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
286
+ /// <returns>[private] A new RestRequest instance.</returns>
287
+ /// <exception cref="ArgumentNullException"></exception>
288
+ private RestRequest NewRequest(
289
+ HttpMethod method,
290
+ string path,
291
+ RequestOptions options,
292
+ IReadableSeamRequestConfiguration configuration = null,
293
+ string apiToken = null
294
+ )
295
+ {
296
+ if (path == null)
297
+ throw new ArgumentNullException("path");
298
+ if (options == null)
299
+ throw new ArgumentNullException("options");
300
+ if (configuration == null)
301
+ throw new ArgumentNullException("configuration");
302
+
303
+ apiToken ??= _apiToken;
304
+
305
+ RestRequest request = new RestRequest(path, Method(method));
306
+
307
+ if (options.PathParameters != null)
308
+ {
309
+ foreach (var pathParam in options.PathParameters)
310
+ {
311
+ request.AddParameter(pathParam.Key, pathParam.Value, ParameterType.UrlSegment);
312
+ }
313
+ }
314
+
315
+ if (options.QueryParameters != null)
316
+ {
317
+ foreach (var queryParam in options.QueryParameters)
318
+ {
319
+ foreach (var value in queryParam.Value)
320
+ {
321
+ request.AddQueryParameter(queryParam.Key, value);
322
+ }
323
+ }
324
+ }
325
+
326
+ if (configuration.DefaultHeaders != null)
327
+ {
328
+ foreach (var headerParam in configuration.DefaultHeaders)
329
+ {
330
+ request.AddHeader(headerParam.Key, headerParam.Value);
331
+ }
332
+ }
333
+
334
+ if (apiToken != null)
335
+ {
336
+ request.AddHeader("Authorization", "Bearer " + apiToken);
337
+ }
338
+
339
+ if (options.HeaderParameters != null)
340
+ {
341
+ foreach (var headerParam in options.HeaderParameters)
342
+ {
343
+ foreach (var value in headerParam.Value)
344
+ {
345
+ request.AddHeader(headerParam.Key, value);
346
+ }
347
+ }
348
+ }
349
+
350
+ if (options.FormParameters != null)
351
+ {
352
+ foreach (var formParam in options.FormParameters)
353
+ {
354
+ request.AddParameter(formParam.Key, formParam.Value);
355
+ }
356
+ }
357
+
358
+ if (options.Data != null)
359
+ {
360
+ if (options.Data is Stream stream)
361
+ {
362
+ var contentType = "application/octet-stream";
363
+ if (options.HeaderParameters != null)
364
+ {
365
+ var contentTypes = options.HeaderParameters["Content-Type"];
366
+ contentType = contentTypes[0];
367
+ }
368
+
369
+ var bytes = ClientUtils.ReadAsBytes(stream);
370
+ request.AddParameter(contentType, bytes, ParameterType.RequestBody);
371
+ }
372
+ else
373
+ {
374
+ if (options.HeaderParameters != null)
375
+ {
376
+ IList<string> contentTypes = null;
377
+
378
+ if (options.HeaderParameters.ContainsKey("Content-Type"))
379
+ {
380
+ contentTypes = options.HeaderParameters["Content-Type"];
381
+ }
382
+
383
+ if (
384
+ contentTypes == null
385
+ || contentTypes.Any(header => header.Contains("application/json"))
386
+ )
387
+ {
388
+ request.RequestFormat = DataFormat.Json;
389
+ }
390
+ else
391
+ {
392
+ // TODO: Generated client user should add additional handlers. RestSharp only supports XML and JSON, with XML as default.
393
+ }
394
+ }
395
+ else
396
+ {
397
+ // Here, we'll assume JSON APIs are more common. XML can be forced by adding produces/consumes to openapi spec explicitly.
398
+ request.RequestFormat = DataFormat.Json;
399
+ }
400
+
401
+ request.AddJsonBody(options.Data);
402
+ }
403
+ }
404
+
405
+ if (options.FileParameters != null)
406
+ {
407
+ foreach (var fileParam in options.FileParameters)
408
+ {
409
+ foreach (var file in fileParam.Value)
410
+ {
411
+ var bytes = ClientUtils.ReadAsBytes(file);
412
+ var fileStream = file as FileStream;
413
+ if (fileStream != null)
414
+ request.AddFile(
415
+ fileParam.Key,
416
+ bytes,
417
+ System.IO.Path.GetFileName(fileStream.Name)
418
+ );
419
+ else
420
+ request.AddFile(fileParam.Key, bytes, "no_file_name_provided");
421
+ }
422
+ }
423
+ }
424
+
425
+ return request;
426
+ }
427
+
428
+ private ApiResponse<T> ToApiResponse<T>(RestResponse<T> response)
429
+ {
430
+ T result = response.Data;
431
+ string rawContent = response.Content;
432
+
433
+ var transformed = new ApiResponse<T>(
434
+ response.StatusCode,
435
+ new Multimap<string, string>(),
436
+ result,
437
+ rawContent
438
+ )
439
+ {
440
+ ErrorText = response.ErrorMessage,
441
+ Cookies = new List<Cookie>()
442
+ };
443
+
444
+ if (response.Headers != null)
445
+ {
446
+ foreach (var responseHeader in response.Headers)
447
+ {
448
+ transformed.Headers.Add(
449
+ responseHeader.Name,
450
+ ClientUtils.ParameterToString(responseHeader.Value)
451
+ );
452
+ }
453
+ }
454
+
455
+ if (response.ContentHeaders != null)
456
+ {
457
+ foreach (var responseHeader in response.ContentHeaders)
458
+ {
459
+ transformed.Headers.Add(
460
+ responseHeader.Name,
461
+ ClientUtils.ParameterToString(responseHeader.Value)
462
+ );
463
+ }
464
+ }
465
+
466
+ if (response.Cookies != null)
467
+ {
468
+ foreach (var responseCookies in response.Cookies.Cast<Cookie>())
469
+ {
470
+ transformed.Cookies.Add(
471
+ new Cookie(
472
+ responseCookies.Name,
473
+ responseCookies.Value,
474
+ responseCookies.Path,
475
+ responseCookies.Domain
476
+ )
477
+ );
478
+ }
479
+ }
480
+
481
+ return transformed;
482
+ }
483
+
484
+ private ApiResponse<T> Exec<T>(
485
+ RestRequest request,
486
+ RequestOptions options,
487
+ IReadableSeamRequestConfiguration configuration
488
+ )
489
+ {
490
+ var baseUrl = _baseUrl;
491
+
492
+ var cookies = new CookieContainer();
493
+
494
+ if (options.Cookies != null && options.Cookies.Count > 0)
495
+ {
496
+ foreach (var cookie in options.Cookies)
497
+ {
498
+ cookies.Add(new Cookie(cookie.Name, cookie.Value));
499
+ }
500
+ }
501
+
502
+ var clientOptions = new RestClientOptions(baseUrl)
503
+ {
504
+ ClientCertificates = configuration.ClientCertificates,
505
+ CookieContainer = cookies,
506
+ MaxTimeout = configuration.Timeout,
507
+ Proxy = configuration.Proxy,
508
+ UserAgent = configuration.UserAgent,
509
+ // UseDefaultCredentials = configuration.UseDefaultCredentials,
510
+ RemoteCertificateValidationCallback =
511
+ configuration.RemoteCertificateValidationCallback,
512
+ ThrowOnAnyError = false
513
+ };
514
+
515
+ using (
516
+ RestClient client = new RestClient(
517
+ clientOptions,
518
+ configureSerialization: serializerConfig =>
519
+ serializerConfig.UseSerializer(
520
+ () => new CustomJsonCodec(SerializerSettings, configuration)
521
+ )
522
+ )
523
+ )
524
+ {
525
+ InterceptRequest(request);
526
+
527
+ RestResponse<T> response;
528
+ if (RetryConfiguration.RetryPolicy != null)
529
+ {
530
+ var policy = RetryConfiguration.RetryPolicy;
531
+ var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
532
+ response =
533
+ (policyResult.Outcome == OutcomeType.Successful)
534
+ ? client.Deserialize<T>(policyResult.Result)
535
+ : new RestResponse<T>(request)
536
+ {
537
+ ErrorException = policyResult.FinalException
538
+ };
539
+ }
540
+ else
541
+ {
542
+ response = client.Execute<T>(request);
543
+ }
544
+
545
+ // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
546
+ if (typeof(AbstractModelSchema).IsAssignableFrom(typeof(T)))
547
+ {
548
+ try
549
+ {
550
+ response.Data = (T)
551
+ typeof(T)
552
+ .GetMethod("FromJson")
553
+ .Invoke(null, new object[] { response.Content });
554
+ }
555
+ catch (Exception ex)
556
+ {
557
+ throw ex.InnerException != null ? ex.InnerException : ex;
558
+ }
559
+ }
560
+ else if (typeof(T).Name == "Stream") // for binary response
561
+ {
562
+ response.Data = (T)(object)new MemoryStream(response.RawBytes);
563
+ }
564
+ else if (typeof(T).Name == "Byte[]") // for byte response
565
+ {
566
+ response.Data = (T)(object)response.RawBytes;
567
+ }
568
+ else if (typeof(T).Name == "String") // for string response
569
+ {
570
+ response.Data = (T)(object)response.Content;
571
+ }
572
+
573
+ InterceptResponse(request, response);
574
+
575
+ var result = ToApiResponse(response);
576
+ if (response.ErrorMessage != null)
577
+ {
578
+ result.ErrorText = response.ErrorMessage;
579
+ }
580
+
581
+ if (response.Cookies != null && response.Cookies.Count > 0)
582
+ {
583
+ if (result.Cookies == null)
584
+ result.Cookies = new List<Cookie>();
585
+ foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
586
+ {
587
+ var cookie = new Cookie(
588
+ restResponseCookie.Name,
589
+ restResponseCookie.Value,
590
+ restResponseCookie.Path,
591
+ restResponseCookie.Domain
592
+ )
593
+ {
594
+ Comment = restResponseCookie.Comment,
595
+ CommentUri = restResponseCookie.CommentUri,
596
+ Discard = restResponseCookie.Discard,
597
+ Expired = restResponseCookie.Expired,
598
+ Expires = restResponseCookie.Expires,
599
+ HttpOnly = restResponseCookie.HttpOnly,
600
+ Port = restResponseCookie.Port,
601
+ Secure = restResponseCookie.Secure,
602
+ Version = restResponseCookie.Version
603
+ };
604
+
605
+ result.Cookies.Add(cookie);
606
+ }
607
+ }
608
+
609
+ var exceptionFactory = SeamRequestConfiguration.DefaultExceptionFactory;
610
+ if (exceptionFactory != null)
611
+ {
612
+ var exception = exceptionFactory(request.Resource, result);
613
+ if (exception != null)
614
+ {
615
+ throw exception;
616
+ }
617
+ }
618
+
619
+ return result;
620
+ }
621
+ }
622
+
623
+ private async Task<ApiResponse<T>> ExecAsync<T>(
624
+ RestRequest request,
625
+ RequestOptions options,
626
+ IReadableSeamRequestConfiguration configuration,
627
+ System.Threading.CancellationToken cancellationToken =
628
+ default(System.Threading.CancellationToken)
629
+ )
630
+ {
631
+ var baseUrl = _baseUrl;
632
+
633
+ var clientOptions = new RestClientOptions(baseUrl)
634
+ {
635
+ ClientCertificates = configuration.ClientCertificates,
636
+ MaxTimeout = configuration.Timeout,
637
+ Proxy = configuration.Proxy,
638
+ UserAgent = configuration.UserAgent,
639
+ ThrowOnAnyError = false
640
+ };
641
+
642
+ using (
643
+ RestClient client = new RestClient(
644
+ clientOptions,
645
+ configureSerialization: serializerConfig =>
646
+ serializerConfig.UseSerializer(
647
+ () => new CustomJsonCodec(SerializerSettings, configuration)
648
+ )
649
+ )
650
+ )
651
+ {
652
+ InterceptRequest(request);
653
+
654
+ RestResponse<T> response;
655
+ if (RetryConfiguration.AsyncRetryPolicy != null)
656
+ {
657
+ var policy = RetryConfiguration.AsyncRetryPolicy;
658
+ var policyResult = await policy
659
+ .ExecuteAndCaptureAsync(
660
+ (ct) => client.ExecuteAsync(request, ct),
661
+ cancellationToken
662
+ )
663
+ .ConfigureAwait(false);
664
+ response =
665
+ (policyResult.Outcome == OutcomeType.Successful)
666
+ ? client.Deserialize<T>(policyResult.Result)
667
+ : new RestResponse<T>(request)
668
+ {
669
+ ErrorException = policyResult.FinalException
670
+ };
671
+ }
672
+ else
673
+ {
674
+ response = await client
675
+ .ExecuteAsync<T>(request, cancellationToken)
676
+ .ConfigureAwait(false);
677
+ }
678
+
679
+ // if the response type is oneOf/anyOf, call FromJSON to deserialize the data
680
+ if (typeof(AbstractModelSchema).IsAssignableFrom(typeof(T)))
681
+ {
682
+ response.Data = (T)
683
+ typeof(T)
684
+ .GetMethod("FromJson")
685
+ .Invoke(null, new object[] { response.Content });
686
+ }
687
+ else if (typeof(T).Name == "Stream") // for binary response
688
+ {
689
+ response.Data = (T)(object)new MemoryStream(response.RawBytes);
690
+ }
691
+ else if (typeof(T).Name == "Byte[]") // for byte response
692
+ {
693
+ response.Data = (T)(object)response.RawBytes;
694
+ }
695
+
696
+ InterceptResponse(request, response);
697
+
698
+ var result = ToApiResponse(response);
699
+ if (response.ErrorMessage != null)
700
+ {
701
+ result.ErrorText = response.ErrorMessage;
702
+ }
703
+
704
+ if (response.Cookies != null && response.Cookies.Count > 0)
705
+ {
706
+ if (result.Cookies == null)
707
+ result.Cookies = new List<Cookie>();
708
+ foreach (var restResponseCookie in response.Cookies.Cast<Cookie>())
709
+ {
710
+ var cookie = new Cookie(
711
+ restResponseCookie.Name,
712
+ restResponseCookie.Value,
713
+ restResponseCookie.Path,
714
+ restResponseCookie.Domain
715
+ )
716
+ {
717
+ Comment = restResponseCookie.Comment,
718
+ CommentUri = restResponseCookie.CommentUri,
719
+ Discard = restResponseCookie.Discard,
720
+ Expired = restResponseCookie.Expired,
721
+ Expires = restResponseCookie.Expires,
722
+ HttpOnly = restResponseCookie.HttpOnly,
723
+ Port = restResponseCookie.Port,
724
+ Secure = restResponseCookie.Secure,
725
+ Version = restResponseCookie.Version
726
+ };
727
+
728
+ result.Cookies.Add(cookie);
729
+ }
730
+ }
731
+
732
+ var exceptionFactory = SeamRequestConfiguration.DefaultExceptionFactory;
733
+ if (exceptionFactory != null)
734
+ {
735
+ var exception = exceptionFactory(request.Resource, result);
736
+ if (exception != null)
737
+ {
738
+ throw exception;
739
+ }
740
+ }
741
+
742
+ return result;
743
+ }
744
+ }
745
+
746
+ #region IAsynchronousClient
747
+ /// <summary>
748
+ /// Make a HTTP GET request (async).
749
+ /// </summary>
750
+ /// <param name="path">The target path (or resource).</param>
751
+ /// <param name="options">The additional request options.</param>
752
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
753
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
754
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
755
+ /// <returns>A Task containing ApiResponse</returns>
756
+ public Task<ApiResponse<T>> GetAsync<T>(
757
+ string path,
758
+ RequestOptions options,
759
+ IReadableSeamRequestConfiguration configuration = null,
760
+ System.Threading.CancellationToken cancellationToken =
761
+ default(System.Threading.CancellationToken)
762
+ )
763
+ {
764
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
765
+ return ExecAsync<T>(
766
+ NewRequest(HttpMethod.Get, path, options, config),
767
+ options,
768
+ config,
769
+ cancellationToken
770
+ );
771
+ }
772
+
773
+ /// <summary>
774
+ /// Make a HTTP POST request (async).
775
+ /// </summary>
776
+ /// <param name="path">The target path (or resource).</param>
777
+ /// <param name="options">The additional request options.</param>
778
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
779
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
780
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
781
+ /// <returns>A Task containing ApiResponse</returns>
782
+ public Task<ApiResponse<T>> PostAsync<T>(
783
+ string path,
784
+ RequestOptions options,
785
+ IReadableSeamRequestConfiguration configuration = null,
786
+ System.Threading.CancellationToken cancellationToken =
787
+ default(System.Threading.CancellationToken)
788
+ )
789
+ {
790
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
791
+ return ExecAsync<T>(
792
+ NewRequest(HttpMethod.Post, path, options, config),
793
+ options,
794
+ config,
795
+ cancellationToken
796
+ );
797
+ }
798
+
799
+ /// <summary>
800
+ /// Make a HTTP PUT request (async).
801
+ /// </summary>
802
+ /// <param name="path">The target path (or resource).</param>
803
+ /// <param name="options">The additional request options.</param>
804
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
805
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
806
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
807
+ /// <returns>A Task containing ApiResponse</returns>
808
+ public Task<ApiResponse<T>> PutAsync<T>(
809
+ string path,
810
+ RequestOptions options,
811
+ IReadableSeamRequestConfiguration configuration = null,
812
+ System.Threading.CancellationToken cancellationToken =
813
+ default(System.Threading.CancellationToken)
814
+ )
815
+ {
816
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
817
+ return ExecAsync<T>(
818
+ NewRequest(HttpMethod.Put, path, options, config),
819
+ options,
820
+ config,
821
+ cancellationToken
822
+ );
823
+ }
824
+
825
+ /// <summary>
826
+ /// Make a HTTP DELETE request (async).
827
+ /// </summary>
828
+ /// <param name="path">The target path (or resource).</param>
829
+ /// <param name="options">The additional request options.</param>
830
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
831
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
832
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
833
+ /// <returns>A Task containing ApiResponse</returns>
834
+ public Task<ApiResponse<T>> DeleteAsync<T>(
835
+ string path,
836
+ RequestOptions options,
837
+ IReadableSeamRequestConfiguration configuration = null,
838
+ System.Threading.CancellationToken cancellationToken =
839
+ default(System.Threading.CancellationToken)
840
+ )
841
+ {
842
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
843
+ return ExecAsync<T>(
844
+ NewRequest(HttpMethod.Delete, path, options, config),
845
+ options,
846
+ config,
847
+ cancellationToken
848
+ );
849
+ }
850
+
851
+ /// <summary>
852
+ /// Make a HTTP HEAD request (async).
853
+ /// </summary>
854
+ /// <param name="path">The target path (or resource).</param>
855
+ /// <param name="options">The additional request options.</param>
856
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
857
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
858
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
859
+ /// <returns>A Task containing ApiResponse</returns>
860
+ public Task<ApiResponse<T>> HeadAsync<T>(
861
+ string path,
862
+ RequestOptions options,
863
+ IReadableSeamRequestConfiguration configuration = null,
864
+ System.Threading.CancellationToken cancellationToken =
865
+ default(System.Threading.CancellationToken)
866
+ )
867
+ {
868
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
869
+ return ExecAsync<T>(
870
+ NewRequest(HttpMethod.Head, path, options, config),
871
+ options,
872
+ config,
873
+ cancellationToken
874
+ );
875
+ }
876
+
877
+ /// <summary>
878
+ /// Make a HTTP OPTION request (async).
879
+ /// </summary>
880
+ /// <param name="path">The target path (or resource).</param>
881
+ /// <param name="options">The additional request options.</param>
882
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
883
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
884
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
885
+ /// <returns>A Task containing ApiResponse</returns>
886
+ public Task<ApiResponse<T>> OptionsAsync<T>(
887
+ string path,
888
+ RequestOptions options,
889
+ IReadableSeamRequestConfiguration configuration = null,
890
+ System.Threading.CancellationToken cancellationToken =
891
+ default(System.Threading.CancellationToken)
892
+ )
893
+ {
894
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
895
+ return ExecAsync<T>(
896
+ NewRequest(HttpMethod.Options, path, options, config),
897
+ options,
898
+ config,
899
+ cancellationToken
900
+ );
901
+ }
902
+
903
+ /// <summary>
904
+ /// Make a HTTP PATCH request (async).
905
+ /// </summary>
906
+ /// <param name="path">The target path (or resource).</param>
907
+ /// <param name="options">The additional request options.</param>
908
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
909
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
910
+ /// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
911
+ /// <returns>A Task containing ApiResponse</returns>
912
+ public Task<ApiResponse<T>> PatchAsync<T>(
913
+ string path,
914
+ RequestOptions options,
915
+ IReadableSeamRequestConfiguration configuration = null,
916
+ System.Threading.CancellationToken cancellationToken =
917
+ default(System.Threading.CancellationToken)
918
+ )
919
+ {
920
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
921
+ return ExecAsync<T>(
922
+ NewRequest(HttpMethod.Patch, path, options, config),
923
+ options,
924
+ config,
925
+ cancellationToken
926
+ );
927
+ }
928
+ #endregion IAsynchronousClient
929
+
930
+ #region ISynchronousClient
931
+ /// <summary>
932
+ /// Make a HTTP GET request (synchronous).
933
+ /// </summary>
934
+ /// <param name="path">The target path (or resource).</param>
935
+ /// <param name="options">The additional request options.</param>
936
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
937
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
938
+ /// <returns>A Task containing ApiResponse</returns>
939
+ public ApiResponse<T> Get<T>(
940
+ string path,
941
+ RequestOptions options,
942
+ IReadableSeamRequestConfiguration configuration = null
943
+ )
944
+ {
945
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
946
+ return Exec<T>(NewRequest(HttpMethod.Get, path, options, config), options, config);
947
+ }
948
+
949
+ /// <summary>
950
+ /// Make a HTTP POST request (synchronous).
951
+ /// </summary>
952
+ /// <param name="path">The target path (or resource).</param>
953
+ /// <param name="options">The additional request options.</param>
954
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
955
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
956
+ /// <returns>A Task containing ApiResponse</returns>
957
+ public ApiResponse<T> Post<T>(
958
+ string path,
959
+ RequestOptions options,
960
+ IReadableSeamRequestConfiguration configuration = null
961
+ )
962
+ {
963
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
964
+ return Exec<T>(NewRequest(HttpMethod.Post, path, options, config), options, config);
965
+ }
966
+
967
+ /// <summary>
968
+ /// Make a HTTP PUT request (synchronous).
969
+ /// </summary>
970
+ /// <param name="path">The target path (or resource).</param>
971
+ /// <param name="options">The additional request options.</param>
972
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
973
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
974
+ /// <returns>A Task containing ApiResponse</returns>
975
+ public ApiResponse<T> Put<T>(
976
+ string path,
977
+ RequestOptions options,
978
+ IReadableSeamRequestConfiguration configuration = null
979
+ )
980
+ {
981
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
982
+ return Exec<T>(NewRequest(HttpMethod.Put, path, options, config), options, config);
983
+ }
984
+
985
+ /// <summary>
986
+ /// Make a HTTP DELETE request (synchronous).
987
+ /// </summary>
988
+ /// <param name="path">The target path (or resource).</param>
989
+ /// <param name="options">The additional request options.</param>
990
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
991
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
992
+ /// <returns>A Task containing ApiResponse</returns>
993
+ public ApiResponse<T> Delete<T>(
994
+ string path,
995
+ RequestOptions options,
996
+ IReadableSeamRequestConfiguration configuration = null
997
+ )
998
+ {
999
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
1000
+ return Exec<T>(NewRequest(HttpMethod.Delete, path, options, config), options, config);
1001
+ }
1002
+
1003
+ /// <summary>
1004
+ /// Make a HTTP HEAD request (synchronous).
1005
+ /// </summary>
1006
+ /// <param name="path">The target path (or resource).</param>
1007
+ /// <param name="options">The additional request options.</param>
1008
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
1009
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
1010
+ /// <returns>A Task containing ApiResponse</returns>
1011
+ public ApiResponse<T> Head<T>(
1012
+ string path,
1013
+ RequestOptions options,
1014
+ IReadableSeamRequestConfiguration configuration = null
1015
+ )
1016
+ {
1017
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
1018
+ return Exec<T>(NewRequest(HttpMethod.Head, path, options, config), options, config);
1019
+ }
1020
+
1021
+ /// <summary>
1022
+ /// Make a HTTP OPTION request (synchronous).
1023
+ /// </summary>
1024
+ /// <param name="path">The target path (or resource).</param>
1025
+ /// <param name="options">The additional request options.</param>
1026
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
1027
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
1028
+ /// <returns>A Task containing ApiResponse</returns>
1029
+ public ApiResponse<T> Options<T>(
1030
+ string path,
1031
+ RequestOptions options,
1032
+ IReadableSeamRequestConfiguration configuration = null
1033
+ )
1034
+ {
1035
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
1036
+ return Exec<T>(NewRequest(HttpMethod.Options, path, options, config), options, config);
1037
+ }
1038
+
1039
+ /// <summary>
1040
+ /// Make a HTTP PATCH request (synchronous).
1041
+ /// </summary>
1042
+ /// <param name="path">The target path (or resource).</param>
1043
+ /// <param name="options">The additional request options.</param>
1044
+ /// <param name="configuration">A per-request configuration object. It is assumed that any merge with
1045
+ /// GlobalSeamConfiguration has been done before calling this method.</param>
1046
+ /// <returns>A Task containing ApiResponse</returns>
1047
+ public ApiResponse<T> Patch<T>(
1048
+ string path,
1049
+ RequestOptions options,
1050
+ IReadableSeamRequestConfiguration configuration = null
1051
+ )
1052
+ {
1053
+ var config = configuration ?? GlobalSeamRequestConfiguration.Instance;
1054
+ return Exec<T>(NewRequest(HttpMethod.Patch, path, options, config), options, config);
1055
+ }
1056
+
1057
+ #endregion ISynchronousClient
1058
+ public void Dispose() { }
1059
+ }
1060
+
1061
+ [Obsolete("Please use Seam.Client.SeamClient instead")]
1062
+ public class Seam : SeamClient
1063
+ {
1064
+ public Seam(string apiToken)
1065
+ : base(apiToken) { }
1066
+
1067
+ public Seam(string basePath, string apiToken)
1068
+ : base(basePath, apiToken) { }
1069
+ }
1070
+ }