@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.34

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 (277) hide show
  1. package/LICENSE-THIRD-PARTY +75 -86
  2. package/generators.json +27 -0
  3. package/package.json +10 -10
  4. package/src/connection/generator.js +12 -1
  5. package/src/connection/generator.js.map +1 -1
  6. package/src/connection/supported-connections.d.ts +10 -1
  7. package/src/connection/supported-connections.js +13 -0
  8. package/src/connection/supported-connections.js.map +1 -1
  9. package/src/infra/app/__snapshots__/generator.spec.ts.snap +21 -21
  10. package/src/infra/app/files/app/src/main.ts.template +1 -1
  11. package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
  12. package/src/infra/app/generator.js +3 -1
  13. package/src/infra/app/generator.js.map +1 -1
  14. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +12 -12
  15. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +74 -10
  16. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +22 -4
  17. package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +53 -8
  18. package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +32 -4
  19. package/src/open-api/ts-client/__snapshots__/generator.fast-api-gaps.spec.ts.snap +736 -0
  20. package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +86 -11
  21. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +21 -3
  22. package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +2 -2
  23. package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +6 -6
  24. package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2 -2
  25. package/src/open-api/ts-client/__snapshots__/generator.spec-compliance.spec.ts.snap +1883 -0
  26. package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +4 -4
  27. package/src/open-api/ts-client/files/client.gen.ts.template +196 -13
  28. package/src/open-api/ts-client/files/types.gen.ts.template +2 -0
  29. package/src/open-api/ts-client/generator.js +27 -2
  30. package/src/open-api/ts-client/generator.js.map +1 -1
  31. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  32. package/src/open-api/ts-hooks/generator.js +5 -1
  33. package/src/open-api/ts-hooks/generator.js.map +1 -1
  34. package/src/open-api/utils/codegen-data/languages.js +6 -0
  35. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  36. package/src/open-api/utils/codegen-data/types.d.ts +16 -1
  37. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  38. package/src/open-api/utils/codegen-data.js +71 -0
  39. package/src/open-api/utils/codegen-data.js.map +1 -1
  40. package/src/open-api/utils/normalise.js +53 -8
  41. package/src/open-api/utils/normalise.js.map +1 -1
  42. package/src/open-api/utils/parser.js +48 -15
  43. package/src/open-api/utils/parser.js.map +1 -1
  44. package/src/preset/__snapshots__/generator.spec.ts.snap +5 -3
  45. package/src/preset/generator.d.ts +1 -1
  46. package/src/preset/generator.js +5 -2
  47. package/src/preset/generator.js.map +1 -1
  48. package/src/preset/schema.d.js.map +1 -1
  49. package/src/preset/schema.d.ts +2 -0
  50. package/src/preset/schema.json +6 -0
  51. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  52. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  53. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  54. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  55. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
  56. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  57. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  58. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +2038 -0
  59. package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +104 -0
  60. package/src/py/rdb/agent-connection/generator.d.ts +10 -0
  61. package/src/py/rdb/agent-connection/generator.js +46 -0
  62. package/src/py/rdb/agent-connection/generator.js.map +1 -0
  63. package/src/py/rdb/agent-connection/schema.d.js +8 -0
  64. package/src/py/rdb/agent-connection/schema.d.js.map +1 -0
  65. package/src/py/rdb/agent-connection/schema.d.ts +15 -0
  66. package/src/py/rdb/agent-connection/schema.json +27 -0
  67. package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +44 -0
  68. package/src/py/rdb/fast-api-connection/files/__apiModuleName__/dependencies/__rdbNameSnake__.py.template +14 -0
  69. package/src/py/rdb/fast-api-connection/generator.d.ts +10 -0
  70. package/src/py/rdb/fast-api-connection/generator.js +54 -0
  71. package/src/py/rdb/fast-api-connection/generator.js.map +1 -0
  72. package/src/py/rdb/fast-api-connection/schema.d.js +8 -0
  73. package/src/py/rdb/fast-api-connection/schema.d.js.map +1 -0
  74. package/src/py/rdb/fast-api-connection/schema.d.ts +13 -0
  75. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  76. package/src/py/rdb/files/Dockerfile.create-db-user.template +10 -0
  77. package/src/py/rdb/files/Dockerfile.migration.template +10 -0
  78. package/src/py/rdb/files/__name__/__init__.py.template +3 -0
  79. package/src/py/rdb/files/__name__/connection.py.template +55 -0
  80. package/src/py/rdb/files/__name__/create_db_user_handler.py.template +97 -0
  81. package/src/py/rdb/files/__name__/migration_handler.py.template +36 -0
  82. package/src/py/rdb/files/__name__/models/__init__.py.template +3 -0
  83. package/src/py/rdb/files/__name__/models/example.py.template +8 -0
  84. package/src/py/rdb/files/__name__/utils.py.template +104 -0
  85. package/src/py/rdb/files/alembic.ini.template +38 -0
  86. package/src/py/rdb/files/config.json.template +14 -0
  87. package/src/py/rdb/files/migrations/env.py.template +80 -0
  88. package/src/py/rdb/files/migrations/script.py.mako.template +28 -0
  89. package/src/py/rdb/generator.d.ts +6 -0
  90. package/src/py/rdb/generator.js +263 -0
  91. package/src/py/rdb/generator.js.map +1 -0
  92. package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +101 -0
  93. package/src/py/rdb/mcp-server-connection/generator.d.ts +10 -0
  94. package/src/py/rdb/mcp-server-connection/generator.js +46 -0
  95. package/src/py/rdb/mcp-server-connection/generator.js.map +1 -0
  96. package/src/py/rdb/mcp-server-connection/schema.d.js +8 -0
  97. package/src/py/rdb/mcp-server-connection/schema.d.js.map +1 -0
  98. package/src/py/rdb/mcp-server-connection/schema.d.ts +15 -0
  99. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  100. package/src/py/rdb/schema.d.js +6 -0
  101. package/src/py/rdb/schema.d.js.map +1 -0
  102. package/src/py/rdb/schema.d.ts +16 -0
  103. package/src/py/rdb/schema.json +77 -0
  104. package/src/py/rdb/utils.d.ts +6 -0
  105. package/src/py/rdb/utils.js +16 -0
  106. package/src/py/rdb/utils.js.map +1 -0
  107. package/src/sdk/py.d.ts +2 -0
  108. package/src/sdk/py.js +1 -0
  109. package/src/sdk/py.js.map +1 -1
  110. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
  111. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  112. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  113. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  114. package/src/smithy/ts/api/files/service.ts.template +3 -3
  115. package/src/smithy/ts/api/generator.js +3 -1
  116. package/src/smithy/ts/api/generator.js.map +1 -1
  117. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
  118. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  119. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  120. package/src/trpc/backend/files/src/index.ts.template +5 -5
  121. package/src/trpc/backend/files/src/init.ts.template +1 -1
  122. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  123. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  124. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  125. package/src/trpc/backend/files/src/router.ts.template +2 -2
  126. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  127. package/src/trpc/backend/generator.js +3 -1
  128. package/src/trpc/backend/generator.js.map +1 -1
  129. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  130. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  131. package/src/ts/agent/a2a-connection/generator.js +3 -1
  132. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  133. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  134. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  135. package/src/ts/agent/files/http/client.ts.template +2 -2
  136. package/src/ts/agent/files/http/index.ts.template +2 -2
  137. package/src/ts/agent/files/http/router.ts.template +3 -3
  138. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  139. package/src/ts/agent/gateway-connection/generator.js +3 -1
  140. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  141. package/src/ts/agent/generator.js +5 -2
  142. package/src/ts/agent/generator.js.map +1 -1
  143. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  144. package/src/ts/agent/mcp-connection/generator.js +3 -1
  145. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  146. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  147. package/src/ts/astro-docs/generator.js +2 -0
  148. package/src/ts/astro-docs/generator.js.map +1 -1
  149. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  150. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  151. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  152. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  153. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  154. package/src/ts/dynamodb/generator.js +3 -1
  155. package/src/ts/dynamodb/generator.js.map +1 -1
  156. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  157. package/src/ts/lib/generator.js +7 -1
  158. package/src/ts/lib/generator.js.map +1 -1
  159. package/src/ts/lib/ts-project-utils.js +19 -4
  160. package/src/ts/lib/ts-project-utils.js.map +1 -1
  161. package/src/ts/lib/types.d.ts +6 -0
  162. package/src/ts/lib/types.js.map +1 -1
  163. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
  164. package/src/ts/mcp-server/generator.js +3 -2
  165. package/src/ts/mcp-server/generator.js.map +1 -1
  166. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  167. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  168. package/src/ts/nx-generator/generator.js +5 -2
  169. package/src/ts/nx-generator/generator.js.map +1 -1
  170. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  171. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  172. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  173. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  174. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  175. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  176. package/src/ts/nx-plugin/generator.js +3 -1
  177. package/src/ts/nx-plugin/generator.js.map +1 -1
  178. package/src/ts/nx-plugin/utils.js +7 -4
  179. package/src/ts/nx-plugin/utils.js.map +1 -1
  180. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +149 -177
  181. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  182. package/src/ts/rdb/files/src/index.ts.template +1 -1
  183. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  184. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  185. package/src/ts/rdb/generator.js +7 -4
  186. package/src/ts/rdb/generator.js.map +1 -1
  187. package/src/ts/rdb/schema.json +1 -1
  188. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +45 -45
  189. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  190. package/src/utils/agent-chat/agent-chat.js +3 -1
  191. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  192. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  193. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  194. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  195. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  196. package/src/utils/agent-connection/agent-connection.js +4 -1
  197. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  198. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  199. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  200. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  201. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  202. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  203. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  204. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  205. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  206. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  207. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  208. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  209. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  210. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  211. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  212. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  213. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  214. package/src/utils/api-constructs/api-constructs.js +8 -2
  215. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  216. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  217. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  218. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  219. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  220. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  221. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  222. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  223. package/src/utils/ast.js +16 -0
  224. package/src/utils/ast.js.map +1 -1
  225. package/src/utils/commands.d.ts +1 -1
  226. package/src/utils/commands.js +4 -1
  227. package/src/utils/commands.js.map +1 -1
  228. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  229. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  230. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  231. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  232. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  233. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  234. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  235. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  236. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  237. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  238. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  239. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  240. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  241. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  242. package/src/utils/function-constructs/function-constructs.js +3 -1
  243. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  244. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  245. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  246. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  247. package/src/utils/module-format.d.ts +28 -0
  248. package/src/utils/module-format.js +28 -0
  249. package/src/utils/module-format.js.map +1 -0
  250. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +61 -17
  251. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +68 -78
  252. package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +88 -8
  253. package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +5 -32
  254. package/src/utils/rdb-constructs/rdb-constructs.d.ts +11 -1
  255. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  256. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  257. package/src/utils/shared-constructs.js +12 -22
  258. package/src/utils/shared-constructs.js.map +1 -1
  259. package/src/utils/shared-infra-config.js +3 -1
  260. package/src/utils/shared-infra-config.js.map +1 -1
  261. package/src/utils/shared-infra-scripts.js +3 -1
  262. package/src/utils/shared-infra-scripts.js.map +1 -1
  263. package/src/utils/shared-rdb-scripts.js +5 -1
  264. package/src/utils/shared-rdb-scripts.js.map +1 -1
  265. package/src/utils/shared-shadcn.js +3 -1
  266. package/src/utils/shared-shadcn.js.map +1 -1
  267. package/src/utils/test.d.ts +2 -0
  268. package/src/utils/test.js +7 -1
  269. package/src/utils/test.js.map +1 -1
  270. package/src/utils/versions.d.ts +73 -69
  271. package/src/utils/versions.js +71 -67
  272. package/src/utils/versions.js.map +1 -1
  273. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  274. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  275. package/src/utils/website-constructs/website-constructs.js +9 -2
  276. package/src/utils/website-constructs/website-constructs.js.map +1 -1
  277. package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +0 -25
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/utils/normalise.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport cloneDeepWith from 'lodash.clonedeepwith';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport {\n camelCase,\n pascalCase,\n toClassName,\n upperFirst,\n} from '../../utils/names';\nimport { STREAMING_CONTENT_TYPES } from './codegen-data/types';\nimport { isRef, resolveIfRef, resolveRef, splitRef } from './refs';\nimport type { Spec } from './types';\n\ninterface SubSchema {\n readonly nameParts: string[];\n readonly schema: OpenAPIV3.SchemaObject;\n readonly propPath: (string | number)[];\n}\n\ninterface SubSchemaRef {\n readonly $ref: string;\n readonly name: string;\n readonly schema: OpenAPIV3.SchemaObject;\n}\n\n/**\n * Normalise schema names to valid TypeScript identifiers.\n * Converts names with hyphens or other invalid characters to PascalCase.\n * Throws an error if normalisation would create a name clash.\n */\nconst normaliseSchemaNames = (spec: Spec): Spec => {\n const schemaNameMapping: { [oldName: string]: string } = {};\n const originalNames = Object.keys(spec.components?.schemas ?? {});\n const existingSchemaNames = new Set(originalNames);\n\n // The name each schema resolves to (its normalised form, or itself when it\n // needs no normalisation). Used to detect two distinct schemas that would\n // collapse onto the same identifier.\n const resolvedNameOwners: { [resolvedName: string]: string } = {};\n\n // Build mapping of old names to new names\n originalNames.forEach((name) => {\n const normalizedName = toClassName(name);\n if (normalizedName !== name) {\n // Check if the normalized name would clash with an existing schema\n if (existingSchemaNames.has(normalizedName)) {\n throw new Error(\n `Schema name normalization conflict: \"${name}\" would be normalized to \"${normalizedName}\", but a schema with that name already exists. Please rename one of these schemas in your OpenAPI specification.`,\n );\n }\n schemaNameMapping[name] = normalizedName;\n }\n\n // Detect two distinct schemas resolving to the same name (e.g. \"Foo-Bar\"\n // and \"Foo.Bar\" both normalise to \"FooBar\"), which would otherwise\n // silently overwrite one another.\n const owner = resolvedNameOwners[normalizedName];\n if (owner !== undefined) {\n throw new Error(\n `Schema name normalization conflict: \"${name}\" and \"${owner}\" both normalize to \"${normalizedName}\". Please rename one of these schemas in your OpenAPI specification.`,\n );\n }\n resolvedNameOwners[normalizedName] = name;\n });\n\n // If no normalization needed, return spec as-is\n if (Object.keys(schemaNameMapping).length === 0) {\n return spec;\n }\n\n // Update all $ref references throughout the spec\n spec = cloneDeepWith(spec, (v) => {\n if (isRef(v)) {\n const parts = splitRef(v.$ref);\n if (\n parts.length === 3 &&\n parts[0] === 'components' &&\n parts[1] === 'schemas'\n ) {\n const oldName = parts[2];\n const newName = schemaNameMapping[oldName];\n if (newName) {\n return { $ref: `#/components/schemas/${newName}` };\n }\n }\n }\n });\n\n // Rename schema keys, recording the original name so downstream code can\n // recover the on-the-wire value (e.g. an implicit discriminator matches on\n // the original schema name, not its normalised identifier).\n Object.entries(schemaNameMapping).forEach(([oldName, newName]) => {\n const schema = spec.components!.schemas![oldName];\n if (schema && !isRef(schema)) {\n (schema as { 'x-aws-nx-original-name'?: string })[\n 'x-aws-nx-original-name'\n ] = oldName;\n }\n spec.components!.schemas![newName] = schema;\n delete spec.components!.schemas![oldName];\n });\n\n return spec;\n};\n\nconst isCompositeSchema = (schema: OpenAPIV3.SchemaObject) =>\n !!schema.allOf || !!schema.anyOf || !!schema.oneOf;\n\n/**\n * The media type whose schema is hoisted for a request/response: prefer\n * `application/json`, falling back to any `+json` vendored type (e.g.\n * `application/problem+json`).\n */\nconst preferredJsonMediaType = (mediaTypes: string[]): string | undefined =>\n mediaTypes.find((mediaType) => mediaType === 'application/json') ??\n mediaTypes.find((mediaType) => mediaType.split(';')[0].endsWith('+json'));\n\nconst hasSubSchemasToVisit = (\n schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,\n): schema is OpenAPIV3.SchemaObject =>\n !!schema &&\n !isRef(schema) &&\n (['object', 'array'].includes(schema.type as any) ||\n isCompositeSchema(schema) ||\n !!schema.not ||\n (schema.type === 'string' && !!schema.enum));\n\nconst filterInlineCompositeSchemas = (\n schemas: (OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject)[],\n nameParts: string[],\n namePartPrefix: string,\n propPath: (string | number)[],\n): SubSchema[] => {\n let inlineSchemaIndex = 0;\n return schemas.flatMap((s, i) => {\n if (hasSubSchemasToVisit(s)) {\n const subSchema: SubSchema = {\n nameParts: s.title\n ? [pascalCase(s.title)]\n : [\n ...nameParts,\n `${namePartPrefix}${inlineSchemaIndex === 0 ? '' : inlineSchemaIndex}`,\n ],\n schema: s,\n propPath: [...propPath, i],\n };\n inlineSchemaIndex++;\n return [subSchema];\n }\n return [];\n });\n};\n\n/**\n * Returns a unique model/schema name for any models which we hoist\n */\nconst createUniqueModelName = (\n nameParts: string[],\n seenModelNameCounts: { [name: string]: number },\n): string => {\n // Normalise each part to a class-name form (stripping `_`, hyphens, etc) so\n // the hoisted schema name matches what `toTypeScriptModelName`/`toClassName`\n // later derive — otherwise a part like `store_photos` yields a `Store_photos`\n // schema whose reference (`StorePhotos`) no longer resolves.\n const candidateName = nameParts.map(toClassName).join('');\n\n const seenModelNameCount = seenModelNameCounts[candidateName];\n\n // We have not seen this name so we're free to use it\n if (seenModelNameCount === undefined) {\n seenModelNameCounts[candidateName] = 1;\n return candidateName;\n }\n\n // We have seen the name before, so we must disambiguate\n seenModelNameCounts[candidateName]++;\n return `${candidateName}${seenModelNameCount}`;\n};\n\nconst hoistInlineObjectSubSchemas = (\n nameParts: string[],\n schema: OpenAPIV3.SchemaObject,\n seenModelNameCounts: { [name: string]: number },\n): SubSchemaRef[] => {\n // Find all the inline subschemas we should visit\n const inlineSubSchemas: SubSchema[] = [\n ...(hasSubSchemasToVisit(schema.not)\n ? [\n {\n nameParts: schema.not?.title\n ? [pascalCase(schema.not?.title)]\n : [...nameParts, 'Not'],\n schema: schema.not,\n propPath: ['not'],\n },\n ]\n : []),\n ...(schema.anyOf\n ? filterInlineCompositeSchemas(schema.anyOf, nameParts, 'AnyOf', [\n 'anyOf',\n ])\n : []),\n ...(schema.allOf\n ? filterInlineCompositeSchemas(schema.allOf, nameParts, 'AllOf', [\n 'allOf',\n ])\n : []),\n ...(schema.oneOf\n ? filterInlineCompositeSchemas(schema.oneOf, nameParts, 'OneOf', [\n 'oneOf',\n ])\n : []),\n ...('items' in schema && hasSubSchemasToVisit(schema.items)\n ? [\n {\n nameParts: schema.items?.title\n ? [pascalCase(schema.items?.title)]\n : [...nameParts, 'Item'],\n schema: schema.items,\n propPath: ['items'],\n },\n ]\n : []),\n ...Object.entries(schema.properties ?? {})\n .filter(([, s]) => hasSubSchemasToVisit(s))\n .map(([name, s]) => ({\n nameParts: (s as OpenAPIV3.SchemaObject).title\n ? [pascalCase((s as OpenAPIV3.SchemaObject).title)]\n : [...nameParts, name],\n schema: s as OpenAPIV3.SchemaObject,\n propPath: ['properties', name],\n })),\n ...(typeof schema.additionalProperties !== 'boolean' &&\n hasSubSchemasToVisit(schema.additionalProperties)\n ? [\n {\n nameParts: schema.additionalProperties?.title\n ? [pascalCase(schema.additionalProperties?.title)]\n : [...nameParts, 'Value'],\n schema: schema.additionalProperties,\n propPath: ['additionalProperties'],\n },\n ]\n : []),\n ...Object.entries((schema as any).patternProperties ?? {})\n .filter(([, s]) => hasSubSchemasToVisit(s))\n .map(([pattern, s], i) => ({\n nameParts: (s as OpenAPIV3.SchemaObject).title\n ? [pascalCase((s as OpenAPIV3.SchemaObject).title)]\n : [...nameParts, pascalCase(pattern), `${i}`],\n schema: s as OpenAPIV3.SchemaObject,\n propPath: ['patternProperties', pattern],\n })),\n ];\n\n // Hoist these recursively first (ie depth first search) so that we don't miss refs\n const recursiveRefs = inlineSubSchemas.flatMap((s) =>\n hoistInlineObjectSubSchemas(s.nameParts, s.schema, seenModelNameCounts),\n );\n\n // Clone the object subschemas to build the refs. Note that only objects with \"properties\" are hoisted as these are non-dictionary types\n const refs = inlineSubSchemas\n .filter(\n (s) =>\n (s.schema.type === 'object' && s.schema.properties) ||\n isCompositeSchema(s.schema) ||\n (s.schema.type === 'object' && (s.schema as any).patternProperties) ||\n (s.schema.type === 'string' && s.schema.enum),\n )\n .map((s) => {\n const name = createUniqueModelName(s.nameParts, seenModelNameCounts);\n\n const $ref = `#/components/schemas/${name}`;\n const ref = {\n $ref,\n name,\n schema: structuredClone({\n ...s.schema,\n 'x-aws-nx-hoisted': true,\n }),\n };\n\n // Replace each subschema with a ref in the spec\n const schemaWithPropToReplace = s.propPath\n .slice(0, -1)\n .reduce(\n (resolvedInSchema, pathPart) => resolvedInSchema?.[pathPart],\n schema,\n );\n if (schemaWithPropToReplace) {\n schemaWithPropToReplace[s.propPath[s.propPath.length - 1]] = { $ref };\n }\n\n return ref;\n });\n\n return [...refs, ...recursiveRefs];\n};\n\n/**\n * Rewrites OpenAPI 3.1 `const` schemas to the semantically equivalent `enum`\n * form. FastAPI emits `{type: 'string', const: 'X'}` for `Literal['X']`; the\n * parser understands the enum shape, whereas the const shape would synthesise\n * phantom named references.\n */\nconst rewriteConstToEnum = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n 'const' in v &&\n !('enum' in v)\n ) {\n const { const: constValue, ...rest } = v;\n // Recurse with the same rewrite so consts nested within a rewritten\n // schema are also rewritten.\n return cloneDeepWith({ ...rest, enum: [constValue] }, rewrite);\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Rewrites a composite schema with sibling `properties`/`required` (a valid\n * JSON Schema conjunction, common in FastAPI/Pydantic output) into an\n * equivalent extra `allOf` member, so the parser sees a pure composite and the\n * sibling fields are neither dropped from the type nor stripped when\n * marshalling.\n */\nconst rewriteCompositeSiblingProperties = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n Array.isArray(v.allOf) &&\n v.properties\n ) {\n const { properties, required, type: _type, ...rest } = v;\n return cloneDeepWith(\n {\n ...rest,\n allOf: [\n ...v.allOf,\n {\n type: 'object',\n properties,\n ...(required ? { required } : {}),\n },\n ],\n },\n rewrite,\n );\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Rewrites an OpenAPI 3.1 multi-type schema (`type: ['integer', 'string']`)\n * into the equivalent `anyOf` of single-type schemas, dropping `null` from the\n * list and marking the schema nullable instead. This lets the parser render a\n * proper union rather than collapsing to the first declared type.\n */\nconst rewriteMultiTypeToAnyOf = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n Array.isArray(v.type) &&\n !('anyOf' in v) &&\n !('oneOf' in v) &&\n !('allOf' in v) &&\n !('enum' in v)\n ) {\n const { type, nullable, ...rest } = v;\n const nonNull = (type as string[]).filter((t) => t !== 'null');\n const isNullable = nullable === true || nonNull.length !== type.length;\n // Recurse with the same rewrite so multi-type schemas nested within a\n // rewritten schema (e.g. the items of a nullable array) are also\n // rewritten.\n // A single non-null type is not a union; keep it as a plain typed schema.\n if (nonNull.length <= 1) {\n return cloneDeepWith(\n {\n ...rest,\n ...(nonNull.length === 1 ? { type: nonNull[0] } : {}),\n ...(isNullable ? { nullable: true } : {}),\n },\n rewrite,\n );\n }\n return cloneDeepWith(\n {\n ...rest,\n anyOf: nonNull.map((t) => ({ type: t })),\n ...(isNullable ? { nullable: true } : {}),\n },\n rewrite,\n );\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Inlines `$ref` path items so that every operation is visited by the\n * normalisation below (operationId assignment, schema hoisting). Each path\n * gets its own copy, so paths sharing a path item are normalised\n * independently.\n */\nconst inlinePathItemRefs = (spec: Spec): void => {\n Object.entries(spec.paths ?? {}).forEach(([path, pathItem]) => {\n if (isRef(pathItem)) {\n const { $ref, ...rest } = pathItem;\n spec.paths![path] = {\n ...structuredClone(resolveRef(spec, $ref)),\n ...rest,\n };\n }\n });\n};\n\n/**\n * In order to ensure we generate models consistently whether or not users used refs or inline schemas,\n * we hoist any inline refs to non-primitives\n */\nexport const normaliseOpenApiSpecForCodeGen = (inSpec: Spec): Spec => {\n // Clone the spec so we're free to mutate it\n let spec = cloneDeepWith(inSpec);\n\n inlinePathItemRefs(spec);\n spec = rewriteConstToEnum(spec);\n spec = rewriteMultiTypeToAnyOf(spec);\n spec = rewriteCompositeSiblingProperties(spec);\n\n // Ensure spec has schemas set\n if (!spec?.components?.schemas) {\n spec.components = {\n ...spec.components,\n };\n spec.components.schemas = {\n ...spec.components.schemas,\n };\n }\n\n const seenOperationIds = new Set<string>();\n const duplicatedOperationIds = new Set<string>();\n\n // Make sure all operationIds are camelCase, and find which ones are duplicated\n Object.entries(spec.paths ?? {}).forEach(([path, pathOps]) =>\n Object.entries(pathOps ?? {}).forEach(([method, op]) => {\n const operation = resolveIfRef(spec, op);\n if (operation && typeof operation === 'object') {\n const operationId = camelCase(\n (operation as any).operationId ?? `${method}-${path}`,\n );\n (operation as any).operationId = operationId;\n if (seenOperationIds.has(operationId)) {\n duplicatedOperationIds.add(operationId);\n }\n seenOperationIds.add(operationId);\n }\n }),\n );\n\n // Reset seen operation ids\n seenOperationIds.clear();\n\n const untagged = Symbol('untagged');\n const seenOperationIdsByTag: { [tag: string | symbol]: Set<string> } = {};\n\n // \"Hoist\" inline request and response schemas\n Object.entries(spec.paths ?? {}).forEach(([path, pathOps]) =>\n Object.entries(pathOps ?? {}).forEach(([method, op]) => {\n const operation = resolveIfRef(spec, op);\n if (operation && typeof operation === 'object') {\n const tags: string[] = (operation as any).tags ?? [];\n const operationId = (operation as any).operationId as string;\n\n // Allow operations to have the same id\n let deduplicatedOpId = operationId;\n let deduplicatedDotNotationOpId = operationId;\n\n // Attempt to deduplicate the operationId by its tags\n if (duplicatedOperationIds.has(operationId)) {\n deduplicatedOpId = camelCase(\n tags.map((t) => `${t}-`).join('') + operationId,\n );\n deduplicatedDotNotationOpId =\n tags.map((t) => `${camelCase(t)}.`).join('') +\n camelCase(operationId);\n }\n\n (operation as any)['x-aws-nx-deduplicated-op-id'] = deduplicatedOpId;\n (operation as any)['x-aws-nx-deduplicated-dot-op-id'] =\n deduplicatedDotNotationOpId;\n\n seenOperationIds.add(deduplicatedOpId);\n\n // Throw an error for any duplicated operation ids with the same tag, or untagged\n [...(tags.length === 0 ? [untagged] : tags)].forEach((tag) => {\n if (\n seenOperationIdsByTag[tag] &&\n seenOperationIdsByTag[tag].has(operationId)\n ) {\n throw new Error(\n tag === untagged\n ? `Untagged operations cannot have the same operationId (${operationId})`\n : `Operations with the same tag (${String(tag)}) cannot have the same operationId (${operationId})`,\n );\n }\n\n seenOperationIdsByTag[tag] = new Set([\n ...(seenOperationIdsByTag[tag] ?? []),\n operationId,\n ]);\n });\n\n if ('responses' in operation) {\n Object.entries(operation.responses ?? {}).forEach(([code, res]) => {\n const response = resolveIfRef(spec, res);\n const jsonMediaType = preferredJsonMediaType(\n Object.keys(response?.content ?? {}),\n );\n const jsonResponseSchema = jsonMediaType\n ? response!.content![jsonMediaType].schema\n : undefined;\n if (\n jsonResponseSchema &&\n !isRef(jsonResponseSchema) &&\n (['object', 'array'].includes(jsonResponseSchema.type!) ||\n isCompositeSchema(jsonResponseSchema) ||\n (jsonResponseSchema?.type === 'string' &&\n jsonResponseSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}${code}Response`;\n spec.components!.schemas![schemaName] = jsonResponseSchema;\n response!.content![jsonMediaType!].schema = {\n $ref: `#/components/schemas/${schemaName}`,\n };\n }\n\n // Hoist inline streaming item schemas (OpenAPI 3.2 itemSchema) so\n // each streamed item gets a named model.\n STREAMING_CONTENT_TYPES.forEach((mediaType) => {\n const streamingContent = response?.content?.[mediaType] as\n | { itemSchema?: OpenAPIV3.SchemaObject }\n | undefined;\n const itemSchema = streamingContent?.itemSchema;\n if (\n itemSchema &&\n !isRef(itemSchema) &&\n (['object', 'array'].includes(itemSchema.type!) ||\n isCompositeSchema(itemSchema) ||\n (itemSchema.type === 'string' && itemSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}${code}ResponseItem`;\n spec.components!.schemas![schemaName] = itemSchema;\n streamingContent.itemSchema = {\n $ref: `#/components/schemas/${schemaName}`,\n } as OpenAPIV3.SchemaObject;\n }\n });\n });\n }\n if ('requestBody' in operation) {\n const requestBody = resolveIfRef(spec, operation.requestBody);\n const contentMediaTypes = Object.keys(requestBody?.content ?? {});\n // Hoist the JSON body, falling back to a form-data body (multipart or\n // urlencoded) so an inline form object is fully typed and marshalled\n // rather than left `unknown`.\n const bodyMediaType =\n preferredJsonMediaType(contentMediaTypes) ??\n contentMediaTypes.find((mt) =>\n [\n 'multipart/form-data',\n 'application/x-www-form-urlencoded',\n ].includes(mt.split(';')[0]),\n );\n const bodyRequestSchema = bodyMediaType\n ? requestBody!.content![bodyMediaType].schema\n : undefined;\n if (\n bodyRequestSchema &&\n !isRef(bodyRequestSchema) &&\n (['object', 'array'].includes(bodyRequestSchema.type!) ||\n isCompositeSchema(bodyRequestSchema) ||\n (bodyRequestSchema?.type === 'string' && bodyRequestSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}RequestContent`;\n spec.components!.schemas![schemaName] = bodyRequestSchema;\n requestBody!.content![bodyMediaType!].schema = {\n $ref: `#/components/schemas/${schemaName}`,\n };\n }\n }\n\n // Hoist parameter schemas. Composite and inline-object schemas are\n // hoisted to named models so the parameter is fully typed (e.g. a\n // `deepObject` query param's members are marshalled, not left `unknown`).\n if ('parameters' in operation) {\n (operation.parameters ?? []).forEach((p) => {\n const param = resolveIfRef(spec, p);\n const paramSchema = param?.schema as\n | OpenAPIV3.SchemaObject\n | undefined;\n if (\n paramSchema &&\n !isRef(paramSchema) &&\n (isCompositeSchema(paramSchema) ||\n (paramSchema.type === 'object' && !!paramSchema.properties))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}Request${upperFirst(param.in)}${upperFirst(camelCase(param.name))}`;\n spec.components!.schemas![schemaName] = paramSchema;\n param.schema = { $ref: `#/components/schemas/${schemaName}` };\n }\n });\n }\n }\n }),\n );\n\n // Normalize schema names to valid TypeScript identifiers (e.g., \"Message-Output\" -> \"MessageOutput\")\n spec = normaliseSchemaNames(spec);\n\n // Initialise the models that we have seen with all schemas.\n // This is required to ensure we do not create any clashing models below\n const seenModelNameCounts = Object.fromEntries(\n Object.keys(spec.components?.schemas ?? {}).map((name) => [name, 1]),\n );\n\n // \"Hoist\" any nested object definitions in arrays/maps that aren't already refs, as parseOpenapi will treat the\n // type as \"any\" if they're defined inline (and not a ref)\n Object.entries(spec.components?.schemas ?? {}).forEach(([name, schema]) => {\n if (!isRef(schema)) {\n const refs = hoistInlineObjectSubSchemas(\n [name],\n schema,\n seenModelNameCounts,\n );\n refs.forEach((ref) => {\n spec.components!.schemas![ref.name] = ref.schema;\n });\n }\n });\n\n // \"Inline\" any refs to non objects/enums\n const inlinedRefs: Set<string> = new Set();\n spec = cloneDeepWith(spec, (v) => {\n if (v && typeof v === 'object' && v.$ref) {\n const resolved = resolveRef(spec, v.$ref);\n if (\n resolved &&\n resolved.type &&\n resolved.type !== 'object' &&\n !(resolved.type === 'string' && resolved.enum)\n ) {\n inlinedRefs.add(v.$ref);\n return resolved;\n }\n }\n });\n\n // Delete the non object schemas that were inlined\n [...inlinedRefs].forEach((ref) => {\n const parts = splitRef(ref);\n if (\n parts.length === 3 &&\n parts[0] === 'components' &&\n parts[1] === 'schemas'\n ) {\n delete spec.components!.schemas![parts[2]];\n }\n });\n\n return spec;\n};\n"],"names":["cloneDeepWith","camelCase","pascalCase","toClassName","upperFirst","STREAMING_CONTENT_TYPES","isRef","resolveIfRef","resolveRef","splitRef","normaliseSchemaNames","spec","schemaNameMapping","originalNames","Object","keys","components","schemas","existingSchemaNames","Set","resolvedNameOwners","forEach","name","normalizedName","has","Error","owner","undefined","length","v","parts","$ref","oldName","newName","entries","schema","isCompositeSchema","allOf","anyOf","oneOf","preferredJsonMediaType","mediaTypes","find","mediaType","split","endsWith","hasSubSchemasToVisit","includes","type","not","enum","filterInlineCompositeSchemas","nameParts","namePartPrefix","propPath","inlineSchemaIndex","flatMap","s","i","subSchema","title","createUniqueModelName","seenModelNameCounts","candidateName","map","join","seenModelNameCount","hoistInlineObjectSubSchemas","inlineSubSchemas","items","properties","filter","additionalProperties","patternProperties","pattern","recursiveRefs","refs","ref","structuredClone","schemaWithPropToReplace","slice","reduce","resolvedInSchema","pathPart","rewriteConstToEnum","rewrite","Array","isArray","const","constValue","rest","rewriteCompositeSiblingProperties","required","_type","rewriteMultiTypeToAnyOf","nullable","nonNull","t","isNullable","inlinePathItemRefs","paths","path","pathItem","normaliseOpenApiSpecForCodeGen","inSpec","seenOperationIds","duplicatedOperationIds","pathOps","method","op","operation","operationId","add","clear","untagged","Symbol","seenOperationIdsByTag","tags","deduplicatedOpId","deduplicatedDotNotationOpId","tag","String","responses","code","res","response","jsonMediaType","content","jsonResponseSchema","schemaName","streamingContent","itemSchema","requestBody","contentMediaTypes","bodyMediaType","mt","bodyRequestSchema","parameters","p","param","paramSchema","in","fromEntries","inlinedRefs","resolved"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,mBAAmB,uBAAuB;AAEjD,SACEC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,UAAU,QACL,uBAAoB;AAC3B,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,KAAK,EAAEC,YAAY,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,YAAS;AAenE;;;;CAIC,GACD,MAAMC,uBAAuB,CAACC;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AkD;IAClD;WAAID;KAAY,CAAC1H,OAAO,CAAC,CAACwD;QACxB,MAAM/C,QAAQrB,SAASoE;QACvB,IACE/C,MAAMF,MAAM,KAAK,KACjBE,KAAK,CAAC,EAAE,KAAK,gBACbA,KAAK,CAAC,EAAE,KAAK,WACb;YACA,OAAOnB,KAAKK,UAAU,CAAEC,OAAO,AAAC,CAACa,KAAK,CAAC,EAAE,CAAC;QAC5C;IACF;IAEA,OAAOnB;AACT,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/utils/normalise.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport cloneDeepWith from 'lodash.clonedeepwith';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport {\n camelCase,\n pascalCase,\n toClassName,\n upperFirst,\n} from '../../utils/names';\nimport { STREAMING_CONTENT_TYPES } from './codegen-data/types';\nimport { isRef, resolveIfRef, resolveRef, splitRef } from './refs';\nimport type { Spec } from './types';\n\ninterface SubSchema {\n readonly nameParts: string[];\n readonly schema: OpenAPIV3.SchemaObject;\n readonly propPath: (string | number)[];\n}\n\ninterface SubSchemaRef {\n readonly $ref: string;\n readonly name: string;\n readonly schema: OpenAPIV3.SchemaObject;\n}\n\n/**\n * Normalise schema names to valid TypeScript identifiers.\n * Converts names with hyphens or other invalid characters to PascalCase.\n * Throws an error if normalisation would create a name clash.\n */\nconst normaliseSchemaNames = (spec: Spec): Spec => {\n const schemaNameMapping: { [oldName: string]: string } = {};\n const originalNames = Object.keys(spec.components?.schemas ?? {});\n const existingSchemaNames = new Set(originalNames);\n\n // The name each schema resolves to (its normalised form, or itself when it\n // needs no normalisation). Used to detect two distinct schemas that would\n // collapse onto the same identifier.\n const resolvedNameOwners: { [resolvedName: string]: string } = {};\n\n // Build mapping of old names to new names\n originalNames.forEach((name) => {\n const normalizedName = toClassName(name);\n if (normalizedName !== name) {\n // Check if the normalized name would clash with an existing schema\n if (existingSchemaNames.has(normalizedName)) {\n throw new Error(\n `Schema name normalization conflict: \"${name}\" would be normalized to \"${normalizedName}\", but a schema with that name already exists. Please rename one of these schemas in your OpenAPI specification.`,\n );\n }\n schemaNameMapping[name] = normalizedName;\n }\n\n // Detect two distinct schemas resolving to the same name (e.g. \"Foo-Bar\"\n // and \"Foo.Bar\" both normalise to \"FooBar\"), which would otherwise\n // silently overwrite one another.\n const owner = resolvedNameOwners[normalizedName];\n if (owner !== undefined) {\n throw new Error(\n `Schema name normalization conflict: \"${name}\" and \"${owner}\" both normalize to \"${normalizedName}\". Please rename one of these schemas in your OpenAPI specification.`,\n );\n }\n resolvedNameOwners[normalizedName] = name;\n });\n\n // If no normalization needed, return spec as-is\n if (Object.keys(schemaNameMapping).length === 0) {\n return spec;\n }\n\n // Update all $ref references throughout the spec\n spec = cloneDeepWith(spec, (v) => {\n if (isRef(v)) {\n const parts = splitRef(v.$ref);\n if (\n parts.length === 3 &&\n parts[0] === 'components' &&\n parts[1] === 'schemas'\n ) {\n const oldName = parts[2];\n const newName = schemaNameMapping[oldName];\n if (newName) {\n return { $ref: `#/components/schemas/${newName}` };\n }\n }\n }\n });\n\n // Rename schema keys, recording the original name so downstream code can\n // recover the on-the-wire value (e.g. an implicit discriminator matches on\n // the original schema name, not its normalised identifier).\n Object.entries(schemaNameMapping).forEach(([oldName, newName]) => {\n const schema = spec.components!.schemas![oldName];\n if (schema && !isRef(schema)) {\n (schema as { 'x-aws-nx-original-name'?: string })[\n 'x-aws-nx-original-name'\n ] = oldName;\n }\n spec.components!.schemas![newName] = schema;\n delete spec.components!.schemas![oldName];\n });\n\n return spec;\n};\n\nconst isCompositeSchema = (schema: OpenAPIV3.SchemaObject) =>\n !!schema.allOf || !!schema.anyOf || !!schema.oneOf;\n\n/**\n * The media type whose schema is hoisted for a request/response: prefer\n * `application/json`, falling back to any `+json` vendored type (e.g.\n * `application/problem+json`).\n */\nconst preferredJsonMediaType = (mediaTypes: string[]): string | undefined =>\n mediaTypes.find((mediaType) => mediaType === 'application/json') ??\n mediaTypes.find((mediaType) => mediaType.split(';')[0].endsWith('+json'));\n\nconst FORM_MEDIA_TYPES = [\n 'multipart/form-data',\n 'application/x-www-form-urlencoded',\n];\n\nconst isFormMediaType = (mediaType: string): boolean =>\n FORM_MEDIA_TYPES.includes(mediaType.split(';')[0]);\n\n/**\n * Whether a `contentMediaType` denotes binary (rather than textual/JSON)\n * content — an octet-stream, image, audio, etc.\n */\nconst isBinaryContentMediaType = (contentMediaType: string): boolean =>\n !(\n contentMediaType.startsWith('text/') ||\n contentMediaType === 'application/json' ||\n contentMediaType.endsWith('+json') ||\n contentMediaType === 'application/xml'\n );\n\n/**\n * Rewrite file string fields of a form body to `format: binary` so the\n * generator types them as `Blob`. FastAPI emits an identical schema\n * (`{type: string, contentMediaType: ...}`) for a multipart file field and for\n * `bytes` in a JSON body; only the enclosing media type distinguishes them, so\n * this promotion is scoped to form bodies. A base64 `contentEncoding` or a\n * textual/JSON `contentMediaType` keeps the field a string. `format: binary` is\n * left untouched (already binary anywhere).\n */\nconst markFormBinaryFields = (schema: OpenAPIV3.SchemaObject): void => {\n Object.values(schema.properties ?? {}).forEach((prop) => {\n if (isRef(prop)) return;\n const s = prop as OpenAPIV3.SchemaObject & {\n contentMediaType?: string;\n contentEncoding?: string;\n };\n if (\n s.type === 'string' &&\n s.format !== 'binary' &&\n s.contentMediaType &&\n !s.contentEncoding &&\n isBinaryContentMediaType(s.contentMediaType)\n ) {\n s.format = 'binary';\n }\n });\n};\n\nconst hasSubSchemasToVisit = (\n schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject,\n): schema is OpenAPIV3.SchemaObject =>\n !!schema &&\n !isRef(schema) &&\n (['object', 'array'].includes(schema.type as any) ||\n isCompositeSchema(schema) ||\n !!schema.not ||\n (schema.type === 'string' && !!schema.enum));\n\nconst filterInlineCompositeSchemas = (\n schemas: (OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject)[],\n nameParts: string[],\n namePartPrefix: string,\n propPath: (string | number)[],\n): SubSchema[] => {\n let inlineSchemaIndex = 0;\n return schemas.flatMap((s, i) => {\n if (hasSubSchemasToVisit(s)) {\n const subSchema: SubSchema = {\n nameParts: s.title\n ? [pascalCase(s.title)]\n : [\n ...nameParts,\n `${namePartPrefix}${inlineSchemaIndex === 0 ? '' : inlineSchemaIndex}`,\n ],\n schema: s,\n propPath: [...propPath, i],\n };\n inlineSchemaIndex++;\n return [subSchema];\n }\n return [];\n });\n};\n\n/**\n * Returns a unique model/schema name for any models which we hoist\n */\nconst createUniqueModelName = (\n nameParts: string[],\n seenModelNameCounts: { [name: string]: number },\n): string => {\n // Normalise each part to a class-name form (stripping `_`, hyphens, etc) so\n // the hoisted schema name matches what `toTypeScriptModelName`/`toClassName`\n // later derive — otherwise a part like `store_photos` yields a `Store_photos`\n // schema whose reference (`StorePhotos`) no longer resolves.\n const candidateName = nameParts.map(toClassName).join('');\n\n const seenModelNameCount = seenModelNameCounts[candidateName];\n\n // We have not seen this name so we're free to use it\n if (seenModelNameCount === undefined) {\n seenModelNameCounts[candidateName] = 1;\n return candidateName;\n }\n\n // We have seen the name before, so we must disambiguate\n seenModelNameCounts[candidateName]++;\n return `${candidateName}${seenModelNameCount}`;\n};\n\nconst hoistInlineObjectSubSchemas = (\n nameParts: string[],\n schema: OpenAPIV3.SchemaObject,\n seenModelNameCounts: { [name: string]: number },\n): SubSchemaRef[] => {\n // Find all the inline subschemas we should visit\n const inlineSubSchemas: SubSchema[] = [\n ...(hasSubSchemasToVisit(schema.not)\n ? [\n {\n nameParts: schema.not?.title\n ? [pascalCase(schema.not?.title)]\n : [...nameParts, 'Not'],\n schema: schema.not,\n propPath: ['not'],\n },\n ]\n : []),\n ...(schema.anyOf\n ? filterInlineCompositeSchemas(schema.anyOf, nameParts, 'AnyOf', [\n 'anyOf',\n ])\n : []),\n ...(schema.allOf\n ? filterInlineCompositeSchemas(schema.allOf, nameParts, 'AllOf', [\n 'allOf',\n ])\n : []),\n ...(schema.oneOf\n ? filterInlineCompositeSchemas(schema.oneOf, nameParts, 'OneOf', [\n 'oneOf',\n ])\n : []),\n ...('items' in schema && hasSubSchemasToVisit(schema.items)\n ? [\n {\n nameParts: schema.items?.title\n ? [pascalCase(schema.items?.title)]\n : [...nameParts, 'Item'],\n schema: schema.items,\n propPath: ['items'],\n },\n ]\n : []),\n ...(\n (schema as { prefixItems?: OpenAPIV3.SchemaObject[] }).prefixItems ?? []\n ).flatMap((s, i) =>\n hasSubSchemasToVisit(s)\n ? [\n {\n nameParts: s.title\n ? [pascalCase(s.title)]\n : [...nameParts, 'Item', `${i}`],\n schema: s,\n propPath: ['prefixItems', i],\n },\n ]\n : [],\n ),\n ...Object.entries(schema.properties ?? {})\n .filter(([, s]) => hasSubSchemasToVisit(s))\n .map(([name, s]) => ({\n nameParts: (s as OpenAPIV3.SchemaObject).title\n ? [pascalCase((s as OpenAPIV3.SchemaObject).title)]\n : [...nameParts, name],\n schema: s as OpenAPIV3.SchemaObject,\n propPath: ['properties', name],\n })),\n ...(typeof schema.additionalProperties !== 'boolean' &&\n hasSubSchemasToVisit(schema.additionalProperties)\n ? [\n {\n nameParts: schema.additionalProperties?.title\n ? [pascalCase(schema.additionalProperties?.title)]\n : [...nameParts, 'Value'],\n schema: schema.additionalProperties,\n propPath: ['additionalProperties'],\n },\n ]\n : []),\n ...Object.entries((schema as any).patternProperties ?? {})\n .filter(([, s]) => hasSubSchemasToVisit(s))\n .map(([pattern, s], i) => ({\n nameParts: (s as OpenAPIV3.SchemaObject).title\n ? [pascalCase((s as OpenAPIV3.SchemaObject).title)]\n : [...nameParts, pascalCase(pattern), `${i}`],\n schema: s as OpenAPIV3.SchemaObject,\n propPath: ['patternProperties', pattern],\n })),\n ];\n\n // Hoist these recursively first (ie depth first search) so that we don't miss refs\n const recursiveRefs = inlineSubSchemas.flatMap((s) =>\n hoistInlineObjectSubSchemas(s.nameParts, s.schema, seenModelNameCounts),\n );\n\n // Clone the object subschemas to build the refs. Note that only objects with \"properties\" are hoisted as these are non-dictionary types\n const refs = inlineSubSchemas\n .filter(\n (s) =>\n (s.schema.type === 'object' && s.schema.properties) ||\n isCompositeSchema(s.schema) ||\n (s.schema.type === 'object' && (s.schema as any).patternProperties) ||\n (s.schema.type === 'string' && s.schema.enum),\n )\n .map((s) => {\n const name = createUniqueModelName(s.nameParts, seenModelNameCounts);\n\n const $ref = `#/components/schemas/${name}`;\n const ref = {\n $ref,\n name,\n schema: structuredClone({\n ...s.schema,\n 'x-aws-nx-hoisted': true,\n }),\n };\n\n // Replace each subschema with a ref in the spec\n const schemaWithPropToReplace = s.propPath\n .slice(0, -1)\n .reduce(\n (resolvedInSchema, pathPart) => resolvedInSchema?.[pathPart],\n schema,\n );\n if (schemaWithPropToReplace) {\n schemaWithPropToReplace[s.propPath[s.propPath.length - 1]] = { $ref };\n }\n\n return ref;\n });\n\n return [...refs, ...recursiveRefs];\n};\n\n/**\n * Rewrites OpenAPI 3.1 `const` schemas to the semantically equivalent `enum`\n * form. FastAPI emits `{type: 'string', const: 'X'}` for `Literal['X']`; the\n * parser understands the enum shape, whereas the const shape would synthesise\n * phantom named references.\n */\nconst rewriteConstToEnum = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n 'const' in v &&\n !('enum' in v)\n ) {\n const { const: constValue, ...rest } = v;\n // Recurse with the same rewrite so consts nested within a rewritten\n // schema are also rewritten.\n return cloneDeepWith({ ...rest, enum: [constValue] }, rewrite);\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Rewrites a composite schema with sibling `properties`/`required` (a valid\n * JSON Schema conjunction, common in FastAPI/Pydantic output) into an\n * equivalent extra `allOf` member, so the parser sees a pure composite and the\n * sibling fields are neither dropped from the type nor stripped when\n * marshalling.\n */\nconst rewriteCompositeSiblingProperties = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n Array.isArray(v.allOf) &&\n v.properties\n ) {\n const { properties, required, type: _type, ...rest } = v;\n return cloneDeepWith(\n {\n ...rest,\n allOf: [\n ...v.allOf,\n {\n type: 'object',\n properties,\n ...(required ? { required } : {}),\n },\n ],\n },\n rewrite,\n );\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Rewrites an OpenAPI 3.1 multi-type schema (`type: ['integer', 'string']`)\n * into the equivalent `anyOf` of single-type schemas, dropping `null` from the\n * list and marking the schema nullable instead. This lets the parser render a\n * proper union rather than collapsing to the first declared type.\n */\nconst rewriteMultiTypeToAnyOf = (spec: Spec): Spec => {\n const rewrite = (v: any): any => {\n if (\n v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n Array.isArray(v.type) &&\n !('anyOf' in v) &&\n !('oneOf' in v) &&\n !('allOf' in v) &&\n !('enum' in v)\n ) {\n const { type, nullable, ...rest } = v;\n const nonNull = (type as string[]).filter((t) => t !== 'null');\n const isNullable = nullable === true || nonNull.length !== type.length;\n // Recurse with the same rewrite so multi-type schemas nested within a\n // rewritten schema (e.g. the items of a nullable array) are also\n // rewritten.\n // A single non-null type is not a union; keep it as a plain typed schema.\n if (nonNull.length <= 1) {\n return cloneDeepWith(\n {\n ...rest,\n ...(nonNull.length === 1 ? { type: nonNull[0] } : {}),\n ...(isNullable ? { nullable: true } : {}),\n },\n rewrite,\n );\n }\n return cloneDeepWith(\n {\n ...rest,\n anyOf: nonNull.map((t) => ({ type: t })),\n ...(isNullable ? { nullable: true } : {}),\n },\n rewrite,\n );\n }\n };\n return cloneDeepWith(spec, rewrite);\n};\n\n/**\n * Inlines `$ref` path items so that every operation is visited by the\n * normalisation below (operationId assignment, schema hoisting). Each path\n * gets its own copy, so paths sharing a path item are normalised\n * independently.\n */\nconst inlinePathItemRefs = (spec: Spec): void => {\n Object.entries(spec.paths ?? {}).forEach(([path, pathItem]) => {\n if (isRef(pathItem)) {\n const { $ref, ...rest } = pathItem;\n spec.paths![path] = {\n ...structuredClone(resolveRef(spec, $ref)),\n ...rest,\n };\n }\n });\n};\n\n/**\n * In order to ensure we generate models consistently whether or not users used refs or inline schemas,\n * we hoist any inline refs to non-primitives\n */\nexport const normaliseOpenApiSpecForCodeGen = (inSpec: Spec): Spec => {\n // Clone the spec so we're free to mutate it\n let spec = cloneDeepWith(inSpec);\n\n inlinePathItemRefs(spec);\n spec = rewriteConstToEnum(spec);\n spec = rewriteMultiTypeToAnyOf(spec);\n spec = rewriteCompositeSiblingProperties(spec);\n\n // Ensure spec has schemas set\n if (!spec?.components?.schemas) {\n spec.components = {\n ...spec.components,\n };\n spec.components.schemas = {\n ...spec.components.schemas,\n };\n }\n\n const seenOperationIds = new Set<string>();\n const duplicatedOperationIds = new Set<string>();\n\n // Make sure all operationIds are camelCase, and find which ones are duplicated\n Object.entries(spec.paths ?? {}).forEach(([path, pathOps]) =>\n Object.entries(pathOps ?? {}).forEach(([method, op]) => {\n const operation = resolveIfRef(spec, op);\n if (operation && typeof operation === 'object') {\n const operationId = camelCase(\n (operation as any).operationId ?? `${method}-${path}`,\n );\n (operation as any).operationId = operationId;\n if (seenOperationIds.has(operationId)) {\n duplicatedOperationIds.add(operationId);\n }\n seenOperationIds.add(operationId);\n }\n }),\n );\n\n // Reset seen operation ids\n seenOperationIds.clear();\n\n const untagged = Symbol('untagged');\n const seenOperationIdsByTag: { [tag: string | symbol]: Set<string> } = {};\n\n // \"Hoist\" inline request and response schemas\n Object.entries(spec.paths ?? {}).forEach(([path, pathOps]) =>\n Object.entries(pathOps ?? {}).forEach(([method, op]) => {\n const operation = resolveIfRef(spec, op);\n if (operation && typeof operation === 'object') {\n const tags: string[] = (operation as any).tags ?? [];\n const operationId = (operation as any).operationId as string;\n\n // Allow operations to have the same id\n let deduplicatedOpId = operationId;\n let deduplicatedDotNotationOpId = operationId;\n\n // Attempt to deduplicate the operationId by its tags\n if (duplicatedOperationIds.has(operationId)) {\n deduplicatedOpId = camelCase(\n tags.map((t) => `${t}-`).join('') + operationId,\n );\n deduplicatedDotNotationOpId =\n tags.map((t) => `${camelCase(t)}.`).join('') +\n camelCase(operationId);\n }\n\n (operation as any)['x-aws-nx-deduplicated-op-id'] = deduplicatedOpId;\n (operation as any)['x-aws-nx-deduplicated-dot-op-id'] =\n deduplicatedDotNotationOpId;\n\n seenOperationIds.add(deduplicatedOpId);\n\n // Throw an error for any duplicated operation ids with the same tag, or untagged\n [...(tags.length === 0 ? [untagged] : tags)].forEach((tag) => {\n if (\n seenOperationIdsByTag[tag] &&\n seenOperationIdsByTag[tag].has(operationId)\n ) {\n throw new Error(\n tag === untagged\n ? `Untagged operations cannot have the same operationId (${operationId})`\n : `Operations with the same tag (${String(tag)}) cannot have the same operationId (${operationId})`,\n );\n }\n\n seenOperationIdsByTag[tag] = new Set([\n ...(seenOperationIdsByTag[tag] ?? []),\n operationId,\n ]);\n });\n\n if ('responses' in operation) {\n Object.entries(operation.responses ?? {}).forEach(([code, res]) => {\n const response = resolveIfRef(spec, res);\n const jsonMediaType = preferredJsonMediaType(\n Object.keys(response?.content ?? {}),\n );\n const jsonResponseSchema = jsonMediaType\n ? response!.content![jsonMediaType].schema\n : undefined;\n if (\n jsonResponseSchema &&\n !isRef(jsonResponseSchema) &&\n (['object', 'array'].includes(jsonResponseSchema.type!) ||\n isCompositeSchema(jsonResponseSchema) ||\n (jsonResponseSchema?.type === 'string' &&\n jsonResponseSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}${code}Response`;\n spec.components!.schemas![schemaName] = jsonResponseSchema;\n response!.content![jsonMediaType!].schema = {\n $ref: `#/components/schemas/${schemaName}`,\n };\n }\n\n // Hoist inline streaming item schemas (OpenAPI 3.2 itemSchema) so\n // each streamed item gets a named model.\n STREAMING_CONTENT_TYPES.forEach((mediaType) => {\n const streamingContent = response?.content?.[mediaType] as\n | { itemSchema?: OpenAPIV3.SchemaObject }\n | undefined;\n const itemSchema = streamingContent?.itemSchema;\n if (\n itemSchema &&\n !isRef(itemSchema) &&\n (['object', 'array'].includes(itemSchema.type!) ||\n isCompositeSchema(itemSchema) ||\n (itemSchema.type === 'string' && itemSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}${code}ResponseItem`;\n spec.components!.schemas![schemaName] = itemSchema;\n streamingContent.itemSchema = {\n $ref: `#/components/schemas/${schemaName}`,\n } as OpenAPIV3.SchemaObject;\n }\n });\n });\n }\n if ('requestBody' in operation) {\n const requestBody = resolveIfRef(spec, operation.requestBody);\n const contentMediaTypes = Object.keys(requestBody?.content ?? {});\n // Hoist the JSON body, falling back to a form-data body (multipart or\n // urlencoded) so an inline form object is fully typed and marshalled\n // rather than left `unknown`.\n const bodyMediaType =\n preferredJsonMediaType(contentMediaTypes) ??\n contentMediaTypes.find(isFormMediaType);\n const bodyContentSchema = bodyMediaType\n ? requestBody!.content![bodyMediaType].schema\n : undefined;\n // A form body's binary string fields are file uploads (Blob). Mark\n // the resolved schema (inline or $ref target) before hoisting.\n if (bodyMediaType && isFormMediaType(bodyMediaType)) {\n const resolved = resolveIfRef(spec, bodyContentSchema) as\n | OpenAPIV3.SchemaObject\n | undefined;\n if (resolved) markFormBinaryFields(resolved);\n }\n if (\n bodyContentSchema &&\n !isRef(bodyContentSchema) &&\n (['object', 'array'].includes(bodyContentSchema.type!) ||\n isCompositeSchema(bodyContentSchema) ||\n (bodyContentSchema?.type === 'string' && bodyContentSchema.enum))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}RequestContent`;\n spec.components!.schemas![schemaName] = bodyContentSchema;\n requestBody!.content![bodyMediaType!].schema = {\n $ref: `#/components/schemas/${schemaName}`,\n };\n }\n }\n\n // Hoist parameter schemas. Composite and inline-object schemas are\n // hoisted to named models so the parameter is fully typed (e.g. a\n // `deepObject` query param's members are marshalled, not left `unknown`).\n if ('parameters' in operation) {\n (operation.parameters ?? []).forEach((p) => {\n const param = resolveIfRef(spec, p);\n const paramSchema = param?.schema as\n | OpenAPIV3.SchemaObject\n | undefined;\n if (\n paramSchema &&\n !isRef(paramSchema) &&\n (isCompositeSchema(paramSchema) ||\n (paramSchema.type === 'object' && !!paramSchema.properties))\n ) {\n const schemaName = `${upperFirst(deduplicatedOpId)}Request${upperFirst(param.in)}${upperFirst(camelCase(param.name))}`;\n spec.components!.schemas![schemaName] = paramSchema;\n param.schema = { $ref: `#/components/schemas/${schemaName}` };\n }\n });\n }\n }\n }),\n );\n\n // Normalize schema names to valid TypeScript identifiers (e.g., \"Message-Output\" -> \"MessageOutput\")\n spec = normaliseSchemaNames(spec);\n\n // Initialise the models that we have seen with all schemas.\n // This is required to ensure we do not create any clashing models below\n const seenModelNameCounts = Object.fromEntries(\n Object.keys(spec.components?.schemas ?? {}).map((name) => [name, 1]),\n );\n\n // \"Hoist\" any nested object definitions in arrays/maps that aren't already refs, as parseOpenapi will treat the\n // type as \"any\" if they're defined inline (and not a ref)\n Object.entries(spec.components?.schemas ?? {}).forEach(([name, schema]) => {\n if (!isRef(schema)) {\n const refs = hoistInlineObjectSubSchemas(\n [name],\n schema,\n seenModelNameCounts,\n );\n refs.forEach((ref) => {\n spec.components!.schemas![ref.name] = ref.schema;\n });\n }\n });\n\n // \"Inline\" any refs to non objects/enums\n const inlinedRefs: Set<string> = new Set();\n spec = cloneDeepWith(spec, (v) => {\n if (v && typeof v === 'object' && v.$ref) {\n const resolved = resolveRef(spec, v.$ref);\n if (\n resolved &&\n resolved.type &&\n resolved.type !== 'object' &&\n !(resolved.type === 'string' && resolved.enum)\n ) {\n inlinedRefs.add(v.$ref);\n return resolved;\n }\n }\n });\n\n // Delete the non object schemas that were inlined\n [...inlinedRefs].forEach((ref) => {\n const parts = splitRef(ref);\n if (\n parts.length === 3 &&\n parts[0] === 'components' &&\n parts[1] === 'schemas'\n ) {\n delete spec.components!.schemas![parts[2]];\n }\n });\n\n return spec;\n};\n"],"names":["cloneDeepWith","camelCase","pascalCase","toClassName","upperFirst","STREAMING_CONTENT_TYPES","isRef","resolveIfRef","resolveRef","splitRef","normaliseSchemaNames","spec","schemaNameMapping","originalNames","Object","keys","components","schemas","existingSchemaNames","Set","resolvedNameOwners","forEach","name","normalizedName","has","Error","owner","undefined","length","v","parts","$ref","oldName","newName","entries","schema","isCompositeSchema","allOf","anyOf","oneOf","preferredJsonMediaType","mediaTypes","find","mediaType","split","endsWith","FORM_MEDIA_TYPES","isFormMediaType","includes","isBinaryContentMediaType","contentMediaType","startsWith","markFormBinaryFields","values","properties","prop","s","type","format","contentEncoding","hasSubSchemasToVisit","not","enum","filterInlineCompositeSchemas","nameParts","namePartPrefix","propPath","inlineSchemaIndex","flatMap","i","subSchema","title","createUniqueModelName","seenModelNameCounts","candidateName","map","join","seenModelNameCount","hoistInlineObjectSubSchemas","inlineSubSchemas","items","prefixItems","filter","additionalProperties","patternProperties","pattern","recursiveRefs","refs","ref","structuredClone","schemaWithPropToReplace","slice","reduce","resolvedInSchema","pathPart","rewriteConstToEnum","rewrite","Array","isArray","const","constValue","rest","rewriteCompositeSiblingProperties","required","_type","rewriteMultiTypeToAnyOf","nullable","nonNull","t","isNullable","inlinePathItemRefs","paths","path","pathItem","normaliseOpenApiSpecForCodeGen","inSpec","seenOperationIds","duplicatedOperationIds","pathOps","method","op","operation","operationId","add","clear","untagged","Symbol","seenOperationIdsByTag","tags","deduplicatedOpId","deduplicatedDotNotationOpId","tag","String","responses","code","res","response","jsonMediaType","content","jsonResponseSchema","schemaName","streamingContent","itemSchema","requestBody","contentMediaTypes","bodyMediaType","bodyContentSchema","resolved","parameters","p","param","paramSchema","in","fromEntries","inlinedRefs"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,mBAAmB,uBAAuB;AAEjD,SACEC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,UAAU,QACL,uBAAoB;AAC3B,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,KAAK,EAAEC,YAAY,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,YAAS;AAenE;;;;CAIC,GACD,MAA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,CAAC,EAAE,KAAK,gBACbA,KAAK,CAAC,EAAE,KAAK,WACb;YACA,OAAOnB,KAAKK,UAAU,CAAEC,OAAO,AAAC,CAACa,KAAK,CAAC,EAAE,CAAC;QAC5C;IACF;IAEA,OAAOnB;AACT,EAAE"}
@@ -53,23 +53,17 @@ const compositeMembers = (schema)=>schema.allOf ?? schema.anyOf ?? schema.oneOf
53
53
  return !hasProperties && !schema.patternProperties;
54
54
  };
