ts-openapi-codegen 1.0.0-beta.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/README.md +221 -123
  2. package/README.rus.md +725 -0
  3. package/dist/cli/checkAndUpdateConfig/checkConfig.d.ts +12 -0
  4. package/dist/cli/checkAndUpdateConfig/checkConfig.d.ts.map +1 -0
  5. package/dist/cli/checkAndUpdateConfig/checkConfig.js +66 -0
  6. package/dist/cli/checkAndUpdateConfig/constants.d.ts +13 -0
  7. package/dist/cli/checkAndUpdateConfig/constants.d.ts.map +1 -0
  8. package/dist/cli/checkAndUpdateConfig/constants.js +29 -0
  9. package/dist/cli/checkAndUpdateConfig/types.d.ts +20 -0
  10. package/dist/cli/checkAndUpdateConfig/types.d.ts.map +1 -0
  11. package/dist/cli/checkAndUpdateConfig/types.js +12 -0
  12. package/dist/cli/checkAndUpdateConfig/updateConfig.d.ts +12 -0
  13. package/dist/cli/checkAndUpdateConfig/updateConfig.d.ts.map +1 -0
  14. package/dist/cli/checkAndUpdateConfig/updateConfig.js +56 -0
  15. package/dist/cli/checkAndUpdateConfig/utils/generateConfigExample.d.ts +2 -0
  16. package/dist/cli/checkAndUpdateConfig/utils/generateConfigExample.d.ts.map +1 -0
  17. package/dist/cli/checkAndUpdateConfig/utils/generateConfigExample.js +11 -0
  18. package/dist/cli/checkAndUpdateConfig/utils/prepareConfigData.d.ts +14 -0
  19. package/dist/cli/checkAndUpdateConfig/utils/prepareConfigData.d.ts.map +1 -0
  20. package/dist/cli/checkAndUpdateConfig/utils/prepareConfigData.js +30 -0
  21. package/dist/cli/checkAndUpdateConfig/utils/removeDefaultConfigValues.d.ts +17 -0
  22. package/dist/cli/checkAndUpdateConfig/utils/removeDefaultConfigValues.d.ts.map +1 -0
  23. package/dist/cli/checkAndUpdateConfig/utils/removeDefaultConfigValues.js +29 -0
  24. package/dist/cli/checkAndUpdateConfig/utils/rewriteConfigFile.d.ts +2 -0
  25. package/dist/cli/checkAndUpdateConfig/utils/rewriteConfigFile.d.ts.map +1 -0
  26. package/dist/cli/checkAndUpdateConfig/utils/rewriteConfigFile.js +11 -0
  27. package/dist/cli/checkAndUpdateConfig/utils/selectConfigAction.d.ts +29 -0
  28. package/dist/cli/checkAndUpdateConfig/utils/selectConfigAction.d.ts.map +1 -0
  29. package/dist/cli/checkAndUpdateConfig/utils/selectConfigAction.js +49 -0
  30. package/dist/cli/checkAndUpdateConfig/utils/updateExistingConfigFile.d.ts +6 -0
  31. package/dist/cli/checkAndUpdateConfig/utils/updateExistingConfigFile.d.ts.map +1 -0
  32. package/dist/cli/checkAndUpdateConfig/utils/updateExistingConfigFile.js +22 -0
  33. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.d.ts +17 -0
  34. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.d.ts.map +1 -0
  35. package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.js +53 -0
  36. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.d.ts +34 -0
  37. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.d.ts.map +1 -0
  38. package/dist/cli/checkAndUpdateConfig/utils/writeConfigFile.js +41 -0
  39. package/dist/cli/checkAndUpdateConfig/utils/writeExampleConfigFile.d.ts +6 -0
  40. package/dist/cli/checkAndUpdateConfig/utils/writeExampleConfigFile.d.ts.map +1 -0
  41. package/dist/cli/checkAndUpdateConfig/utils/writeExampleConfigFile.js +18 -0
  42. package/dist/cli/generate/runGenerateOpenApi.d.ts +2 -2
  43. package/dist/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
  44. package/dist/cli/generate/runGenerateOpenApi.js +12 -14
  45. package/dist/cli/index.d.ts +1 -0
  46. package/dist/cli/index.js +56 -30
  47. package/dist/cli/initOpenApiConfig/runInitOpenapiConfig.d.ts.map +1 -1
  48. package/dist/cli/initOpenApiConfig/runInitOpenapiConfig.js +11 -18
  49. package/dist/cli/interactive/confirmDialog.d.ts +17 -0
  50. package/dist/cli/interactive/confirmDialog.d.ts.map +1 -0
  51. package/dist/cli/interactive/confirmDialog.js +36 -0
  52. package/dist/cli/interactive/constants.d.ts +7 -0
  53. package/dist/cli/interactive/constants.d.ts.map +1 -0
  54. package/dist/cli/interactive/constants.js +25 -0
  55. package/dist/cli/interactive/selectDialog.d.ts +17 -0
  56. package/dist/cli/interactive/selectDialog.d.ts.map +1 -0
  57. package/dist/cli/interactive/selectDialog.js +43 -0
  58. package/dist/cli/interactive/types.d.ts +40 -0
  59. package/dist/cli/interactive/types.d.ts.map +1 -0
  60. package/dist/cli/interactive/types.js +12 -0
  61. package/dist/common/Consts.d.ts +23 -0
  62. package/dist/common/Consts.d.ts.map +1 -1
  63. package/dist/common/Consts.js +28 -1
  64. package/dist/common/Enums.d.ts +4 -0
  65. package/dist/common/Enums.d.ts.map +1 -1
  66. package/dist/common/Enums.js +6 -1
  67. package/dist/common/Logger.d.ts +1 -1
  68. package/dist/common/Logger.d.ts.map +1 -1
  69. package/dist/common/Logger.js +5 -38
  70. package/dist/common/UpdateNotifier.d.ts +36 -2
  71. package/dist/common/UpdateNotifier.d.ts.map +1 -1
  72. package/dist/common/UpdateNotifier.js +150 -57
  73. package/dist/common/VersionedSchema/Types.d.ts +5 -0
  74. package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
  75. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +1 -7
  76. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
  77. package/dist/common/VersionedSchema/Utils/getCurrentErrorMessage.d.ts +3 -0
  78. package/dist/common/VersionedSchema/Utils/getCurrentErrorMessage.d.ts.map +1 -0
  79. package/dist/common/VersionedSchema/Utils/getCurrentErrorMessage.js +14 -0
  80. package/dist/common/VersionedSchema/Utils/getKeyByMapValue.d.ts +2 -0
  81. package/dist/common/VersionedSchema/Utils/getKeyByMapValue.d.ts.map +1 -0
  82. package/dist/common/VersionedSchema/Utils/getKeyByMapValue.js +11 -0
  83. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts +5 -2
  84. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
  85. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +22 -15
  86. package/dist/common/utils/__tests__/__mock__/mockJoiSchema.d.ts.map +1 -0
  87. package/dist/common/utils/__tests__/convertArrayToObject.test.d.ts.map +1 -0
  88. package/dist/common/{__tests__ → utils/__tests__}/convertArrayToObject.test.js +14 -14
  89. package/dist/common/utils/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +1 -0
  90. package/dist/common/{__tests__ → utils/__tests__}/determineBestMatchingSchemaVersion.test.js +5 -5
  91. package/dist/common/utils/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +1 -0
  92. package/dist/common/{__tests__ → utils/__tests__}/generateKeyMappingForInvalidKeys.test.js +4 -4
  93. package/dist/common/utils/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +1 -0
  94. package/dist/common/{__tests__ → utils/__tests__}/getUniqueKeysFromSchemas.test.js +4 -4
  95. package/dist/common/utils/__tests__/getUniqueObjectKeys.test.d.ts.map +1 -0
  96. package/dist/common/{__tests__ → utils/__tests__}/getUniqueObjectKeys.test.js +5 -5
  97. package/dist/common/utils/__tests__/mergeObjectSchemas.test.d.ts.map +1 -0
  98. package/dist/common/{__tests__ → utils/__tests__}/mergeObjectSchemas.test.js +5 -5
  99. package/dist/common/utils/__tests__/migrationForMultiOptions.test.d.ts.map +1 -0
  100. package/dist/common/{__tests__ → utils/__tests__}/migrationForMultiOptions.test.js +21 -15
  101. package/dist/common/utils/__tests__/migrationForOptions.test.d.ts.map +1 -0
  102. package/dist/common/{__tests__ → utils/__tests__}/migrationForOptions.test.js +13 -9
  103. package/dist/common/utils/__tests__/pathHelpers.test.d.ts.map +1 -0
  104. package/dist/{core → common}/utils/__tests__/pathHelpers.test.js +8 -8
  105. package/dist/common/utils/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +1 -0
  106. package/dist/common/{__tests__ → utils/__tests__}/replaceInvalidKeysWithMappedNames.test.js +5 -5
  107. package/dist/common/utils/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +1 -0
  108. package/dist/common/{__tests__ → utils/__tests__}/validateAndSuggestKeyCorrections.test.js +5 -5
  109. package/dist/common/utils/convertArrayToObject.d.ts +2 -0
  110. package/dist/common/utils/convertArrayToObject.d.ts.map +1 -0
  111. package/dist/common/{Utils.js → utils/convertArrayToObject.js} +0 -20
  112. package/dist/{core/utils/fileSystem.d.ts → common/utils/fileSystemHelpers.d.ts} +8 -5
  113. package/dist/common/utils/fileSystemHelpers.d.ts.map +1 -0
  114. package/dist/common/utils/fileSystemHelpers.js +85 -0
  115. package/dist/common/utils/format.d.ts +3 -0
  116. package/dist/common/utils/format.d.ts.map +1 -0
  117. package/dist/{core → common}/utils/format.js +2 -2
  118. package/dist/common/utils/loadConfigIfExists.d.ts +2 -0
  119. package/dist/common/utils/loadConfigIfExists.d.ts.map +1 -0
  120. package/dist/common/utils/loadConfigIfExists.js +22 -0
  121. package/dist/common/utils/pathHelpers.d.ts +6 -0
  122. package/dist/common/utils/pathHelpers.d.ts.map +1 -0
  123. package/dist/{core → common}/utils/pathHelpers.js +16 -20
  124. package/dist/common/utils/safeHasOwn.d.ts +2 -0
  125. package/dist/common/utils/safeHasOwn.d.ts.map +1 -0
  126. package/dist/common/utils/safeHasOwn.js +9 -0
  127. package/dist/core/Context.d.ts.map +1 -1
  128. package/dist/core/Context.js +3 -3
  129. package/dist/core/WriteClient.d.ts.map +1 -1
  130. package/dist/core/WriteClient.js +18 -18
  131. package/dist/core/__tests__/WriteClient.test.js +61 -60
  132. package/dist/core/api/v2/Parser.d.ts.map +1 -1
  133. package/dist/core/api/v2/Parser.js +2 -9
  134. package/dist/core/api/v2/parser/__tests__/getServer.test.js +2 -2
  135. package/dist/core/api/v2/parser/__tests__/getType.test.js +3 -3
  136. package/dist/core/api/v2/parser/getModelProperties.d.ts.map +1 -1
  137. package/dist/core/api/v2/parser/getModelProperties.js +2 -5
  138. package/dist/core/api/v2/parser/getModels.d.ts.map +1 -1
  139. package/dist/core/api/v2/parser/getModels.js +2 -1
  140. package/dist/core/api/v2/parser/getOperationParameter.d.ts.map +1 -1
  141. package/dist/core/api/v2/parser/getOperationParameter.js +2 -1
  142. package/dist/core/api/v2/parser/getOperationResponse.d.ts.map +1 -1
  143. package/dist/core/api/v2/parser/getOperationResponse.js +2 -5
  144. package/dist/core/api/v2/parser/getOperationResponses.d.ts.map +1 -1
  145. package/dist/core/api/v2/parser/getOperationResponses.js +2 -5
  146. package/dist/core/api/v2/parser/getServices.d.ts.map +1 -1
  147. package/dist/core/api/v2/parser/getServices.js +2 -5
  148. package/dist/core/api/v2/parser/getType.js +4 -4
  149. package/dist/core/api/v3/Parser.d.ts +1 -1
  150. package/dist/core/api/v3/Parser.d.ts.map +1 -1
  151. package/dist/core/api/v3/Parser.js +2 -9
  152. package/dist/core/api/v3/parser/__tests__/getServer.test.js +3 -3
  153. package/dist/core/api/v3/parser/__tests__/getType.test.js +3 -3
  154. package/dist/core/api/v3/parser/getModelProperties.d.ts.map +1 -1
  155. package/dist/core/api/v3/parser/getModelProperties.js +2 -5
  156. package/dist/core/api/v3/parser/getModels.d.ts.map +1 -1
  157. package/dist/core/api/v3/parser/getModels.js +2 -1
  158. package/dist/core/api/v3/parser/getOperationResponse.d.ts.map +1 -1
  159. package/dist/core/api/v3/parser/getOperationResponse.js +2 -5
  160. package/dist/core/api/v3/parser/getOperationResponses.d.ts.map +1 -1
  161. package/dist/core/api/v3/parser/getOperationResponses.js +2 -5
  162. package/dist/core/api/v3/parser/getServer.d.ts.map +1 -1
  163. package/dist/core/api/v3/parser/getServer.js +2 -5
  164. package/dist/core/api/v3/parser/getServices.d.ts.map +1 -1
  165. package/dist/core/api/v3/parser/getServices.js +2 -5
  166. package/dist/core/api/v3/parser/getType.d.ts.map +1 -1
  167. package/dist/core/api/v3/parser/getType.js +5 -13
  168. package/dist/core/index.d.ts +4 -0
  169. package/dist/core/index.d.ts.map +1 -1
  170. package/dist/core/index.js +34 -27
  171. package/dist/core/types/Consts.d.ts +5 -1
  172. package/dist/core/types/Consts.d.ts.map +1 -1
  173. package/dist/core/types/Consts.js +6 -2
  174. package/dist/core/types/base/Root.model.d.ts +1 -0
  175. package/dist/core/types/base/Root.model.d.ts.map +1 -1
  176. package/dist/core/utils/__tests__/escapeDescription.test.js +3 -3
  177. package/dist/core/utils/__tests__/escapeName.test.js +2 -2
  178. package/dist/core/utils/__tests__/flatMap.test.js +2 -2
  179. package/dist/core/utils/__tests__/getAbsolutePath.test.js +6 -6
  180. package/dist/core/utils/__tests__/getClassName.test.js +2 -2
  181. package/dist/core/utils/__tests__/getComment.test.js +2 -2
  182. package/dist/core/utils/__tests__/getEnumFromDescription.test.js +2 -2
  183. package/dist/core/utils/__tests__/getFileName.test.js +2 -2
  184. package/dist/core/utils/__tests__/getGatheringRefs.test.js +2 -2
  185. package/dist/core/utils/__tests__/getMappedType.test.js +2 -2
  186. package/dist/core/utils/__tests__/getModelNames.test.js +2 -2
  187. package/dist/core/utils/__tests__/getOpenApiVersion.test.js +2 -2
  188. package/dist/core/utils/__tests__/getOperationName.test.js +2 -2
  189. package/dist/core/utils/__tests__/getOperationParameterName.test.js +2 -2
  190. package/dist/core/utils/__tests__/getOperationPath.test.js +2 -2
  191. package/dist/core/utils/__tests__/getOperationResponseCode.test.js +2 -2
  192. package/dist/core/utils/__tests__/getPattern.test.js +2 -2
  193. package/dist/core/utils/__tests__/getRefFromSchema.test.js +2 -2
  194. package/dist/core/utils/__tests__/getRefs.test.js +2 -2
  195. package/dist/core/utils/__tests__/getRelativeModelPath.test.js +3 -3
  196. package/dist/core/utils/__tests__/getServiceClassName.test.js +2 -2
  197. package/dist/core/utils/__tests__/getServiceNames.test.js +2 -2
  198. package/dist/core/utils/__tests__/getServiceVersion.test.js +2 -2
  199. package/dist/core/utils/__tests__/isString.test.js +2 -2
  200. package/dist/core/utils/__tests__/isSubdirectory.test.js +10 -10
  201. package/dist/core/utils/__tests__/registerHandlebarHelpers.test.js +2 -2
  202. package/dist/core/utils/__tests__/registerHandlebarTemplates.test.js +2 -2
  203. package/dist/core/utils/__tests__/replaceString.test.js +2 -2
  204. package/dist/core/utils/__tests__/resolveRefToImportPath.test.js +360 -51
  205. package/dist/core/utils/__tests__/sort.test.js +2 -2
  206. package/dist/core/utils/__tests__/sortByRequiredExtended.test.js +11 -11
  207. package/dist/core/utils/__tests__/sortByRequiredSimple.test.js +11 -11
  208. package/dist/core/utils/__tests__/sortModelsByName.test.js +2 -2
  209. package/dist/core/utils/__tests__/sortServicesByName.test.js +2 -2
  210. package/dist/core/utils/__tests__/stripNamespace.test.js +2 -2
  211. package/dist/core/utils/__tests__/unique.test.js +2 -2
  212. package/dist/core/utils/__tests__/writeClientCore.test.js +52 -50
  213. package/dist/core/utils/__tests__/writeClientFullIndex.test.js +39 -37
  214. package/dist/core/utils/__tests__/writeClientModels.test.js +65 -63
  215. package/dist/core/utils/__tests__/writeClientSchemas.test.js +65 -63
  216. package/dist/core/utils/__tests__/writeClientServices.test.js +60 -58
  217. package/dist/core/utils/appendUniqueLinesToFile.js +4 -4
  218. package/dist/core/utils/createNormalizedRef.js +2 -2
  219. package/dist/core/utils/getAbsolutePath.js +3 -3
  220. package/dist/core/utils/getModelNameWithPrefix.d.ts +3 -0
  221. package/dist/core/utils/getModelNameWithPrefix.d.ts.map +1 -0
  222. package/dist/core/utils/getModelNameWithPrefix.js +15 -0
  223. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  224. package/dist/core/utils/getOpenApiSpec.js +4 -4
  225. package/dist/core/utils/getOutputPaths.d.ts.map +1 -1
  226. package/dist/core/utils/getOutputPaths.js +6 -6
  227. package/dist/core/utils/getPattern.d.ts.map +1 -1
  228. package/dist/core/utils/getPattern.js +2 -1
  229. package/dist/core/utils/getRelativeModelPath.d.ts.map +1 -1
  230. package/dist/core/utils/getRelativeModelPath.js +2 -6
  231. package/dist/core/utils/isSubdirectory.d.ts.map +1 -1
  232. package/dist/core/utils/isSubdirectory.js +4 -3
  233. package/dist/core/utils/mapPathToTargetDirSafe.d.ts.map +1 -1
  234. package/dist/core/utils/mapPathToTargetDirSafe.js +11 -12
  235. package/dist/core/utils/modelHelpers.d.ts.map +1 -1
  236. package/dist/core/utils/modelHelpers.js +18 -6
  237. package/dist/core/utils/normalizeString.d.ts +2 -0
  238. package/dist/core/utils/normalizeString.d.ts.map +1 -0
  239. package/dist/core/utils/normalizeString.js +14 -0
  240. package/dist/core/utils/normalizedAbsolutePath.js +3 -3
  241. package/dist/core/utils/parseRef.d.ts.map +1 -1
  242. package/dist/core/utils/parseRef.js +7 -10
  243. package/dist/core/utils/precompileTemplates.js +14 -10
  244. package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
  245. package/dist/core/utils/registerHandlebarHelpers.js +24 -0
  246. package/dist/core/utils/replaceString.d.ts.map +1 -1
  247. package/dist/core/utils/replaceString.js +2 -1
  248. package/dist/core/utils/resolveRefPath.d.ts.map +1 -1
  249. package/dist/core/utils/resolveRefPath.js +3 -3
  250. package/dist/core/utils/resolveRefToImportPath.d.ts +8 -2
  251. package/dist/core/utils/resolveRefToImportPath.d.ts.map +1 -1
  252. package/dist/core/utils/resolveRefToImportPath.js +91 -31
  253. package/dist/core/utils/serviceHelpers.d.ts.map +1 -1
  254. package/dist/core/utils/serviceHelpers.js +2 -1
  255. package/dist/core/utils/stripNamespace.js +5 -5
  256. package/dist/core/utils/writeClientCore.d.ts.map +1 -1
  257. package/dist/core/utils/writeClientCore.js +12 -12
  258. package/dist/core/utils/writeClientCoreIndex.d.ts.map +1 -1
  259. package/dist/core/utils/writeClientCoreIndex.js +2 -2
  260. package/dist/core/utils/writeClientFullIndex.d.ts.map +1 -1
  261. package/dist/core/utils/writeClientFullIndex.js +4 -4
  262. package/dist/core/utils/writeClientModels.d.ts.map +1 -1
  263. package/dist/core/utils/writeClientModels.js +7 -7
  264. package/dist/core/utils/writeClientModelsIndex.d.ts.map +1 -1
  265. package/dist/core/utils/writeClientModelsIndex.js +2 -2
  266. package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
  267. package/dist/core/utils/writeClientSchemas.js +7 -7
  268. package/dist/core/utils/writeClientSchemasIndex.d.ts.map +1 -1
  269. package/dist/core/utils/writeClientSchemasIndex.js +2 -2
  270. package/dist/core/utils/writeClientServices.d.ts.map +1 -1
  271. package/dist/core/utils/writeClientServices.js +5 -5
  272. package/dist/core/utils/writeClientServicesIndex.d.ts.map +1 -1
  273. package/dist/core/utils/writeClientServicesIndex.js +2 -2
  274. package/dist/core/utils/writeClientSimpleIndex.d.ts.map +1 -1
  275. package/dist/core/utils/writeClientSimpleIndex.js +4 -4
  276. package/dist/templatesCompiled/client/exportModel.js +4 -4
  277. package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
  278. package/dist/templatesCompiled/client/exportService.js +12 -13
  279. package/dist/templatesCompiled/client/indexFull.d.ts.map +1 -1
  280. package/dist/templatesCompiled/client/indexFull.js +35 -29
  281. package/dist/templatesCompiled/client/partials/parameters.d.ts +3 -2
  282. package/dist/templatesCompiled/client/partials/parameters.d.ts.map +1 -1
  283. package/dist/templatesCompiled/client/partials/parameters.js +25 -20
  284. package/dist/templatesCompiled/client/partials/parametersDefinition.d.ts +4 -2
  285. package/dist/templatesCompiled/client/partials/parametersDefinition.d.ts.map +1 -1
  286. package/dist/templatesCompiled/client/partials/parametersDefinition.js +31 -10
  287. package/package.json +15 -13
  288. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.d.ts +0 -5
  289. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.d.ts.map +0 -1
  290. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.js +0 -45
  291. package/dist/common/Utils.d.ts +0 -3
  292. package/dist/common/Utils.d.ts.map +0 -1
  293. package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts.map +0 -1
  294. package/dist/common/__tests__/convertArrayToObject.test.d.ts.map +0 -1
  295. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +0 -1
  296. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +0 -1
  297. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +0 -1
  298. package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts.map +0 -1
  299. package/dist/common/__tests__/mergeObjectSchemas.test.d.ts.map +0 -1
  300. package/dist/common/__tests__/migrationForMultiOptions.test.d.ts.map +0 -1
  301. package/dist/common/__tests__/migrationForOptions.test.d.ts.map +0 -1
  302. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +0 -1
  303. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +0 -1
  304. package/dist/core/utils/__tests__/getRelativeModelImportPath.test.d.ts +0 -2
  305. package/dist/core/utils/__tests__/getRelativeModelImportPath.test.d.ts.map +0 -1
  306. package/dist/core/utils/__tests__/getRelativeModelImportPath.test.js +0 -82
  307. package/dist/core/utils/__tests__/pathHelpers.test.d.ts.map +0 -1
  308. package/dist/core/utils/fileSystem.d.ts.map +0 -1
  309. package/dist/core/utils/fileSystem.js +0 -26
  310. package/dist/core/utils/format.d.ts +0 -2
  311. package/dist/core/utils/format.d.ts.map +0 -1
  312. package/dist/core/utils/getRelativeModelImportPath.d.ts +0 -9
  313. package/dist/core/utils/getRelativeModelImportPath.d.ts.map +0 -1
  314. package/dist/core/utils/getRelativeModelImportPath.js +0 -45
  315. package/dist/core/utils/isDirectory.d.ts +0 -2
  316. package/dist/core/utils/isDirectory.d.ts.map +0 -1
  317. package/dist/core/utils/isDirectory.js +0 -13
  318. package/dist/core/utils/pathHelpers.d.ts +0 -7
  319. package/dist/core/utils/pathHelpers.d.ts.map +0 -1
  320. /package/dist/common/{__tests__ → utils/__tests__}/__mock__/mockJoiSchema.d.ts +0 -0
  321. /package/dist/common/{__tests__ → utils/__tests__}/__mock__/mockJoiSchema.js +0 -0
  322. /package/dist/common/{__tests__ → utils/__tests__}/convertArrayToObject.test.d.ts +0 -0
  323. /package/dist/common/{__tests__ → utils/__tests__}/determineBestMatchingSchemaVersion.test.d.ts +0 -0
  324. /package/dist/common/{__tests__ → utils/__tests__}/generateKeyMappingForInvalidKeys.test.d.ts +0 -0
  325. /package/dist/common/{__tests__ → utils/__tests__}/getUniqueKeysFromSchemas.test.d.ts +0 -0
  326. /package/dist/common/{__tests__ → utils/__tests__}/getUniqueObjectKeys.test.d.ts +0 -0
  327. /package/dist/common/{__tests__ → utils/__tests__}/mergeObjectSchemas.test.d.ts +0 -0
  328. /package/dist/common/{__tests__ → utils/__tests__}/migrationForMultiOptions.test.d.ts +0 -0
  329. /package/dist/common/{__tests__ → utils/__tests__}/migrationForOptions.test.d.ts +0 -0
  330. /package/dist/{core → common}/utils/__tests__/pathHelpers.test.d.ts +0 -0
  331. /package/dist/common/{__tests__ → utils/__tests__}/replaceInvalidKeysWithMappedNames.test.d.ts +0 -0
  332. /package/dist/common/{__tests__ → utils/__tests__}/validateAndSuggestKeyCorrections.test.d.ts +0 -0
