ts-openapi-codegen 2.1.0-beta.1 → 2.1.0-beta.10

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 (520) hide show
  1. package/README.md +27 -934
  2. package/README.rus.md +27 -934
  3. package/dist/cli/analyzeDiff/__tests__/analyzeDiff.cli.test.js +40 -24
  4. package/dist/cli/analyzeDiff/__tests__/analyzeDiffLomMiracles.test.d.ts +2 -0
  5. package/dist/cli/analyzeDiff/__tests__/analyzeDiffLomMiracles.test.d.ts.map +1 -0
  6. package/dist/cli/analyzeDiff/__tests__/analyzeDiffLomMiracles.test.js +47 -0
  7. package/dist/cli/analyzeDiff/__tests__/analyzeDiffRenameAndInvalidRegex.test.js +17 -7
  8. package/dist/cli/analyzeDiff/__tests__/analyzeDiffTypeCoercion.test.js +17 -7
  9. package/dist/cli/analyzeDiff/analyzeDiff.d.ts +14 -2
  10. package/dist/cli/analyzeDiff/analyzeDiff.d.ts.map +1 -1
  11. package/dist/cli/analyzeDiff/analyzeDiff.js +58 -15
  12. package/dist/cli/analyzeDiff/ciSummary.d.ts +6 -3
  13. package/dist/cli/analyzeDiff/ciSummary.d.ts.map +1 -1
  14. package/dist/cli/analyzeDiff/ciSummary.js +10 -6
  15. package/dist/cli/analyzeDiff/ignoreRules.d.ts +0 -22
  16. package/dist/cli/analyzeDiff/ignoreRules.d.ts.map +1 -1
  17. package/dist/cli/analyzeDiff/ignoreRules.js +3 -25
  18. package/dist/cli/analyzeDiff/miracles.d.ts +0 -54
  19. package/dist/cli/analyzeDiff/miracles.d.ts.map +1 -1
  20. package/dist/cli/analyzeDiff/miracles.js +1 -219
  21. package/dist/cli/analyzeDiff/specParser.d.ts +0 -13
  22. package/dist/cli/analyzeDiff/specParser.d.ts.map +1 -1
  23. package/dist/cli/analyzeDiff/specParser.js +2 -23
  24. package/dist/cli/analyzeDiff/types.d.ts +0 -42
  25. package/dist/cli/analyzeDiff/types.d.ts.map +1 -1
  26. package/dist/cli/analyzeUsage/analyzeUsage.d.ts +4 -0
  27. package/dist/cli/analyzeUsage/analyzeUsage.d.ts.map +1 -0
  28. package/dist/cli/analyzeUsage/analyzeUsage.js +60 -0
  29. package/dist/cli/analyzeUsage/core/Analyzer.d.ts +9 -0
  30. package/dist/cli/analyzeUsage/core/Analyzer.d.ts.map +1 -0
  31. package/dist/cli/analyzeUsage/core/Analyzer.js +29 -0
  32. package/dist/cli/analyzeUsage/core/ProjectContext.d.ts +10 -0
  33. package/dist/cli/analyzeUsage/core/ProjectContext.d.ts.map +1 -0
  34. package/dist/cli/analyzeUsage/core/ProjectContext.js +58 -0
  35. package/dist/cli/analyzeUsage/core/Scanner.d.ts +23 -0
  36. package/dist/cli/analyzeUsage/core/Scanner.d.ts.map +1 -0
  37. package/dist/cli/analyzeUsage/core/Scanner.js +125 -0
  38. package/dist/cli/analyzeUsage/rules/ClientRule.d.ts +14 -0
  39. package/dist/cli/analyzeUsage/rules/ClientRule.d.ts.map +1 -0
  40. package/dist/cli/analyzeUsage/rules/ClientRule.js +86 -0
  41. package/dist/cli/analyzeUsage/rules/CoverageRule.d.ts +7 -0
  42. package/dist/cli/analyzeUsage/rules/CoverageRule.d.ts.map +1 -0
  43. package/dist/cli/analyzeUsage/rules/CoverageRule.js +55 -0
  44. package/dist/cli/analyzeUsage/rules/DiagnosticsRule.d.ts +6 -0
  45. package/dist/cli/analyzeUsage/rules/DiagnosticsRule.d.ts.map +1 -0
  46. package/dist/cli/analyzeUsage/rules/DiagnosticsRule.js +63 -0
  47. package/dist/cli/analyzeUsage/rules/ImportRule.d.ts +6 -0
  48. package/dist/cli/analyzeUsage/rules/ImportRule.d.ts.map +1 -0
  49. package/dist/cli/analyzeUsage/rules/ImportRule.js +50 -0
  50. package/dist/cli/analyzeUsage/rules/ModelRule.d.ts +6 -0
  51. package/dist/cli/analyzeUsage/rules/ModelRule.d.ts.map +1 -0
  52. package/dist/cli/analyzeUsage/rules/ModelRule.js +34 -0
  53. package/dist/cli/analyzeUsage/rules/SchemaRule.d.ts +6 -0
  54. package/dist/cli/analyzeUsage/rules/SchemaRule.d.ts.map +1 -0
  55. package/dist/cli/analyzeUsage/rules/SchemaRule.js +46 -0
  56. package/dist/cli/analyzeUsage/rules/ServiceRule.d.ts +15 -0
  57. package/dist/cli/analyzeUsage/rules/ServiceRule.d.ts.map +1 -0
  58. package/dist/cli/analyzeUsage/rules/ServiceRule.js +96 -0
  59. package/dist/cli/analyzeUsage/types.d.ts +52 -0
  60. package/dist/cli/analyzeUsage/types.d.ts.map +1 -0
  61. package/dist/cli/analyzeUsage/types.js +2 -0
  62. package/dist/cli/analyzeUsage/utils/fuzzy.d.ts +5 -0
  63. package/dist/cli/analyzeUsage/utils/fuzzy.d.ts.map +1 -0
  64. package/dist/cli/analyzeUsage/utils/fuzzy.js +38 -0
  65. package/dist/cli/analyzeUsage/utils/report.d.ts +16 -0
  66. package/dist/cli/analyzeUsage/utils/report.d.ts.map +1 -0
  67. package/dist/cli/analyzeUsage/utils/report.js +85 -0
  68. package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.d.ts +2 -0
  69. package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.d.ts.map +1 -0
  70. package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.js +53 -0
  71. package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.d.ts +2 -0
  72. package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.d.ts.map +1 -0
  73. package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.js +52 -0
  74. package/dist/cli/checkAndUpdateConfig/checkConfig.d.ts +2 -1
  75. package/dist/cli/checkAndUpdateConfig/checkConfig.d.ts.map +1 -1
  76. package/dist/cli/checkAndUpdateConfig/checkConfig.js +15 -6
  77. package/dist/cli/checkAndUpdateConfig/updateConfig.d.ts +2 -1
  78. package/dist/cli/checkAndUpdateConfig/updateConfig.d.ts.map +1 -1
  79. package/dist/cli/checkAndUpdateConfig/updateConfig.js +8 -5
  80. package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.d.ts +2 -0
  81. package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.d.ts.map +1 -0
  82. package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.js +20 -0
  83. package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.d.ts +2 -0
  84. package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.d.ts.map +1 -0
  85. package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.js +35 -0
  86. package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.d.ts +2 -0
  87. package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.d.ts.map +1 -0
  88. package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.js +59 -0
  89. package/dist/cli/checkAndUpdateConfig/utils/removeDefaultConfigValues.d.ts.map +1 -1
  90. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.d.ts.map +1 -1
  91. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.js +19 -1
  92. package/dist/cli/checkAndUpdateConfig/utils/validateExecutorSetup.d.ts +6 -0
  93. package/dist/cli/checkAndUpdateConfig/utils/validateExecutorSetup.d.ts.map +1 -0
  94. package/dist/cli/checkAndUpdateConfig/utils/validateExecutorSetup.js +55 -0
  95. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.d.ts +1 -1
  96. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.d.ts.map +1 -1
  97. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.js +1 -1
  98. package/dist/cli/generateOpenApiClient/__tests__/generateOpenApiClient.strict.test.js +18 -9
  99. package/dist/cli/generateOpenApiClient/generateOpenApiClient.d.ts +2 -5
  100. package/dist/cli/generateOpenApiClient/generateOpenApiClient.d.ts.map +1 -1
  101. package/dist/cli/generateOpenApiClient/generateOpenApiClient.js +24 -20
  102. package/dist/cli/index.js +45 -9
  103. package/dist/cli/initOpenApiConfig/Types.d.ts +2 -0
  104. package/dist/cli/initOpenApiConfig/Types.d.ts.map +1 -1
  105. package/dist/cli/initOpenApiConfig/__tests__/init.test.d.ts +2 -0
  106. package/dist/cli/initOpenApiConfig/__tests__/init.test.d.ts.map +1 -0
  107. package/dist/cli/initOpenApiConfig/__tests__/init.test.js +20 -0
  108. package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.d.ts +2 -0
  109. package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.d.ts.map +1 -0
  110. package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.js +49 -0
  111. package/dist/cli/initOpenApiConfig/init.d.ts +2 -1
  112. package/dist/cli/initOpenApiConfig/init.d.ts.map +1 -1
  113. package/dist/cli/initOpenApiConfig/init.js +52 -20
  114. package/dist/cli/initOpenApiConfig/initConfig.d.ts +5 -0
  115. package/dist/cli/initOpenApiConfig/initConfig.d.ts.map +1 -1
  116. package/dist/cli/initOpenApiConfig/initConfig.js +8 -4
  117. package/dist/cli/initOpenApiConfig/initCustomRequest.d.ts +3 -2
  118. package/dist/cli/initOpenApiConfig/initCustomRequest.d.ts.map +1 -1
  119. package/dist/cli/initOpenApiConfig/initCustomRequest.js +36 -10
  120. package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.d.ts +2 -0
  121. package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.d.ts.map +1 -0
  122. package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.js +93 -0
  123. package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.d.ts +2 -0
  124. package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.d.ts.map +1 -0
  125. package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.js +45 -0
  126. package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.d.ts +2 -0
  127. package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.d.ts.map +1 -0
  128. package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.js +61 -0
  129. package/dist/cli/initOpenApiConfig/utils/buildConfig.d.ts +6 -12
  130. package/dist/cli/initOpenApiConfig/utils/buildConfig.d.ts.map +1 -1
  131. package/dist/cli/initOpenApiConfig/utils/buildConfig.js +24 -19
  132. package/dist/cli/initOpenApiConfig/utils/registerHandlebarTemplates.d.ts.map +1 -1
  133. package/dist/cli/initOpenApiConfig/utils/registerHandlebarTemplates.js +2 -0
  134. package/dist/cli/interactive/constants.d.ts +0 -4
  135. package/dist/cli/interactive/constants.d.ts.map +1 -1
  136. package/dist/cli/interactive/constants.js +1 -5
  137. package/dist/cli/previewChanges/previewChanges.d.ts +2 -1
  138. package/dist/cli/previewChanges/previewChanges.d.ts.map +1 -1
  139. package/dist/cli/previewChanges/previewChanges.js +8 -8
  140. package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.d.ts +2 -0
  141. package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.d.ts.map +1 -0
  142. package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.js +52 -0
  143. package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.d.ts +2 -0
  144. package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.d.ts.map +1 -0
  145. package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.js +43 -0
  146. package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.d.ts +2 -0
  147. package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.d.ts.map +1 -0
  148. package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.js +32 -0
  149. package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.d.ts +2 -0
  150. package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.d.ts.map +1 -0
  151. package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.js +68 -0
  152. package/dist/cli/previewChanges/utils/formatDiff.d.ts.map +1 -1
  153. package/dist/cli/previewChanges/utils/updateOutputPaths.d.ts.map +1 -1
  154. package/dist/cli/previewChanges/utils/updateOutputPaths.js +5 -12
  155. package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.d.ts +2 -0
  156. package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.d.ts.map +1 -0
  157. package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.js +36 -0
  158. package/dist/cli/schemas/__tests__/generateOptionsSchema.test.d.ts +2 -0
  159. package/dist/cli/schemas/__tests__/generateOptionsSchema.test.d.ts.map +1 -0
  160. package/dist/cli/schemas/__tests__/generateOptionsSchema.test.js +59 -0
  161. package/dist/cli/schemas/__tests__/initOptionsSchema.test.d.ts +2 -0
  162. package/dist/cli/schemas/__tests__/initOptionsSchema.test.d.ts.map +1 -0
  163. package/dist/cli/schemas/__tests__/initOptionsSchema.test.js +43 -0
  164. package/dist/cli/schemas/__tests__/previewChangesSchema.test.d.ts +2 -0
  165. package/dist/cli/schemas/__tests__/previewChangesSchema.test.d.ts.map +1 -0
  166. package/dist/cli/schemas/__tests__/previewChangesSchema.test.js +31 -0
  167. package/dist/cli/schemas/analyzeUsage.d.ts +13 -0
  168. package/dist/cli/schemas/analyzeUsage.d.ts.map +1 -0
  169. package/dist/cli/schemas/analyzeUsage.js +41 -0
  170. package/dist/cli/schemas/generate.d.ts +10 -2
  171. package/dist/cli/schemas/generate.d.ts.map +1 -1
  172. package/dist/cli/schemas/generate.js +7 -2
  173. package/dist/cli/schemas/index.d.ts +2 -2
  174. package/dist/cli/schemas/index.d.ts.map +1 -1
  175. package/dist/cli/schemas/index.js +1 -1
  176. package/dist/cli/schemas/init.d.ts +10 -0
  177. package/dist/cli/schemas/init.d.ts.map +1 -1
  178. package/dist/cli/schemas/init.js +3 -1
  179. package/dist/cli/types.d.ts +6 -0
  180. package/dist/cli/types.d.ts.map +1 -0
  181. package/dist/cli/types.js +2 -0
  182. package/dist/common/Consts.d.ts +1 -0
  183. package/dist/common/Consts.d.ts.map +1 -1
  184. package/dist/common/Consts.js +7 -3
  185. package/dist/common/Logger.d.ts.map +1 -1
  186. package/dist/common/Logger.js +3 -3
  187. package/dist/common/LoggerMessages.d.ts +71 -12
  188. package/dist/common/LoggerMessages.d.ts.map +1 -1
  189. package/dist/common/LoggerMessages.js +76 -18
  190. package/dist/common/TEslintFixOptions.d.ts +20 -0
  191. package/dist/common/TEslintFixOptions.d.ts.map +1 -0
  192. package/dist/common/TEslintFixOptions.js +15 -0
  193. package/dist/common/TRawOptions.d.ts.map +1 -1
  194. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -1
  195. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +2 -4
  196. package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts.map +1 -1
  197. package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.js +1 -1
  198. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedBase.d.ts.map +1 -1
  199. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedBase.js +1 -2
  200. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts.map +1 -1
  201. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.js +1 -1
  202. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts.map +1 -1
  203. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.js +1 -1
  204. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts.map +1 -1
  205. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV5.d.ts +10 -2
  206. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV5.d.ts.map +1 -1
  207. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV5.js +15 -5
  208. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts +18 -4
  209. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts.map +1 -1
  210. package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.js +7 -1
  211. package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
  212. package/dist/common/VersionedSchema/CommonSchemas.js +4 -2
  213. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV2.js +1 -1
  214. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV3.d.ts.map +1 -1
  215. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV3.js +1 -1
  216. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.js +1 -1
  217. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts.map +1 -1
  218. package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.d.ts.map +1 -1
  219. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV1.d.ts +2 -2
  220. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV1.d.ts.map +1 -1
  221. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV2.d.ts +2 -2
  222. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV3.js +1 -1
  223. package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts +1 -1
  224. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
  225. package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +7 -1
  226. package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.js +4 -16
  227. package/dist/common/VersionedSchema/Utils/buildVersionedSchema.d.ts.map +1 -1
  228. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts +1 -1
  229. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts.map +1 -1
  230. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.js +1 -1
  231. package/dist/common/VersionedSchema/Utils/createTrivialMigration.d.ts.map +1 -1
  232. package/dist/common/VersionedSchema/Utils/createTrivialMigration.js +1 -1
  233. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
  234. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +4 -6
  235. package/dist/common/VersionedSchema/Utils/getLatestVersionFromMigrationPlans.d.ts.map +1 -1
  236. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
  237. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +6 -8
  238. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts.map +1 -1
  239. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.js +1 -1
  240. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts.map +1 -1
  241. package/dist/common/VersionedSchema/refinements/dependentOptionsRefinement.d.ts +1 -1
  242. package/dist/common/VersionedSchema/refinements/dependentOptionsRefinement.d.ts.map +1 -1
  243. package/dist/common/utils/__tests__/eslintFix.test.js +25 -67
  244. package/dist/common/utils/__tests__/extractEslintFixOptions.test.d.ts +2 -0
  245. package/dist/common/utils/__tests__/extractEslintFixOptions.test.d.ts.map +1 -0
  246. package/dist/common/utils/__tests__/extractEslintFixOptions.test.js +28 -0
  247. package/dist/common/utils/__tests__/format.test.js +26 -17
  248. package/dist/common/utils/__tests__/prepareTempTsConfig.test.d.ts +2 -0
  249. package/dist/common/utils/__tests__/prepareTempTsConfig.test.d.ts.map +1 -0
  250. package/dist/common/utils/__tests__/prepareTempTsConfig.test.js +78 -0
  251. package/dist/common/utils/codegenTempDir.d.ts +20 -0
  252. package/dist/common/utils/codegenTempDir.d.ts.map +1 -0
  253. package/dist/common/utils/codegenTempDir.js +42 -0
  254. package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
  255. package/dist/common/utils/convertArrayToObject.js +3 -8
  256. package/dist/common/utils/eslintFix.d.ts +48 -4
  257. package/dist/common/utils/eslintFix.d.ts.map +1 -1
  258. package/dist/common/utils/eslintFix.js +121 -15
  259. package/dist/common/utils/format.d.ts +1 -1
  260. package/dist/common/utils/format.d.ts.map +1 -1
  261. package/dist/common/utils/format.js +23 -11
  262. package/dist/common/utils/jsonPath.d.ts.map +1 -1
  263. package/dist/common/utils/prepareTempEslintConfig.d.ts +18 -0
  264. package/dist/common/utils/prepareTempEslintConfig.d.ts.map +1 -0
  265. package/dist/common/utils/prepareTempEslintConfig.js +55 -0
  266. package/dist/common/utils/prepareTempTsConfig.d.ts +23 -0
  267. package/dist/common/utils/prepareTempTsConfig.d.ts.map +1 -0
  268. package/dist/common/utils/prepareTempTsConfig.js +105 -0
  269. package/dist/core/Context.d.ts.map +1 -1
  270. package/dist/core/Context.js +2 -6
  271. package/dist/core/OpenApiClient.d.ts +27 -1
  272. package/dist/core/OpenApiClient.d.ts.map +1 -1
  273. package/dist/core/OpenApiClient.js +259 -19
  274. package/dist/core/WriteClient.d.ts +84 -17
  275. package/dist/core/WriteClient.d.ts.map +1 -1
  276. package/dist/core/WriteClient.js +96 -22
  277. package/dist/core/__tests__/WriteClient.test.js +2 -1
  278. package/dist/core/api/v2/parser/getOperationResponses.d.ts.map +1 -1
  279. package/dist/core/api/v2/parser/getOperationResponses.js +1 -3
  280. package/dist/core/api/v2/parser/getServiceName.d.ts +1 -1
  281. package/dist/core/api/v3/parser/getOperation.d.ts.map +1 -1
  282. package/dist/core/api/v3/parser/getOperationParameters.d.ts.map +1 -1
  283. package/dist/core/api/v3/parser/getOperationResponses.d.ts.map +1 -1
  284. package/dist/core/api/v3/parser/getOperationResponses.js +1 -3
  285. package/dist/core/api/v3/parser/getServiceName.d.ts +1 -1
  286. package/dist/core/governance/evaluateGovernanceRules.d.ts.map +1 -1
  287. package/dist/core/governance/evaluateGovernanceRules.js +1 -3
  288. package/dist/core/governance/loadGovernanceConfig.d.ts.map +1 -1
  289. package/dist/core/governance/loadGovernanceConfig.js +2 -4
  290. package/dist/core/plugins/GeneratorPlugin.model.d.ts.map +1 -1
  291. package/dist/core/plugins/applySemanticDiffPluginHooks.d.ts.map +1 -1
  292. package/dist/core/plugins/getBuiltinPlugins.d.ts.map +1 -1
  293. package/dist/core/plugins/loadGeneratorPlugins.d.ts.map +1 -1
  294. package/dist/core/plugins/loadGeneratorPlugins.js +1 -1
  295. package/dist/core/semanticDiff/__tests__/analyzeOpenApiDiff.test.js +79 -21
  296. package/dist/core/semanticDiff/__tests__/semanticDiffReportSchema.test.js +20 -1
  297. package/dist/core/semanticDiff/analyzeOpenApiDiff.d.ts +58 -6
  298. package/dist/core/semanticDiff/analyzeOpenApiDiff.d.ts.map +1 -1
  299. package/dist/core/semanticDiff/analyzeOpenApiDiff.js +47 -19
  300. package/dist/core/semanticDiff/semanticDiffReportSchema.d.ts +8 -3
  301. package/dist/core/semanticDiff/semanticDiffReportSchema.d.ts.map +1 -1
  302. package/dist/core/semanticDiff/semanticDiffReportSchema.js +139 -56
  303. package/dist/core/strict/validateOpenApiStrict.d.ts.map +1 -1
  304. package/dist/core/types/Consts.js +1 -1
  305. package/dist/core/types/DiffReport.model.d.ts +101 -0
  306. package/dist/core/types/DiffReport.model.d.ts.map +1 -0
  307. package/dist/core/types/DiffReport.model.js +5 -0
  308. package/dist/core/types/base/ClientArtifacts.model.d.ts +3 -3
  309. package/dist/core/types/base/ClientArtifacts.model.d.ts.map +1 -1
  310. package/dist/core/types/base/ExportedModel.model.d.ts +1 -1
  311. package/dist/core/types/base/ExportedModel.model.d.ts.map +1 -1
  312. package/dist/core/types/base/ExportedService.model.d.ts.map +1 -1
  313. package/dist/core/types/base/OutputPaths.model.d.ts.map +1 -1
  314. package/dist/core/types/base/PrefixArtifacts.model.d.ts.map +1 -1
  315. package/dist/core/types/base/PropertyGroup.model.d.ts +1 -1
  316. package/dist/core/types/base/SimpleClientArtifacts.model.d.ts +1 -1
  317. package/dist/core/types/base/SimpleClientArtifacts.model.d.ts.map +1 -1
  318. package/dist/core/types/base/Templates.model.d.ts +1 -0
  319. package/dist/core/types/base/Templates.model.d.ts.map +1 -1
  320. package/dist/core/types/shared/Client.model.d.ts +1 -1
  321. package/dist/core/types/shared/Client.model.d.ts.map +1 -1
  322. package/dist/core/types/shared/Model.model.d.ts +37 -1
  323. package/dist/core/types/shared/Model.model.d.ts.map +1 -1
  324. package/dist/core/utils/GenerationCache.d.ts +18 -0
  325. package/dist/core/utils/GenerationCache.d.ts.map +1 -0
  326. package/dist/core/utils/GenerationCache.js +41 -0
  327. package/dist/core/utils/__mocks__/templates.d.ts.map +1 -1
  328. package/dist/core/utils/__mocks__/templates.js +1 -0
  329. package/dist/core/utils/__tests__/GenerationCache.test.d.ts +2 -0
  330. package/dist/core/utils/__tests__/GenerationCache.test.d.ts.map +1 -0
  331. package/dist/core/utils/__tests__/GenerationCache.test.js +37 -0
  332. package/dist/core/utils/__tests__/applyDiffReportToClient.test.js +182 -0
  333. package/dist/core/utils/__tests__/buildMiraclesFromSemanticChanges.test.d.ts +2 -0
  334. package/dist/core/utils/__tests__/buildMiraclesFromSemanticChanges.test.d.ts.map +1 -0
  335. package/dist/core/utils/__tests__/buildMiraclesFromSemanticChanges.test.js +77 -0
  336. package/dist/core/utils/__tests__/expandOpenApiRefsForSemanticDiff.test.d.ts +2 -0
  337. package/dist/core/utils/__tests__/expandOpenApiRefsForSemanticDiff.test.d.ts.map +1 -0
  338. package/dist/core/utils/__tests__/expandOpenApiRefsForSemanticDiff.test.js +159 -0
  339. package/dist/core/utils/__tests__/loadDiffReport.test.d.ts +2 -0
  340. package/dist/core/utils/__tests__/loadDiffReport.test.d.ts.map +1 -0
  341. package/dist/core/utils/__tests__/loadDiffReport.test.js +246 -0
  342. package/dist/core/utils/__tests__/modelHelpers.test.js +27 -9
  343. package/dist/core/utils/__tests__/postProcessModelImports.test.js +1 -4
  344. package/dist/core/utils/__tests__/postProcessServiceImports.test.js +1 -4
  345. package/dist/core/utils/__tests__/prepareDtoModels.test.js +168 -1
  346. package/dist/core/utils/__tests__/registerHandlebarHelpers.test.js +27 -0
  347. package/dist/core/utils/__tests__/resolveClassesModeTypes.test.d.ts +2 -0
  348. package/dist/core/utils/__tests__/resolveClassesModeTypes.test.d.ts.map +1 -0
  349. package/dist/core/utils/__tests__/resolveClassesModeTypes.test.js +111 -0
  350. package/dist/core/utils/__tests__/semanticChangesToDiffEntries.test.d.ts +2 -0
  351. package/dist/core/utils/__tests__/semanticChangesToDiffEntries.test.d.ts.map +1 -0
  352. package/dist/core/utils/__tests__/semanticChangesToDiffEntries.test.js +68 -0
  353. package/dist/core/utils/__tests__/serviceHelpers.test.js +10 -11
  354. package/dist/core/utils/__tests__/sortByRequiredExtended.test.js +10 -27
  355. package/dist/core/utils/__tests__/templateRendering.test.d.ts +2 -0
  356. package/dist/core/utils/__tests__/templateRendering.test.d.ts.map +1 -0
  357. package/dist/core/utils/__tests__/templateRendering.test.js +190 -0
  358. package/dist/core/utils/__tests__/writeFileIfChanged.test.d.ts +2 -0
  359. package/dist/core/utils/__tests__/writeFileIfChanged.test.d.ts.map +1 -0
  360. package/dist/core/utils/__tests__/writeFileIfChanged.test.js +30 -0
  361. package/dist/core/utils/adapters/__tests__/semanticToStructural.test.d.ts +2 -0
  362. package/dist/core/utils/adapters/__tests__/semanticToStructural.test.d.ts.map +1 -0
  363. package/dist/core/utils/adapters/__tests__/semanticToStructural.test.js +63 -0
  364. package/dist/core/utils/adapters/extractMiraclesFromSemantic.d.ts +10 -0
  365. package/dist/core/utils/adapters/extractMiraclesFromSemantic.d.ts.map +1 -0
  366. package/dist/core/utils/adapters/extractMiraclesFromSemantic.js +13 -0
  367. package/dist/core/utils/adapters/index.d.ts +3 -0
  368. package/dist/core/utils/adapters/index.d.ts.map +1 -0
  369. package/dist/core/utils/adapters/index.js +6 -0
  370. package/dist/core/utils/adapters/semanticToStructural.d.ts +12 -0
  371. package/dist/core/utils/adapters/semanticToStructural.d.ts.map +1 -0
  372. package/dist/core/utils/adapters/semanticToStructural.js +36 -0
  373. package/dist/core/utils/applyDiffReportToClient.d.ts +13 -1
  374. package/dist/core/utils/applyDiffReportToClient.d.ts.map +1 -1
  375. package/dist/core/utils/applyDiffReportToClient.js +189 -109
  376. package/dist/core/utils/areEqual.d.ts +1 -1
  377. package/dist/core/utils/buildMiraclesFromSemanticChanges.d.ts +25 -0
  378. package/dist/core/utils/buildMiraclesFromSemanticChanges.d.ts.map +1 -0
  379. package/dist/core/utils/buildMiraclesFromSemanticChanges.js +146 -0
  380. package/dist/core/utils/expandOpenApiRefsForSemanticDiff.d.ts +23 -0
  381. package/dist/core/utils/expandOpenApiRefsForSemanticDiff.d.ts.map +1 -0
  382. package/dist/core/utils/expandOpenApiRefsForSemanticDiff.js +163 -0
  383. package/dist/core/utils/getOpenApiSpec.d.ts +6 -0
  384. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  385. package/dist/core/utils/getOpenApiSpec.js +6 -0
  386. package/dist/core/utils/getOperationErrors.d.ts +2 -2
  387. package/dist/core/utils/getOperationErrors.d.ts.map +1 -1
  388. package/dist/core/utils/getOperationResults.d.ts +1 -1
  389. package/dist/core/utils/getPropertyGroupSimple.d.ts.map +1 -1
  390. package/dist/core/utils/getPropertyGroupSimple.js +1 -3
  391. package/dist/core/utils/isSubdirectory.d.ts.map +1 -1
  392. package/dist/core/utils/loadDiffReport.d.ts +11 -30
  393. package/dist/core/utils/loadDiffReport.d.ts.map +1 -1
  394. package/dist/core/utils/loadDiffReport.js +75 -9
  395. package/dist/core/utils/loadSemanticOpenApiSpec.d.ts +15 -0
  396. package/dist/core/utils/loadSemanticOpenApiSpec.d.ts.map +1 -0
  397. package/dist/core/utils/loadSemanticOpenApiSpec.js +61 -0
  398. package/dist/core/utils/modelHelpers.d.ts +13 -5
  399. package/dist/core/utils/modelHelpers.d.ts.map +1 -1
  400. package/dist/core/utils/modelHelpers.js +28 -23
  401. package/dist/core/utils/normalizeString.d.ts.map +1 -1
  402. package/dist/core/utils/normalizeString.js +1 -5
  403. package/dist/core/utils/postProcessServiceImports.d.ts.map +1 -1
  404. package/dist/core/utils/postProcessServiceImports.js +1 -3
  405. package/dist/core/utils/precompileTemplates.js +4 -2
  406. package/dist/core/utils/prepareAlias.d.ts +1 -1
  407. package/dist/core/utils/prepareDtoModels.d.ts +5 -0
  408. package/dist/core/utils/prepareDtoModels.d.ts.map +1 -1
  409. package/dist/core/utils/prepareDtoModels.js +57 -20
  410. package/dist/core/utils/registerHandlebarHelpers.d.ts +1 -0
  411. package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
  412. package/dist/core/utils/registerHandlebarHelpers.js +3 -0
  413. package/dist/core/utils/registerHandlebarTemplates.d.ts +1 -0
  414. package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
  415. package/dist/core/utils/registerHandlebarTemplates.js +2 -0
  416. package/dist/core/utils/resolveClassesModeTypes.d.ts +8 -0
  417. package/dist/core/utils/resolveClassesModeTypes.d.ts.map +1 -0
  418. package/dist/core/utils/resolveClassesModeTypes.js +77 -0
  419. package/dist/core/utils/semanticChangesToDiffEntries.d.ts +28 -0
  420. package/dist/core/utils/semanticChangesToDiffEntries.d.ts.map +1 -0
  421. package/dist/core/utils/semanticChangesToDiffEntries.js +98 -0
  422. package/dist/core/utils/semanticPointerToJsonPath.d.ts +7 -0
  423. package/dist/core/utils/semanticPointerToJsonPath.d.ts.map +1 -0
  424. package/dist/core/utils/semanticPointerToJsonPath.js +67 -0
  425. package/dist/core/utils/serviceHelpers.d.ts +6 -7
  426. package/dist/core/utils/serviceHelpers.d.ts.map +1 -1
  427. package/dist/core/utils/serviceHelpers.js +8 -25
  428. package/dist/core/utils/sortModelByName.d.ts +1 -1
  429. package/dist/core/utils/validateRawOptions.js +2 -2
  430. package/dist/core/utils/writeClientCore.d.ts +2 -0
  431. package/dist/core/utils/writeClientCore.d.ts.map +1 -1
  432. package/dist/core/utils/writeClientCore.js +43 -21
  433. package/dist/core/utils/writeClientCoreIndex.d.ts.map +1 -1
  434. package/dist/core/utils/writeClientCoreIndex.js +14 -4
  435. package/dist/core/utils/writeClientExecutor.d.ts +1 -3
  436. package/dist/core/utils/writeClientExecutor.d.ts.map +1 -1
  437. package/dist/core/utils/writeClientExecutor.js +6 -11
  438. package/dist/core/utils/writeClientFullIndex.js +4 -4
  439. package/dist/core/utils/writeClientModels.d.ts +1 -2
  440. package/dist/core/utils/writeClientModels.d.ts.map +1 -1
  441. package/dist/core/utils/writeClientModels.js +14 -16
  442. package/dist/core/utils/writeClientModelsIndex.d.ts +1 -1
  443. package/dist/core/utils/writeClientModelsIndex.d.ts.map +1 -1
  444. package/dist/core/utils/writeClientModelsIndex.js +14 -4
  445. package/dist/core/utils/writeClientSchemas.d.ts +1 -3
  446. package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
  447. package/dist/core/utils/writeClientSchemas.js +9 -14
  448. package/dist/core/utils/writeClientSchemasIndex.d.ts.map +1 -1
  449. package/dist/core/utils/writeClientSchemasIndex.js +14 -4
  450. package/dist/core/utils/writeClientServices.d.ts +15 -16
  451. package/dist/core/utils/writeClientServices.d.ts.map +1 -1
  452. package/dist/core/utils/writeClientServices.js +12 -19
  453. package/dist/core/utils/writeClientServicesIndex.d.ts.map +1 -1
  454. package/dist/core/utils/writeClientServicesIndex.js +14 -4
  455. package/dist/core/utils/writeClientSimpleIndex.js +4 -4
  456. package/dist/core/utils/writeFileIfChanged.d.ts +3 -0
  457. package/dist/core/utils/writeFileIfChanged.d.ts.map +1 -0
  458. package/dist/core/utils/writeFileIfChanged.js +22 -0
  459. package/dist/templatesCompiled/cli/customCreateExecutorAdapter.d.ts +8 -0
  460. package/dist/templatesCompiled/cli/customCreateExecutorAdapter.d.ts.map +1 -0
  461. package/dist/templatesCompiled/cli/customCreateExecutorAdapter.js +18 -0
  462. package/dist/templatesCompiled/cli/customRequest.js +7 -7
  463. package/dist/templatesCompiled/cli/customRequestExecutor.js +7 -7
  464. package/dist/templatesCompiled/client/core/ApiError.js +1 -1
  465. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts +0 -6
  466. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts.map +1 -1
  467. package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.js +3 -22
  468. package/dist/templatesCompiled/client/core/executor/legacyRequestAdapter.d.ts +11 -0
  469. package/dist/templatesCompiled/client/core/executor/legacyRequestAdapter.d.ts.map +1 -0
  470. package/dist/templatesCompiled/client/core/executor/legacyRequestAdapter.js +28 -0
  471. package/dist/templatesCompiled/client/core/executor/requestExecutor.d.ts +2 -0
  472. package/dist/templatesCompiled/client/core/executor/requestExecutor.d.ts.map +1 -1
  473. package/dist/templatesCompiled/client/core/executor/requestExecutor.js +8 -2
  474. package/dist/templatesCompiled/client/core/functions/catchErrors.js +1 -1
  475. package/dist/templatesCompiled/client/core/interceptors/apiErrorInterceptor.js +1 -1
  476. package/dist/templatesCompiled/client/core/interceptors/interceptors.js +1 -1
  477. package/dist/templatesCompiled/client/core/interceptors/withInterceptors.js +1 -1
  478. package/dist/templatesCompiled/client/exportClient.d.ts +0 -4
  479. package/dist/templatesCompiled/client/exportClient.d.ts.map +1 -1
  480. package/dist/templatesCompiled/client/exportClient.js +9 -45
  481. package/dist/templatesCompiled/client/exportModels.d.ts +17 -11
  482. package/dist/templatesCompiled/client/exportModels.d.ts.map +1 -1
  483. package/dist/templatesCompiled/client/exportModels.js +96 -49
  484. package/dist/templatesCompiled/client/exportService.d.ts +13 -10
  485. package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
  486. package/dist/templatesCompiled/client/exportService.js +95 -67
  487. package/dist/templatesCompiled/client/indexCore.js +4 -4
  488. package/dist/templatesCompiled/client/indexFull.js +8 -8
  489. package/dist/templatesCompiled/client/indexSimple.js +2 -2
  490. package/dist/templatesCompiled/client/partials/header.d.ts +1 -0
  491. package/dist/templatesCompiled/client/partials/header.d.ts.map +1 -1
  492. package/dist/templatesCompiled/client/partials/header.js +11 -2
  493. package/dist/test/helpers/silenceLoggers.d.ts +11 -0
  494. package/dist/test/helpers/silenceLoggers.d.ts.map +1 -0
  495. package/dist/test/helpers/silenceLoggers.js +88 -0
  496. package/package.json +132 -136
  497. package/dist/cli/analyzeDiff/buildLegacyReport.d.ts +0 -17
  498. package/dist/cli/analyzeDiff/buildLegacyReport.d.ts.map +0 -1
  499. package/dist/cli/analyzeDiff/buildLegacyReport.js +0 -54
  500. package/dist/cli/analyzeDiff/diffEngine.d.ts +0 -54
  501. package/dist/cli/analyzeDiff/diffEngine.d.ts.map +0 -1
  502. package/dist/cli/analyzeDiff/diffEngine.js +0 -209
  503. package/dist/cli/analyzeDiff/logLegacyReport.d.ts +0 -6
  504. package/dist/cli/analyzeDiff/logLegacyReport.d.ts.map +0 -1
  505. package/dist/cli/analyzeDiff/logLegacyReport.js +0 -29
  506. package/dist/cli/analyzeDiff/report.d.ts +0 -3
  507. package/dist/cli/analyzeDiff/report.d.ts.map +0 -1
  508. package/dist/cli/analyzeDiff/report.js +0 -7
  509. package/dist/cli/analyzeDiff/writeLegacyReport.d.ts +0 -6
  510. package/dist/cli/analyzeDiff/writeLegacyReport.d.ts.map +0 -1
  511. package/dist/cli/analyzeDiff/writeLegacyReport.js +0 -21
  512. package/dist/common/VersionedSchema/refinements/singleOrMultiRefinement.d.ts +0 -4
  513. package/dist/common/VersionedSchema/refinements/singleOrMultiRefinement.d.ts.map +0 -1
  514. package/dist/common/VersionedSchema/refinements/singleOrMultiRefinement.js +0 -21
  515. package/dist/common/utils/normalizeObject.d.ts +0 -2
  516. package/dist/common/utils/normalizeObject.d.ts.map +0 -1
  517. package/dist/common/utils/normalizeObject.js +0 -63
  518. package/dist/core/utils/appendUniqueLinesToFile.d.ts +0 -2
  519. package/dist/core/utils/appendUniqueLinesToFile.d.ts.map +0 -1
  520. package/dist/core/utils/appendUniqueLinesToFile.js +0 -24