55
55
  /**
56
- * The internal primitive type name for a primitive schema.
56
+ * The internal primitive type name for a primitive schema. A `string` field
57
+ * denotes raw binary content (rendered as a `Blob`) only via `format: binary`.
58
+ * The 3.1 `contentMediaType` idiom is ambiguous in isolation — FastAPI emits it
59
+ * both for multipart file fields (binary) and for `bytes` in a JSON body
60
+ * (base64 string) — so `normalise` rewrites it to `format: binary` for form
61
+ * bodies only, and this stays context-free.
57
62
  */ const primitiveType = (schema)=>{
58
63
  const type = primaryType(schema);
59
- if (type === 'string' && isBinaryStringSchema(schema)) return 'binary';
64
+ if (type === 'string' && schema.format === 'binary') return 'binary';
60
65
  return (type && PRIMITIVE_TYPE_MAP[type]) ?? 'unknown';
61
66
  };
62
- /**
63
- * Whether a `string` schema denotes raw binary content (rendered as a `Blob`).
64
- * Covers the 3.0 `format: binary` idiom and the 3.1 `contentMediaType` idiom
65
- * (as emitted by FastAPI for `UploadFile`). A base64 `contentEncoding`, or a
66
- * textual/JSON media type, keeps the value a string on the wire.
67
- */ const isBinaryStringSchema = (schema)=>{
68
- if (schema.format === 'binary') return true;
69
- const contentMediaType = schema.contentMediaType;
70
- if (!contentMediaType || schema.contentEncoding) return false;
71
- return !(contentMediaType.startsWith('text/') || contentMediaType === 'application/json' || contentMediaType.endsWith('+json') || contentMediaType === 'application/xml');
72
- };
73
67
  /**
74
68
  * Prefer application/json, falling back to the first declared media type.
75
69
  */ const preferredMediaType = (content)=>'application/json' in content ? 'application/json' : Object.keys(content)[0];