package/README.md CHANGED
@@ -21,14 +21,13 @@
21
21
  - Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
22
22
  - Quick, lightweight, robust and framework agnostic 🚀
23
23
  - Supports generation of TypeScript clients
24
- - Supports generations of fetch and XHR http clients
24
+ - Supports generations of fetch, XHR, Node.js and axios http clients
25
25
  - Supports OpenAPI specification v2.0 and v3.0
26
26
  - Supports JSON and YAML files for input
27
27
  - Supports generation through CLI, Node.js and NPX
28
28
  - Supports tsc and @babel/plugin-transform-typescript
29
- - Supports axios
30
29
  - Supports customization names of models
31
- - Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/)
30
+ - Supports external references using [`swagger-parser`](https://github.com/APIDevTools/swagger-parser/)
32
31
 
33
32
  ## Install
34
33
 
@@ -39,133 +38,228 @@ npm install ts-openapi-codegen --save-dev
39
38
 
40
39
  ## Usage
41
40
 
42
- Two ways of configuration exist.
43
- First, through the command line. Second, through a configuration file.
44
-
45
- ### First
46
-
47
- ```
48
- $ openapi --help
49
-
50
- Usage: openapi [options]
51
-
52
- Options:
53
- -V, --version Output the version number
54
- -i, --input <value> OpenAPI specification, can be a path, url or string content (required)
55
- -o, --output <value> Output directory (required)
56
- -oc, --outputCore <value> Output directory for core files
57
- -os, --outputServices <value> Output directory for services
58
- -om, --outputModels <value> Output directory for models
59
- -osm, --outputSchemas <value> Output directory for schemas
60
- -c, --httpClient <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
61
- --useOptions <value> Use options instead of arguments (default: false)
62
- --useUnionTypes <value> Use union types instead of enums (default: false)
63
- --excludeCoreServiceFiles (default: false)
64
- --includeSchemasFiles (default: false)
65
- --interfacePrefix <value> Prefix for interface model(default: "I")
66
- --enumPrefix <value> Prefix for enum model(default: "E")
67
- --typePrefix <value> Prefix for type model(default: "T")
68
- --useCancelableRequest Use cancelled promise as returned data type in request(default: false)
69
- -s, --sortByRequired Property sorting strategy: simplified or extended
70
-
71
- Examples
72
- $ openapi --input ./spec.json
73
- $ openapi --input ./spec.json --output ./dist
74
- $ openapi --input ./spec.json --output ./dist --client xhr
75
- ```
76
- ### Second
77
- [In package.json add new script](./example/package.json).
78
- You should create a file in the root of a project with the name '[openapi.config.json](./example/openapi.config.json)', where you can describe configurations for several files with openapi specification.
79
- ## Example:
80
-
81
- **openapi.config.json**
41
+ The CLI tool supports three main commands: `generate`, `check-openapi-config`, and `init-openapi-config`.
42
+
43
+ ### Command: `generate`
44
+
45
+ Generates TypeScript client code based on OpenAPI specifications.
46
+
47
+ **Basic usage:**
48
+ ```bash
49
+ openapi generate --input ./spec.json --output ./dist
50
+ ```
51
+
52
+ **All available options:**
53
+
54
+ | Option | Short | Type | Default | Description |
55
+ |--------|-------|------|---------|-------------|
56
+ | `--input` | `-i` | string | - | OpenAPI specification (path, URL, or string content) - **required** |
57
+ | `--output` | `-o` | string | - | Output directory - **required** |
58
+ | `--openapi-config` | `-ocn` | string | `openapi.config.json` | Path to configuration file |
59
+ | `--outputCore` | `-oc` | string | `{output}` | Output directory for core files |
60
+ | `--outputServices` | `-os` | string | `{output}` | Output directory for services |
61
+ | `--outputModels` | `-om` | string | `{output}` | Output directory for models |
62
+ | `--outputSchemas` | `-osm` | string | `{output}` | Output directory for schemas |
63
+ | `--httpClient` | `-c` | string | `fetch` | HTTP client to generate: `fetch`, `xhr`, `node`, or `axios` |
64
+ | `--useOptions` | - | boolean | `false` | Use options instead of arguments |
65
+ | `--useUnionTypes` | - | boolean | `false` | Use union types instead of enums |
66
+ | `--excludeCoreServiceFiles` | - | boolean | `false` | Exclude generation of core and service files |
67
+ | `--includeSchemasFiles` | - | boolean | `false` | Enable generation of model validation schemas |
68
+ | `--request` | - | string | - | Path to custom request file |
69
+ | `--interfacePrefix` | - | string | `I` | Prefix for interface models |
70
+ | `--enumPrefix` | - | string | `E` | Prefix for enum models |
71
+ | `--typePrefix` | - | string | `T` | Prefix for type models |
72
+ | `--useCancelableRequest` | - | boolean | `false` | Use cancelable promise as return type |
73
+ | `--sortByRequired` | `-s` | boolean | `false` | Use extended sorting strategy for function arguments |
74
+ | `--useSeparatedIndexes` | - | boolean | `false` | Use separate index files for core, models, schemas, and services |
75
+ | `--logLevel` | `-l` | string | `error` | Logging level: `info`, `warn`, or `error` |
76
+ | `--logTarget` | `-t` | string | `console` | Logging target: `console` or `file` |
77
+
78
+ **Examples:**
79
+ ```bash
80
+ # Basic generation
81
+ openapi generate --input ./spec.json --output ./dist
82
+
83
+ # With custom HTTP client
84
+ openapi generate --input ./spec.json --output ./dist --httpClient axios
85
+
86
+ # With configuration file
87
+ openapi generate --openapi-config ./my-config.json
88
+
89
+ # With all options via CLI
90
+ openapi generate \
91
+ --input ./spec.json \
92
+ --output ./dist \
93
+ --httpClient fetch \
94
+ --useOptions \
95
+ --useUnionTypes \
96
+ --includeSchemasFiles \
97
+ --logLevel info
98
+ ```
99
+
100
+ ### Command: `check-openapi-config`
101
+
102
+ Validates the configuration file structure and values.
103
+
104
+ **Usage:**
105
+ ```bash
106
+ openapi check-openapi-config
107
+ openapi check-openapi-config --openapi-config ./custom-config.json
108
+ ```
109
+
110
+ **Options:**
111
+ - `--openapi-config` / `-ocn` - Path to configuration file (default: `openapi.config.json`)
112
+
113
+ ### Command: `init-openapi-config`
114
+
115
+ Generates a configuration file template.
116
+
117
+ **Usage:**
118
+ ```bash
119
+ # Generate single options template
120
+ openapi init-openapi-config
121
+
122
+ # Generate multi-options template
123
+ openapi init-openapi-config --type MULTIOPTION
124
+
125
+ # Custom config file name
126
+ openapi init-openapi-config --openapi-config ./my-config.json
127
+ ```
128
+
129
+ **Options:**
130
+ - `--openapi-config` / `-ocn` - Path to output configuration file (default: `openapi.config.json`)
131
+ - `--type` / `-t` - Template type: `OPTION` (single) or `MULTIOPTION` (multiple) (default: `OPTION`)
132
+
133
+ ### Configuration File
134
+
135
+ Instead of passing all options via CLI, you can use a configuration file. Create `openapi.config.json` in your project root:
136
+
137
+ **Single options format:**
82
138
  ```json
83
- [{
84
- "input": "./first.yml",
85
- "output": "./dist",
86
- "client": "xhr",
87
- "excludeCoreServiceFiles": true,
88
- "includeSchemasFiles": true,
89
- },{
90
- "input": "./second.yml",
139
+ {
140
+ "input": "./spec.json",
91
141
  "output": "./dist",
92
- "client": "xhr",
93
- "excludeCoreServiceFiles": true,
94
- "includeSchemasFiles": true,
95
- }]
142
+ "client": "fetch",
143
+ "useOptions": false,
144
+ "useUnionTypes": false,
145
+ "excludeCoreServiceFiles": false,
146
+ "includeSchemasFiles": false,
147
+ "interfacePrefix": "I",
148
+ "enumPrefix": "E",
149
+ "typePrefix": "T",
150
+ "useCancelableRequest": false,
151
+ "sortByRequired": false,
152
+ "useSeparatedIndexes": false,
153
+ "request": "./custom-request.ts"
154
+ }
96
155
  ```
97
- or with common block
156
+
157
+ **Multi-options format (with common block):**
98
158
  ```json
99
159
  {
100
160
  "output": "./dist",
101
- "client": "xhr",
161
+ "client": "fetch",
102
162
  "excludeCoreServiceFiles": true,
103
163
  "includeSchemasFiles": true,
104
- "items": [{
105
- "input": "./first.yml"
106
- },{
107
- "input": "./second.yml"
108
- }]
164
+ "items": [
165
+ {
166
+ "input": "./first.yml"
167
+ },
168
+ {
169
+ "input": "./second.yml",
170
+ "output": "./dist-v2"
171
+ }
172
+ ]
109
173
  }
110
174
  ```
111
175
 
112
- | Name | Item | type | Default | Description |
113
- |-------------------------|-------------------------|-------------|----------|-----------------------------------------------------------|
114
- | output | | string | |The relative location of the output directory |
115
- | outputCore | | string | {output} |The relative location of the output directory for core |
116
- | outputServices | | string | {output} |The relative location of the output directory for services |
117
- | outputModels | | string | {output} |The relative location of the output directory for models |
118
- | outputSchemas | | string | {output} |The relative location of the output directory for schemas |
119
- | client | | string | 'fetch' |The selected httpClient (fetch or XHR) |
120
- | useOptions | | boolean | false |Use options or arguments functions |
121
- | useUnionTypes | | boolean | false |Use union types instead of enums |
122
- | excludeCoreServiceFiles | | boolean | true | |
123
- | includeSchemasFiles | | boolean | true | |
124
- | request | | string | |Path to custom request file |
125
- | interfacePrefix | | string | 'I' |Prefix for interface model |
126
- | enumPrefix | | string | 'E' |Prefix for enum model |
127
- | typePrefix | | string | 'T' |Prefix for type model |
128
- | useCancelableRequest | | boolean | false |Use cancelled promise as returned data type in request |
129
- | items | | array | | |
130
- | | input | string | |The relative location of the OpenAPI spec |
131
- | | output | string | | |
132
- | | outputCore | string | | |
133
- | | outputServices | string | | |
134
- | | outputModels | string | | |
135
- | | outputSchemas | string | | |
136
- | | client | string |'fetch' |The selected httpClient (fetch or XHR) |
137
- | | useOptions | boolean |false |Use options or arguments functions |
138
- | | useUnionTypes | boolean |false |Use union types instead of enums |
139
- | | excludeCoreServiceFiles | boolean |true | |
140
- | | includeSchemasFiles | boolean |true | |
141
- | | request | string | |Path to custom request file |
142
- | | write | boolean |true |Write the files to disk (true or false) |
143
- | | interfacePrefix | string | |Prefix for interface model(I) |
144
- | | enumPrefix | string | |Prefix for enum model(E) |
145
- | | typePrefix | string | |Prefix for type model(T) |
146
- | | useCancelableRequest | boolean |false |Use cancelled promise as returned data type in request |
147
-
148
- ## Example
176
+ **Array format (multiple configs):**
177
+ ```json
178
+ [
179
+ {
180
+ "input": "./first.yml",
181
+ "output": "./dist",
182
+ "client": "xhr"
183
+ },
184
+ {
185
+ "input": "./second.yml",
186
+ "output": "./dist",
187
+ "client": "fetch"
188
+ }
189
+ ]
190
+ ```
191
+
192
+ | Name | Type | Default | Description |
193
+ |------|------|---------|-------------|
194
+ | `input` | string | - | OpenAPI specification path/URL (required for items) |
195
+ | `output` | string | - | Output directory (required) |
196
+ | `outputCore` | string | `{output}` | Output directory for core files |
197
+ | `outputServices` | string | `{output}` | Output directory for services |
198
+ | `outputModels` | string | `{output}` | Output directory for models |
199
+ | `outputSchemas` | string | `{output}` | Output directory for schemas |
200
+ | `client` | string | `fetch` | HTTP client: `fetch`, `xhr`, `node`, or `axios` |
201
+ | `useOptions` | boolean | `false` | Use options instead of arguments |
202
+ | `useUnionTypes` | boolean | `false` | Use union types instead of enums |
203
+ | `excludeCoreServiceFiles` | boolean | `false` | Exclude core and service files generation |
204
+ | `includeSchemasFiles` | boolean | `false` | Enable model validation schemas generation |
205
+ | `request` | string | - | Path to custom request file |
206
+ | `interfacePrefix` | string | `I` | Prefix for interface models |
207
+ | `enumPrefix` | string | `E` | Prefix for enum models |
208
+ | `typePrefix` | string | `T` | Prefix for type models |
209
+ | `useCancelableRequest` | boolean | `false` | Use cancelable promise as return type |
210
+ | `sortByRequired` | boolean | `false` | Extended sorting strategy for arguments |
211
+ | `useSeparatedIndexes` | boolean | `false` | Use separate index files |
212
+ | `items` | array | - | Array of configurations (for multi-options format) |
213
+
214
+ **Note:** You can use the `init-openapi-config` command to generate a template configuration file.
215
+
216
+ ## Examples
217
+
218
+ ### Using CLI commands
219
+
220
+ **Basic generation:**
221
+ ```bash
222
+ openapi generate --input ./spec.json --output ./dist
223
+ ```
224
+
225
+ **With configuration file:**
226
+ ```bash
227
+ # First, create config file
228
+ openapi init-openapi-config
229
+
230
+ # Then generate
231
+ openapi generate
232
+ ```
233
+
234
+ **Check configuration:**
235
+ ```bash
236
+ openapi check-openapi-config
237
+ ```
238
+
239
+ ### Using NPX
240
+
241
+ ```bash
242
+ npx ts-openapi-codegen generate --input ./spec.json --output ./dist
243
+ ```
244
+
245
+ ### Using package.json scripts
149
246
 
150
247
  **package.json**
151
248
  ```json
152
249
  {
153
250
  "scripts": {
154
- "generate": "openapi --input ./spec.json --output ./dist"
251
+ "generate": "openapi generate --input ./spec.json --output ./dist",
252
+ "generate:config": "openapi generate",
253
+ "check-config": "openapi check-openapi-config",
254
+ "init-config": "openapi init-openapi-config"
155
255
  }
156
256
  }
157
257
  ```
158
258
 
159
- **NPX**
160
-
161
- ```
162
- npx openapi-codegen --input ./spec.json --output ./dist
163
- ```
164
-
165
- **Node.js API**
259
+ ### Node.js API
166
260
 
167
261
  ```javascript
168
- const OpenAPI = require('openapi-codegen');
262
+ const OpenAPI = require('ts-openapi-codegen');
169
263
 
170
264
  OpenAPI.generate({
171
265
  input: './spec.json',
@@ -182,6 +276,16 @@ OpenAPI.generate({
182
276
 
183
277
  ## Features
184
278
 
279
+ ### HTTP Clients
280
+
281
+ The generator supports multiple HTTP clients:
282
+ - **fetch** (default) - Browser Fetch API
283
+ - **xhr** - XMLHttpRequest
284
+ - **node** - Node.js compatible client using `node-fetch`
285
+ - **axios** - Axios HTTP client
286
+
287
+ Select the client using the `--httpClient` option or `client` property in config file.
288
+
185
289
  ### Argument style vs. Object style `--useOptions`
186
290
  There's no [named parameter](https://en.wikipedia.org/wiki/Named_parameter) in JavaScript or TypeScript, because of
187
291
  that, we offer the flag `--useOptions` to generate code in two different styles.
@@ -265,7 +369,7 @@ const order: Order = {
265
369
  }
266
370
  ```
267
371
 
268
- ### Runtime schemas `--exportSchemas`
372
+ ### Runtime schemas `--includeSchemasFiles`
269
373
  By default, the OpenAPI generator only exports interfaces for your models. These interfaces will help you during
270
374
  development, but will not be available in JavaScript during runtime. However, Swagger allows you to define properties
271
375
  that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc. Let's say
@@ -318,7 +422,7 @@ The interface does not contain any properties like `maxLength` or `pattern`. How
318
422
  if we wanted to create some form where a user could create such a model. In that form you would iterate
319
423
  over the properties to render form fields based on their type and validate the input based on the `maxLength`
320
424
  or `pattern` property. This requires us to have this information somewhere... For this we can use the
321
- flag `--exportSchemas` to generate a runtime model next to the normal interface:
425
+ flag `--includeSchemasFiles` to generate a runtime model next to the normal interface:
322
426
 
323
427
  ```typescript
324
428
  export const $MyModel = {
@@ -407,7 +511,10 @@ export function request<T>(config: TOpenAPIConfig, options: ApiRequestOptions):
407
511
  ```
408
512
 
409
513
  ### Sorting strategy for function arguments `--sortByRequired`
410
- 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.
514
+ 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.
515
+
516
+ ### Separate index files `--useSeparatedIndexes`
517
+ 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.
411
518
 
412
519
  ### Enum with custom names and descriptions
413
520
  You can use `x-enum-varnames` and `x-enum-descriptions` in your spec to generate enum with custom names and descriptions.
@@ -542,15 +649,6 @@ At start-up, an OpenAPI or Swagger file with external references will be "bundle
542
649
  so that all external references and back-references will be resolved (but local
543
650
  references preserved).
544
651
 
545
- ### Compare to other generators
546
- Depending on which swagger generator you use, you will see different output.
547
- For instance: Different ways of generating models, services, level of quality,
548
- HTTP client, etc. I've compiled a list with the results per area and how they
549
- compare against the openapi-typescript-codegen.
550
-
551
- [Click here to see the comparison](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/index.html)
552
-
553
-
554
652
  FAQ
555
653
  ===
556
654
 
@@ -577,9 +675,9 @@ module.exports = {
577
675
  ### Node.js support
578
676
  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),
579
677
  however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then
580
- you can specify `--client node` in the openapi call:
678
+ you can specify `--httpClient node` in the openapi call:
581
679
 
582
- `openapi --input ./spec.json --output ./dist --client node`
680
+ `openapi generate --input ./spec.json --output ./dist --httpClient node`
583
681
 
584
682
  This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
585
683
  in order to compile and run this client, you will need to install the `node-fetch` dependencies:
@@ -606,7 +704,7 @@ in your `tsconfig.json` file.
606
704
  [downloads-url]: http://npm-stat.com/charts.html?package=ts-openapi-codegen
607
705
  [downloads-image]: http://img.shields.io/npm/dm/ts-openapi-codegen.svg
608
706
  [travis-url]: https://app.travis-ci.com/github/ozonophore/openapi-codegen
609
- [travis-image]: https://app.travis-ci.com/ozonophore/openapi-codegen.svg?branch=master
707
+ [travis-image]: https://app.travis-ci.com/github/ozonophore/openapi-codegen.svg?branch=master
610
708
  [coverage-url]: https://codecov.io/gh/ozonophore/openapi-codegen
611
709
  [coverage-image]: https://codecov.io/gh/ozonophore/openapi-codegen/branch/master/graph/badge.svg?token=RBPZ01BW0Y
612
710
  [typescript-url]: https://www.typescriptlang.org