package/README.md CHANGED
@@ -14,7 +14,6 @@
14
14
  ![lines-image]
15
15
  ![Minimum node.js version](https://badgen.net/npm/node/next)
16
16
 
17
-
18
17
  > Node.js library that generates Typescript clients based on the OpenAPI specification.
19
18
 
20
19
  ## Why?
@@ -28,953 +27,47 @@
28
27
  - Supports tsc and @babel/plugin-transform-typescript
29
28
  - Supports customization names of models
30
29
  - Supports external references using [`swagger-parser`](https://github.com/APIDevTools/swagger-parser/)
30
+ - Supports strict OpenAPI diagnostics with JSON reports (`--strict-openapi`, `--report-file`)
31
+ - Supports generator plugins (`plugins`) including built-in `x-typescript-type`
31
32
  - Supports binary request/response generation (`format: binary` -> `Blob`)
33
+ - Supports opt-in generation cache and incremental writes (`--cache`, `--cachePath`, `--cacheStrategy`, `--cacheDebug`)
34
+ - Generated services accept a `RequestExecutor` in the constructor (`request` / `requestRaw`, interceptors, `customExecutorPath` / `createExecutorAdapter`, `createLegacyRequestAdapter`)
35
+ - CLI `init --requestFormat` scaffolds custom HTTP layers: legacy transport, `createExecutorAdapter`, or standalone `RequestExecutor`
36
+ - `check-config` validates `request` / `customExecutorPath` file presence and `createExecutorAdapter` export
37
+ - Optional output formatting via `prettierConfigPath` (explicit Prettier config file)
38
+ - Optional batch ESLint `--fix` after generation when both `tsconfigPath` and `eslintConfigPath` are set
39
+ - Supports unified `analyze-diff` report (`schemaVersion: 2.0.0`) with separate `semantic` (CI/governance) and `structural` (generation) sections
40
+ - Restores `generate --useHistory` compatibility with semantic diff reports (ghost operations/properties, coercion, rename miracles)
41
+ - Uses selective OpenAPI `$ref` expansion in analyze-diff for faster and safer comparison
42
+ - Automatic RENAME / TYPE_COERCION miracle detection from semantic property changes
32
43
 
33
44
  ## Install
34
45
 
35
- ```
36
- npm install ts-openapi-codegen --save-dev
37
- ```
38
-
39
-
40
- ## Usage
41
-
42
- The CLI tool supports six commands: `generate`, `check-config`, `update-config`, `init`, `preview-changes`, and `analyze-diff`.
43
-
44
- ### Command: `generate`
45
-
46
- Generates TypeScript client code based on OpenAPI specifications.
47
-
48
- **Basic usage:**
49
- ```bash
50
- openapi generate --input ./spec.json --output ./dist
51
- ```
52
-
53
- **All available options:**
54
-
55
- | Option | Short | Type | Default | Description |
56
- |--------|-------|------|---------|-------------|
57
- | `--input` | `-i` | string | - | OpenAPI specification (path, URL, or string content) - **required** |
58
- | `--output` | `-o` | string | - | Output directory - **required** |
59
- | `--openapi-config` | `-ocn` | string | `openapi.config.json` | Path to configuration file |
60
- | `--outputCore` | `-oc` | string | `{output}` | Output directory for core files |
61
- | `--outputServices` | `-os` | string | `{output}` | Output directory for services |
62
- | `--outputModels` | `-om` | string | `{output}` | Output directory for models |
63
- | `--outputSchemas` | `-osm` | string | `{output}` | Output directory for schemas |
64
- | `--httpClient` | `-c` | string | `fetch` | HTTP client to generate: `fetch`, `xhr`, `node`, or `axios` |
65
- | `--useOptions` | - | boolean | `false` | Use options instead of arguments |
66
- | `--useUnionTypes` | - | boolean | `false` | Use union types instead of enums |
67
- | `--excludeCoreServiceFiles` | - | boolean | `false` | Exclude generation of core and service files |
68
- | `--request` | - | string | - | Path to custom request file |
69
- | `--customExecutorPath` | - | string | - | Path to custom `createExecutorAdapter` module |
70
- | `--interfacePrefix` | - | string | `I` | Prefix for interface models |
71
- | `--enumPrefix` | - | string | `E` | Prefix for enum models |
72
- | `--typePrefix` | - | string | `T` | Prefix for type models |
73
- | `--useCancelableRequest` | - | boolean | `false` | Use cancelable promise as return type |
74
- | `--sortByRequired` | `-s` | boolean | `false` | Use extended sorting strategy for function arguments |
75
- | `--useSeparatedIndexes` | - | boolean | `false` | Use separate index files for core, models, schemas, and services |
76
- | `--logLevel` | `-l` | string | `error` | Logging level: `info`, `warn`, or `error` |
77
- | `--logTarget` | `-t` | string | `console` | Logging target: `console` or `file` |
78
- | `--validationLibrary` | - | string | `none` | Validation library for schema generation: `none`, `zod`, `joi`, `yup`, or `jsonschema` |
79
- | `--emptySchemaStrategy` | - | string | `keep` | Strategy for empty schemas: `keep`, `semantic`, or `skip` |
80
- | `--modelsMode` | - | string | `interfaces` | Models generation mode: `interfaces` or `classes` |
81
- | `--useHistory` | - | boolean | `false` | Apply diff report annotations during generation |
82
- | `--diffReport` | - | string | `./openapi-diff-report.json` | Path to diff report JSON |
83
-
84
- **Examples:**
85
- ```bash
86
- # Basic generation
87
- openapi generate --input ./spec.json --output ./dist
88
-
89
- # With custom HTTP client
90
- openapi generate --input ./spec.json --output ./dist --httpClient axios
91
-
92
- # With configuration file
93
- openapi generate --openapi-config ./my-config.json
94
-
95
- # With all options via CLI
96
- openapi generate \
97
- --input ./spec.json \
98
- --output ./dist \
99
- --httpClient fetch \
100
- --useOptions \
101
- --useUnionTypes \
102
- --logLevel info
103
- ```
104
-
105
- ### Command: `check-config`
106
-
107
- Validates the configuration file structure and values.
108
-
109
- **Usage:**
110
- ```bash
111
- openapi check-config
112
- openapi check-config --openapi-config ./custom-config.json
113
- ```
114
-
115
- **Options:**
116
- - `--openapi-config` / `-ocn` - Path to configuration file (default: `openapi.config.json`)
117
-
118
- ### Command: `update-config`
119
-
120
- Updates the configuration file to the latest supported schema version.
121
-
122
- **Usage:**
123
- ```bash
124
- openapi update-config
125
- openapi update-config --openapi-config ./custom-config.json
126
- ```
127
-
128
- **Options:**
129
- - `--openapi-config` / `-ocn` - Path to configuration file (default: `openapi.config.json`)
130
-
131
- ### Command: `init`
132
-
133
- Generates a configuration file template.
134
-
135
- **Usage:**
136
46
  ```bash
137
- # Generate config using default settings
138
- openapi init
139
-
140
- # Custom config file name
141
- openapi init --openapi-config ./my-config.json
142
-
143
- # Specify directory with OpenAPI specs
144
- openapi init --specs-dir ./openapi
145
- ```
146
-
147
- **Options:**
148
- - `--openapi-config` / `-ocn` - Path to output configuration file (default: `openapi.config.json`)
149
- - `--specs-dir` / `-sd` - Directory with OpenAPI specification files (default: `./openapi`)
150
- - `--request` - Path to custom request file
151
- - `--useCancelableRequest` - Generate cancelable request handling
152
- - `--useInteractiveMode` - Enable interactive mode for guided setup
153
-
154
- ### Command: `preview-changes`
155
-
156
- Previews differences between already generated code and newly generated output without overwriting your current generated directory.
157
-
158
- **Usage:**
159
- ```bash
160
- openapi preview-changes
161
- openapi preview-changes --openapi-config ./custom-config.json
162
- ```
163
-
164
- **Options:**
165
- - `--openapi-config` / `-ocn` - Path to configuration file (default: `openapi.config.json`)
166
- - `--generated-dir` / `-gd` - Directory with current generated files (default: `./generated`)
167
- - `--preview-dir` / `-pd` - Temporary preview generation directory (default: `./.ts-openapi-codegen-preview-changes`)
168
- - `--diff-dir` / `-dd` - Directory for diff reports (default: `./.ts-openapi-codegen-diff-changes`)
169
-
170
- ### Command: `analyze-diff`
171
-
172
- Analyzes differences between two OpenAPI specifications and produces a JSON report.
173
-
174
- **Usage:**
175
- ```bash
176
- openapi analyze-diff --input ./openapi/current.yaml --compare-with ./openapi/previous.yaml --output-report ./openapi-diff-report.json
177
- openapi analyze-diff --input ./openapi/spec.yaml --git HEAD~1
178
- ```
179
-
180
- **Options:**
181
- - `--input` / `-i` - Path to current OpenAPI specification file (required)
182
- - `--compare-with` - Path to previous OpenAPI specification file
183
- - `--git` - Git ref to read previous specification version from (e.g. `HEAD~1`)
184
- - `--output-report` - Path to save JSON diff report (default: `./openapi-diff-report.json`)
185
-
186
- #### Miracles and confirmation
187
-
188
- The diff report can contain a `miracles` section with detected renames/type-coercions. Only confirmed miracles are applied in generation.
189
-
190
- **How to confirm miracles:**
191
- 1. Run `analyze-diff` and open the generated report (default: `./openapi-diff-report.json`).
192
- 2. Find the entry in `miracles` you want to accept.
193
- 3. Change `"status": "auto-generated"` to `"status": "confirmed"` and commit the report.
194
-
195
- Example (excerpt):
196
- ```json
197
- {
198
- "miracles": [
199
- {
200
- "oldPath": "$.components.schemas.User.properties.user_name",
201
- "newPath": "$.components.schemas.User.properties.userName",
202
- "type": "RENAME",
203
- "confidence": 0.85,
204
- "status": "confirmed"
205
- }
206
- ]
207
- }
208
- ```
209
-
210
- ### Configuration File
211
-
212
- Instead of passing all options via CLI, you can use a configuration file. Create `openapi.config.json` in your project root:
213
-
214
- **Single options format:**
215
- ```json
216
- {
217
- "input": "./spec.json",
218
- "output": "./dist",
219
- "client": "fetch",
220
- "useOptions": false,
221
- "useUnionTypes": false,
222
- "excludeCoreServiceFiles": false,
223
- "interfacePrefix": "I",
224
- "enumPrefix": "E",
225
- "typePrefix": "T",
226
- "useCancelableRequest": false,
227
- "sortByRequired": false,
228
- "useSeparatedIndexes": false,
229
- "request": "./custom-request.ts",
230
- "customExecutorPath": "./custom/createExecutorAdapter.ts",
231
- "modelsMode": "interfaces",
232
- "useHistory": false,
233
- "diffReport": "./openapi-diff-report.json",
234
- "models": {
235
- "mode": "interfaces"
236
- },
237
- "analyze": {
238
- "useHistory": false,
239
- "reportPath": "./openapi-diff-report.json"
240
- },
241
- "miracles": {
242
- "enabled": true,
243
- "confidence": 1,
244
- "types": ["RENAME", "TYPE_COERCION"]
245
- }
246
- }
247
- ```
248
-
249
- **Multi-options format (with common block):**
250
- ```json
251
- {
252
- "output": "./dist",
253
- "client": "fetch",
254
- "excludeCoreServiceFiles": true,
255
- "items": [
256
- {
257
- "input": "./first.yml"
258
- },
259
- {
260
- "input": "./second.yml",
261
- "output": "./dist-v2"
262
- }
263
- ]
264
- }
265
- ```
266
-
267
- **Array format (multiple configs):**
268
- ```json
269
- [
270
- {
271
- "input": "./first.yml",
272
- "output": "./dist",
273
- "client": "xhr"
274
- },
275
- {
276
- "input": "./second.yml",
277
- "output": "./dist",
278
- "client": "fetch"
279
- }
280
- ]
281
- ```
282
-
283
- | Name | Type | Default | Description |
284
- |------|------|---------|-------------|
285
- | `input` | string | - | OpenAPI specification path/URL (required for items) |
286
- | `output` | string | - | Output directory (required) |
287
- | `outputCore` | string | `{output}` | Output directory for core files |
288
- | `outputServices` | string | `{output}` | Output directory for services |
289
- | `outputModels` | string | `{output}` | Output directory for models |
290
- | `outputSchemas` | string | `{output}` | Output directory for schemas |
291
- | `client` | string | `fetch` | HTTP client: `fetch`, `xhr`, `node`, or `axios` |
292
- | `useOptions` | boolean | `false` | Use options instead of arguments |
293
- | `useUnionTypes` | boolean | `false` | Use union types instead of enums |
294
- | `excludeCoreServiceFiles` | boolean | `false` | Exclude core and service files generation |
295
- | `request` | string | - | Path to custom request file |
296
- | `customExecutorPath` | string | - | Path to custom `createExecutorAdapter` module |
297
- | `interfacePrefix` | string | `I` | Prefix for interface models |
298
- | `enumPrefix` | string | `E` | Prefix for enum models |
299
- | `typePrefix` | string | `T` | Prefix for type models |
300
- | `useCancelableRequest` | boolean | `false` | Use cancelable promise as return type |
301
- | `sortByRequired` | boolean | `false` | Extended sorting strategy for arguments |
302
- | `useSeparatedIndexes` | boolean | `false` | Use separate index files |
303
- | `items` | array | - | Array of configurations (for multi-options format) |
304
- | `validationLibrary` | string | `none` | Validation library for schema generation: `none`, `zod`, `joi`, `yup`, or `jsonschema` |
305
- | `emptySchemaStrategy` | string | `keep` | Strategy for empty schemas: `keep`, `semantic`, or `skip` |
306
- | `modelsMode` | string | `interfaces` | Models generation mode: `interfaces` or `classes` |
307
- | `useHistory` | boolean | `false` | Apply diff report annotations during generation |
308
- | `diffReport` | string | `./openapi-diff-report.json` | Path to diff report JSON |
309
- | `models` | object | - | Models config section (e.g. `mode`) |
310
- | `analyze` | object | - | Analyze config section (e.g. reportPath, useHistory, ignore) |
311
- | `miracles` | object | - | Miracles config section (enabled, confidence, types) |
312
-
313
- **Note:** You can use the `init` command to generate a template configuration file.
314
-
315
- ## Examples
316
-
317
- ### Using CLI commands
318
-
319
- **Basic generation:**
320
- ```bash
321
- openapi generate --input ./spec.json --output ./dist
322
- ```
323
-
324
- **With configuration file:**
325
- ```bash
326
- # First, create config file
327
- openapi init
328
-
329
- # Then generate
330
- openapi generate
331
- ```
332
-
333
- **With DTO models (classes mode):**
334
- ```bash
335
- openapi generate --input ./spec.json --output ./dist --modelsMode classes
336
- ```
337
-
338
- **Generate diff report:**
339
- ```bash
340
- openapi analyze-diff --input ./openapi/current.yaml --compare-with ./openapi/previous.yaml --output-report ./openapi-diff-report.json
341
- ```
342
-
343
- **Check configuration:**
344
- ```bash
345
- openapi check-config
346
- openapi update-config
47
+ npm install ts-openapi-codegen --save-dev
347
48
  ```
348
49
 
349
- **Preview changes before applying:**
350
- ```bash
351
- openapi preview-changes
352
- ```
50
+ ## Agent Skills
353
51
 
354
- ### Using NPX
52
+ AI agents can use bundled [Agent Skills](https://agentskills.io) for RequestExecutor migration and Marauder features. After install:
355
53
 
356
54
  ```bash
357
- npx ts-openapi-codegen generate --input ./spec.json --output ./dist
358
- ```
359
-
360
- ### Using package.json scripts
361
-
362
- **package.json**
363
- ```json
364
- {
365
- "scripts": {
366
- "generate": "openapi generate --input ./spec.json --output ./dist",
367
- "generate:config": "openapi generate",
368
- "check-config": "openapi check-config",
369
- "update-config": "openapi update-config",
370
- "init-config": "openapi init",
371
- "preview-changes": "openapi preview-changes"
372
- }
373
- }
374
- ```
375
-
376
- ### Node.js API
377
-
378
- ```javascript
379
- const OpenAPI = require('ts-openapi-codegen');
380
-
381
- OpenAPI.generate({
382
- input: './spec.json',
383
- output: './dist'
384
- });
385
-
386
- // Or by providing the content of the spec directly 🚀
387
- OpenAPI.generate({
388
- input: require('./spec.json'),
389
- output: './dist'
390
- });
55
+ cp -r node_modules/ts-openapi-codegen/skills ./openapi-codegen-skills
391
56
  ```
392
57
 
58
+ See [skills/README.md](skills/README.md) for agent paths (Cursor, Claude Code, Codex) and available skills.
393
59
 
394
- ## Features
395
-
396
- ### HTTP Clients
397
-
398
- The generator supports multiple HTTP clients:
399
- - **fetch** (default) - Browser Fetch API
400
- - **xhr** - XMLHttpRequest
401
- - **node** - Node.js compatible client using `node-fetch`
402
- - **axios** - Axios HTTP client
403
-
404
- Select the client using the `--httpClient` option or `client` property in config file.
405
-
406
- ### Argument style vs. Object style `--useOptions`
407
- There's no [named parameter](https://en.wikipedia.org/wiki/Named_parameter) in JavaScript or TypeScript, because of
408
- that, we offer the flag `--useOptions` to generate code in two different styles.
409
-
410
- **Argument-style:**
411
- ```typescript
412
- function createUser(name: string, password: string, type?: string, address?: string) {
413
- // ...
414
- }
415
-
416
- // Usage
417
- createUser('Jack', '123456', undefined, 'NY US');
418
- ```
419
-
420
- **Object-style:**
421
- ```typescript
422
- function createUser({ name, password, type, address }: {
423
- name: string,
424
- password: string,
425
- type?: string
426
- address?: string
427
- }) {
428
- // ...
429
- }
430
-
431
- // Usage
432
- createUser({
433
- name: 'Jack',
434
- password: '123456',
435
- address: 'NY US'
436
- });
437
- ```
438
-
439
- ### Enums vs. Union Types `--useUnionTypes`
440
- The OpenAPI spec allows you to define [enums](https://swagger.io/docs/specification/data-models/enums/) inside the
441
- data model. By default, we convert these enums definitions to [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html).
442
- However, these enums are merged inside the namespace of the model, this is unsupported by Babel, [see docs](https://babeljs.io/docs/en/babel-plugin-transform-typescript#impartial-namespace-support).
443
- Because we also want to support projects that use Babel [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript),
444
- we offer the flag `--useUnionTypes` to generate [union types](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#union-types)
445
- instead of the traditional enums. The difference can be seen below:
446
-
447
- **Enums:**
448
- ```typescript
449
- // Model
450
- export interface Order {
451
- id?: number;
452
- quantity?: number;
453
- status?: Order.status;
454
- }
455
-
456
- export namespace Order {
457
- export enum status {
458
- PLACED = 'placed',
459
- APPROVED = 'approved',
460
- DELIVERED = 'delivered',
461
- }
462
- }
60
+ ## Documentation
463
61
 
464
- // Usage
465
- const order: Order = {
466
- id: 1,
467
- quantity: 40,
468
- status: Order.status.PLACED
469
- }
470
- ```
471
-
472
- **Union Types:**
473
- ```typescript
474
- // Model
475
- export interface Order {
476
- id?: number;
477
- quantity?: number;
478
- status?: 'placed' | 'approved' | 'delivered';
479
- }
480
-
481
- // Usage
482
- const order: Order = {
483
- id: 1,
484
- quantity: 40,
485
- status: 'placed'
486
- }
487
- ```
488
-
489
- ### Validation schemas `--validationLibrary`
490
- By default, the OpenAPI generator only exports interfaces for your models. These interfaces will help you during
491
- development, but will not be available in JavaScript during runtime. However, OpenAPI allows you to define properties
492
- that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc.
493
-
494
- The `--validationLibrary` parameter allows you to generate runtime validation schemas using popular validation libraries:
495
- - **none** (default) - No validation schemas generated
496
- - **zod** - Generate Zod validation schemas
497
- - **joi** - Generate Joi validation schemas
498
- - **yup** - Generate Yup validation schemas
499
- - **jsonschema** - Generate JSON Schema validation schemas
500
-
501
- When `--useHistory` is enabled and a diff report marks a type change, validators will attempt to coerce values:
502
- - **Zod** uses `z.coerce.*`
503
- - **Joi** uses `Joi.alternatives().try(...)`
504
- - **Yup** uses `.transform(...)`
505
- - **JSON Schema (AJV)** enables `coerceTypes`
506
-
507
- ### Models mode `--modelsMode`
508
-
509
- By default, models are generated as TypeScript interfaces/types. When `--modelsMode classes` is used, the generator produces:
510
- - `*Raw` interfaces matching the API JSON
511
- - `*Dto` classes with getters, defaults, recursive constructors, and `toJSON()`
512
-
513
- The output is consolidated into a single `models.ts` file, and `BaseDto`/`dtoUtils` are emitted in `core`.
514
-
515
- Let's say we have the following model:
516
-
517
- ```json
518
- {
519
- "MyModel": {
520
- "required": [
521
- "key",
522
- "name"
523
- ],
524
- "type": "object",
525
- "properties": {
526
- "key": {
527
- "maxLength": 64,
528
- "pattern": "^[a-zA-Z0-9_]*$",
529
- "type": "string"
530
- },
531
- "name": {
532
- "maxLength": 255,
533
- "type": "string"
534
- },
535
- "enabled": {
536
- "type": "boolean",
537
- "readOnly": true
538
- },
539
- "modified": {
540
- "type": "string",
541
- "format": "date-time",
542
- "readOnly": true
543
- }
544
- }
545
- }
546
- }
547
- ```
548
-
549
- **With Zod (`--validationLibrary zod`):**
550
-
551
- ```ts
552
- import { z } from 'zod';
553
-
554
- export const MyModelSchema = z.object({
555
- key: z.string().max(64).regex(/^[a-zA-Z0-9_]*$/),
556
- name: z.string().max(255),
557
- enabled: z.boolean().readonly().optional(),
558
- modified: z.string().datetime().readonly().optional(),
559
- });
560
-
561
- export type MyModel = z.infer<typeof MyModelSchema>;
562
-
563
- export function validateMyModel(data: unknown): MyModel {
564
- return MyModelSchema.parse(data);
565
- }
566
-
567
- export function safeValidateMyModel(data: unknown): { success: true; data: MyModel } | { success: false; error: z.ZodError } {
568
- const result = MyModelSchema.safeParse(data);
569
- if (result.success) {
570
- return { success: true, data: result.data };
571
- }
572
- return { success: false, error: result.error };
573
- }
574
- ```
575
-
576
- **With Joi (`--validationLibrary joi`):**
577
-
578
- ```ts
579
- import Joi from 'joi';
580
-
581
- export const MyModelSchema = Joi.object({
582
- key: Joi.string().max(64).pattern(/^[a-zA-Z0-9_]*$/).required(),
583
- name: Joi.string().max(255).required(),
584
- enabled: Joi.boolean().readonly(),
585
- modified: Joi.string().isoDate().readonly(),
586
- });
587
- ```
588
-
589
- **With Yup (`--validationLibrary yup`):**
590
-
591
- ```ts
592
- import * as yup from 'yup';
593
-
594
- export const MyModelSchema = yup.object({
595
- key: yup.string().max(64).matches(/^[a-zA-Z0-9_]*$/).required(),
596
- name: yup.string().max(255).required(),
597
- enabled: yup.boolean().readonly(),
598
- modified: yup.string().datetime().readonly(),
599
- });
600
- ```
601
-
602
- **With JSON Schema (`--validationLibrary jsonschema`):**
603
-
604
- ```ts
605
- export const MyModelSchema = {
606
- type: 'object',
607
- required: ['key', 'name'],
608
- properties: {
609
- key: {
610
- type: 'string',
611
- maxLength: 64,
612
- pattern: '^[a-zA-Z0-9_]*$',
613
- },
614
- name: {
615
- type: 'string',
616
- maxLength: 255,
617
- },
618
- enabled: {
619
- type: 'boolean',
620
- readOnly: true,
621
- },
622
- modified: {
623
- type: 'string',
624
- format: 'date-time',
625
- readOnly: true,
626
- },
627
- },
628
- };
629
- ```
630
- These validation schemas can be used for form generation, input validation, and runtime type checking in your application.
631
-
632
- ### Cancelable promise `--useCancelableRequest`
633
- By default, the OpenAPI generator generates services for accessing the API that use non-cancellable requests. Therefore, we have added the ability to switch the generator to generate canceled API requests. To do this, use the flag `--useCancelableRequest`.
634
- An example of a cancelled request would look like this:
635
-
636
- ```typescript
637
- export function request<T>(config: TOpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> {
638
- return new CancelablePromise(async(resolve, reject, onCancel) => {
639
- const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);
640
- try {
641
- if (!onCancel.isCancelled) {
642
- const response = await sendRequest(options, url, config, onCancel);
643
- const responseBody = await getResponseBody(response);
644
- const responseHeader = getResponseHeader(response, options.responseHeader);
645
- const result: ApiResult = {
646
- url,
647
- ok: response.ok,
648
- status: response.status,
649
- statusText: response.statusText,
650
- body: responseHeader || responseBody,
651
- };
652
-
653
- catchErrors(options, result);
654
- resolve(result.body);
655
- }
656
- } catch (e) {
657
- reject(e);
658
- }
659
- });
660
- }
661
- ```
662
-
663
- ### RequestExecutor
664
-
665
- Starting from version **2.0.0** the generated services use the `RequestExecutor` interface
666
- instead of direct calls to the `request` core function.
667
-
668
- The `RequestExecutor` is a single HTTP logic integration point responsible for executing requests
669
- and extending client behavior. It allows you to:
670
- - use any transport (fetch/axios/xhr/custom);
671
- - Centrally handle requests, responses, and errors;
672
- - expand the client's behavior without changing the generated services.
673
-
674
- #### Interceptors
675
-
676
- `RequestExecutor` supports **interceptors**, which allow you to implement additional
677
- logic at different stages of the request lifecycle.:
678
-
679
- - `onRequest` — modification of the request before sending (headers, auth, logging);
680
- - `onResponse` — processing successful responses;
681
- - `onError` — centralized error handling.
682
-
683
- Interceptors are applied at the executor level and are automatically used by all
684
- generated services.
685
-
686
- ```ts
687
- import { createClient } from './generated';
688
-
689
- const client = createClient({
690
- interceptors: {
691
- onRequest: [
692
- (config) => ({
693
- ...config,
694
- headers: {
695
- ...config.headers,
696
- Authorization: 'Bearer token',
697
- },
698
- }),
699
- ],
700
- onError: [
701
- (error) => {
702
- console.error(error);
703
- throw error;
704
- },
705
- ],
706
- },
707
- });
708
- ```
709
-
710
- #### Custom implementation of RequestExecutor with interceptors
711
-
712
- A custom `RequestExecutor` can be used together with interceptors.
713
- In this case, the executor is responsible only for the transport and execution of the request,
714
- while the interceptors are responsible for the extensible business logic (authorization, logging, error handling).
715
-
716
- ```ts
717
- import type { RequestExecutor, RequestConfig } from './generated/core/executor/requestExecutor';
718
- import { withInterceptors } from './generated/core/interceptors/withInterceptors';
719
- import { SimpleService } from './generated/services/SimpleService';
720
-
721
- interface MyCustomOptions {
722
- timeout?: number;
723
- }
724
-
725
- const baseExecutor: RequestExecutor<MyCustomOptions> = {
726
- async request<T>(config: RequestConfig, options?: MyCustomOptions): Promise<T> {
727
- const response = await fetch(config.url, {
728
- method: config.method,
729
- headers: config.headers,
730
- body: config.body ? JSON.stringify(config.body) : undefined,
731
- signal: options?.timeout
732
- ? AbortSignal.timeout(options.timeout)
733
- : undefined,
734
- });
735
-
736
- if (!response.ok) {
737
- throw new Error(`Request failed: ${response.status}`);
738
- }
739
-
740
- return response.json();
741
- },
742
- };
743
-
744
- // Wrapping the executor interceptors
745
- const executor = withInterceptors(baseExecutor, {
746
- onRequest: [
747
- (config) => ({
748
- ...config,
749
- headers: {
750
- ...config.headers,
751
- Authorization: 'Bearer token',
752
- },
753
- }),
754
- ],
755
- onError: [
756
- (error) => {
757
- console.error(error);
758
- throw error;
759
- },
760
- ],
761
- });
762
-
763
- const service = new SimpleService(executor);
764
- await service.getCallWithoutParametersAndResponse({ timeout: 5000 });
765
- ```
766
-
767
- #### Using generated `createClient` with `customExecutorPath` and `executorFactory`
768
-
769
- If you set `customExecutorPath` in generation config, `createClient.ts` imports your custom
770
- `createExecutorAdapter` and uses it as the default executor.
771
-
772
- You can additionally pass `executorFactory` at runtime to wrap/extend this default executor
773
- (for retry, tracing, metrics, etc.) without changing generated services.
774
-
775
- ```ts
776
- import { createClient } from './generated';
777
-
778
- const client = createClient({
779
- executorFactory: ({ openApiConfig, createDefaultExecutor }) => {
780
- const baseExecutor = createDefaultExecutor();
781
-
782
- return {
783
- async request<TResponse>(config, options) {
784
- console.debug('Request to', openApiConfig.BASE, config.path);
785
- return baseExecutor.request<TResponse>(config, options);
786
- },
787
- };
788
- },
789
- });
790
- ```
791
-
792
- ### Sorting strategy for function arguments `--sortByRequired`
793
- By default, the OpenAPI generator sorts the parameters of service functions according to a simplified scheme. If you need a more strict sorting option, then you need to use the `--sortByRequired` flag. The simplified sorting option is similar to the one used in version 0.2.3 of the OpenAPI generator. This flag allows you to upgrade to a new version of the generator if you are "stuck" on version 0.2.3.
794
-
795
- ### Separate index files `--useSeparatedIndexes`
796
- By default, the generator creates a single index file that exports all generated code. With the `--useSeparatedIndexes` flag, you can generate separate index files for core, models, schemas, and services, which can help with better code organization and tree-shaking.
797
-
798
- ### Enum with custom names and descriptions
799
- You can use `x-enum-varnames` and `x-enum-descriptions` in your spec to generate enum with custom names and descriptions.
800
- It's not in official [spec](https://github.com/OAI/OpenAPI-Specification/issues/681) yet. But it's a supported extension
801
- that can help developers use more meaningful enumerators.
802
- ```json
803
- {
804
- "EnumWithStrings": {
805
- "description": "This is a simple enum with strings",
806
- "enum": [
807
- 0,
808
- 1,
809
- 2
810
- ],
811
- "x-enum-varnames": [
812
- "Success",
813
- "Warning",
814
- "Error"
815
- ],
816
- "x-enum-descriptions": [
817
- "Used when the status of something is successful",
818
- "Used when the status of something has a warning",
819
- "Used when the status of something has an error"
820
- ]
821
- }
822
- }
823
- ```
824
-
825
- Generated code:
826
- ```typescript
827
- enum EnumWithStrings {
828
- /*
829
- * Used when the status of something is successful
830
- */
831
- Success = 0,
832
- /*
833
- * Used when the status of something has a warning
834
- */
835
- Waring = 1,
836
- /*
837
- * Used when the status of something has an error
838
- */
839
- Error = 2,
840
- }
841
- ```
842
-
843
-
844
- ### Nullable in OpenAPI v2
845
- In the OpenAPI v3 spec you can create properties that can be NULL, by providing a `nullable: true` in your schema.
846
- However, the v2 spec does not allow you to do this. You can use the unofficial `x-nullable` in your specification
847
- to generate nullable properties in OpenApi v2.
848
-
849
- ```json
850
- {
851
- "ModelWithNullableString": {
852
- "required": ["requiredProp"],
853
- "description": "This is a model with one string property",
854
- "type": "object",
855
- "properties": {
856
- "prop": {
857
- "description": "This is a simple string property",
858
- "type": "string",
859
- "x-nullable": true
860
- },
861
- "requiredProp": {
862
- "description": "This is a simple string property",
863
- "type": "string",
864
- "x-nullable": true
865
- }
866
- }
867
- }
868
- }
869
- ```
870
-
871
- Generated code:
872
- ```typescript
873
- interface ModelWithNullableString {
874
- prop?: string | null,
875
- requiredProp: string | null,
876
- }
877
- ```
878
-
879
-
880
- ### Authorization
881
- The OpenAPI generator supports Bearer Token authorization. In order to enable the sending
882
- of tokens in each request you can set the token using the global OpenAPI configuration:
883
-
884
- ```typescript
885
- import { OpenAPI } from './generated';
886
-
887
- OpenAPI.TOKEN = 'some-bearer-token';
888
- ```
889
-
890
- Alternatively, we also support an async method that provides the token for each request.
891
- You can simply assign this method to the same `TOKEN `property in the global OpenAPI object.
892
-
893
- ```typescript
894
- import { OpenAPI } from './generated';
895
-
896
- const getToken = async () => {
897
- // Some code that requests a token...
898
- return 'SOME_TOKEN';
899
- }
900
-
901
- OpenAPI.TOKEN = getToken;
902
- ```
903
-
904
- ### References
905
-
906
- Local references to schema definitions (those beginning with `#/definitions/schemas/`)
907
- will be converted to type references to the equivalent, generated top-level type.
908
-
909
- The OpenAPI generator also supports external references, which allows you to break
910
- down your openapi.yml into multiple sub-files, or incorporate third-party schemas
911
- as part of your types to ensure everything is able to be TypeScript generated.
912
-
913
- External references may be:
914
- * *relative references* - references to other files at the same location e.g.
915
- `{ $ref: 'schemas/customer.yml' }`
916
- * *remote references* - fully qualified references to another remote location
917
- e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
918
-
919
- For remote references, both files (when the file is on the current filesystem)
920
- and http(s) URLs are supported.
921
-
922
- External references may also contain internal paths in the external schema (e.g.
923
- `schemas/collection.yml#/definitions/schemas/Customer`) and back-references to
924
- the base openapi file or between files (so that you can reference another
925
- schema in the main file as a type of an object or array property, for example).
926
-
927
- At start-up, an OpenAPI or Swagger file with external references will be "bundled",
928
- so that all external references and back-references will be resolved (but local
929
- references preserved).
930
-
931
- FAQ
932
- ===
933
-
934
- ### Babel support
935
- If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
936
- as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
937
- does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
938
- to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
939
-
940
- **Note:** If you are using Babel 7 and Typescript 3.8 (or higher) then you should enable the `onlyRemoveTypeImports` to
941
- ignore any 'type only' imports, see https://babeljs.io/docs/en/babel-preset-typescript#onlyremovetypeimports for more info
942
-
943
- ```javascript
944
- module.exports = {
945
- presets: [
946
- ['@babel/preset-typescript', {
947
- onlyRemoveTypeImports: true,
948
- }],
949
- ],
950
- };
951
- ```
952
-
953
-
954
- ### Node.js support
955
- By default, this library will generate a client that is compatible with the (browser based) [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API),
956
- however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then
957
- you can specify `--httpClient node` in the openapi call:
958
-
959
- `openapi generate --input ./spec.json --output ./dist --httpClient node`
960
-
961
- This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
962
- in order to compile and run this client, you will need to install the `node-fetch` dependencies:
963
-
964
- ```
965
- npm install @types/node-fetch --save-dev
966
- npm install node-fetch --save-dev
967
- npm install form-data --save-dev
968
- ```
969
-
970
- In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`
971
- in your `tsconfig.json` file.
972
-
973
- ```json
974
- {
975
- "allowSyntheticDefaultImports": true
976
- }
977
- ```
62
+ - [Usage](docs/en/usage.md)
63
+ - [Configuration file](docs/en/configuration.md)
64
+ - [Examples](docs/en/examples.md)
65
+ - [Features](docs/en/features.md)
66
+ - [Migration guide](MIGRATION.md)
67
+ - [Plugins](docs/en/plugins.md)
68
+ - [Plugin API v2 (RFC)](docs/en/plugin-api-v2.md)
69
+ - [Русская версия README](README.rus.md)
70
+ - [Русская документация](docs/ru/usage.md)
978
71
 
979
72
  [npm-url]: https://www.npmjs.com/package/ts-openapi-codegen
980
73
  [npm-image]: https://img.shields.io/npm/v/ts-openapi-codegen.svg