@@ -114,7 +108,20 @@ const parseResponseCode = (code)=>/^\d+$/.test(code) ? parseInt(code, 10) : code
114
108
  }
115
109
  const type = primaryType(schema);
116
110
  if (type === 'array') {
111
+ // A fixed-length tuple (3.1 `prefixItems`, as emitted by Pydantic for
112
+ // `tuple[A, B]`) models each element positionally in `properties`. An open
113
+ // tuple (additional `items` beyond the prefix) degrades to a plain array.
114
+ const prefixItems = schema.prefixItems;
117
115
  const items = schema.items;
116
+ if (prefixItems && prefixItems.length > 0 && !items) {
117
+ const properties = prefixItems.map((member)=>buildInlineModel(spec, member));
118
+ return {
119
+ export: 'tuple',
120
+ type: 'unknown',
121
+ properties,
122
+ imports: collectImports(properties)
123
+ };
124
+ }
118
125
  return {
119
126
  export: 'array',
120
127
  ...collectionValue(spec, items)
@@ -310,12 +317,22 @@ const buildModels = (spec)=>collapseDiscriminators(spec, Object.entries(spec.com
310
317
  if (!requestBody?.content || Object.keys(requestBody.content).length === 0) return null;
311
318
  const mediaType = preferredMediaType(requestBody.content);
312
319
  const base = buildInlineModel(spec, requestBody.content[mediaType]?.schema ?? {});
320
+ // The encoding object's per-part content types (multipart/urlencoded bodies)
321
+ const partContentTypes = Object.fromEntries(Object.entries(requestBody.content[mediaType]?.encoding ?? {}).flatMap(([prop, encoding])=>encoding.contentType ? [
322
+ [
323
+ prop,
324
+ encoding.contentType
325
+ ]
326
+ ] : []));
313
327
  return {
314
328
  ...base,
315
329
  name: 'requestBody',
316
330
  prop: 'requestBody',
317
331
  in: 'body',
318
332
  mediaType,
333
+ ...Object.keys(partContentTypes).length > 0 ? {
334
+ partContentTypes
335
+ } : {},
319
336
  isRequired: !!requestBody.required,
320
337
  description: requestBody.description ?? base.description
321
338
  };
@@ -330,14 +347,21 @@ const buildModels = (spec)=>collapseDiscriminators(spec, Object.entries(spec.com
330
347
  ]).flatMap((p)=>{
331
348
  const param = resolveIfRef(spec, p);
332
349
  if (!param) return [];
333
- const base = buildInlineModel(spec, param.schema ?? {});
350
+ // A content-based parameter declares `content` (a single media type)
351
+ // instead of `schema`; its value is serialised to that media type.
352
+ const contentMediaType = param.content ? Object.keys(param.content)[0] : undefined;
353
+ if (contentMediaType && contentMediaType !== 'application/json') {
354
+ throw new Error(`Parameter "${param.name}" declares content media type "${contentMediaType}", which is not supported (only application/json content-based parameters can be serialised)`);
355
+ }
356
+ const schema = param.schema ?? param.content?.[contentMediaType]?.schema;
357
+ const base = buildInlineModel(spec, schema ?? {});
334
358
  return [
335
359
  {
336
360
  ...base,
337
361
  name: param.name,
338
362
  prop: param.name,
339
363
  in: param.in,
340
- mediaType: null,
364
+ mediaType: param.schema ? null : contentMediaType ?? null,
341
365
  isRequired: !!param.required,
342
366
  description: param.description ? param.description : base.description
343
367
  }
@@ -491,6 +515,15 @@ const buildDefaultService = (spec)=>{
491
515
  linkModel(spec, modelsByName, model.link, schema.items, visited);
492
516
  }
493
517
  }
518
+ if (model.export === 'tuple' && 'prefixItems' in schema) {
519
+ const memberSchemas = schema.prefixItems ?? [];
520
+ model.properties.forEach((member, i)=>{
521
+ const subSchema = resolveIfRef(spec, memberSchemas[i]);
522
+ if (subSchema && !visited.has(member)) {
523
+ linkModel(spec, modelsByName, member, subSchema, visited);
524
+ }
525
+ });
526
+ }
494
527
  model.properties.filter((p)=>!visited.has(p) && schema.properties?.[trim(p.name, `"'`)]).forEach((property)=>{
495
528
  const subSchema = resolveIfRef(spec, schema.properties[trim(property.name, `"'`)]);
496
529
  linkModel(spec, modelsByName, property, subSchema, visited);