klasik 1.0.41 → 2.0.1

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 (511) hide show
  1. package/README.md +568 -1063
  2. package/demo-output/models/index.ts +2 -0
  3. package/demo-output/models/owner.ts +74 -0
  4. package/demo-output/models/pet.ts +107 -0
  5. package/demo-output/package.json +14 -0
  6. package/demo-output/tsconfig.json +26 -0
  7. package/dist/__tests__/test-helpers/cleanup-utils.d.ts +64 -0
  8. package/dist/__tests__/test-helpers/cleanup-utils.d.ts.map +1 -0
  9. package/dist/__tests__/test-helpers/cleanup-utils.js +236 -0
  10. package/dist/__tests__/test-helpers/cleanup-utils.js.map +1 -0
  11. package/dist/builders/class-builder.d.ts +99 -0
  12. package/dist/builders/class-builder.d.ts.map +1 -0
  13. package/dist/builders/class-builder.js +238 -0
  14. package/dist/builders/class-builder.js.map +1 -0
  15. package/dist/builders/import-manager.d.ts +62 -0
  16. package/dist/builders/import-manager.d.ts.map +1 -0
  17. package/dist/builders/import-manager.js +124 -0
  18. package/dist/builders/import-manager.js.map +1 -0
  19. package/dist/cli/commands/download.d.ts +16 -0
  20. package/dist/cli/commands/download.d.ts.map +1 -0
  21. package/dist/cli/commands/download.js +104 -0
  22. package/dist/cli/commands/download.js.map +1 -0
  23. package/dist/cli/commands/generate-crd.d.ts +23 -0
  24. package/dist/cli/commands/generate-crd.d.ts.map +1 -0
  25. package/dist/cli/commands/generate-crd.js +153 -0
  26. package/dist/cli/commands/generate-crd.js.map +1 -0
  27. package/dist/cli/commands/generate-jsonschema.d.ts +21 -0
  28. package/dist/cli/commands/generate-jsonschema.d.ts.map +1 -0
  29. package/dist/cli/commands/generate-jsonschema.js +185 -0
  30. package/dist/cli/commands/generate-jsonschema.js.map +1 -0
  31. package/dist/cli/commands/generate.d.ts +24 -0
  32. package/dist/cli/commands/generate.d.ts.map +1 -0
  33. package/dist/cli/commands/generate.js +98 -0
  34. package/dist/cli/commands/generate.js.map +1 -0
  35. package/dist/cli/index.d.ts +3 -0
  36. package/dist/cli/index.d.ts.map +1 -0
  37. package/dist/cli/index.js +25 -0
  38. package/dist/cli/index.js.map +1 -0
  39. package/dist/cli/utils/logger.d.ts +47 -0
  40. package/dist/cli/utils/logger.d.ts.map +1 -0
  41. package/dist/cli/utils/logger.js +79 -0
  42. package/dist/cli/utils/logger.js.map +1 -0
  43. package/dist/cli/utils/options.d.ts +74 -0
  44. package/dist/cli/utils/options.d.ts.map +1 -0
  45. package/dist/cli/utils/options.js +170 -0
  46. package/dist/cli/utils/options.js.map +1 -0
  47. package/dist/config/configuration.d.ts +38 -0
  48. package/dist/config/configuration.d.ts.map +1 -0
  49. package/dist/config/configuration.js +48 -0
  50. package/dist/config/configuration.js.map +1 -0
  51. package/dist/generator/export-style-manager.d.ts +73 -0
  52. package/dist/generator/export-style-manager.d.ts.map +1 -0
  53. package/dist/generator/export-style-manager.js +190 -0
  54. package/dist/generator/export-style-manager.js.map +1 -0
  55. package/dist/generator/generator.d.ts +70 -0
  56. package/dist/generator/generator.d.ts.map +1 -0
  57. package/dist/generator/generator.js +358 -0
  58. package/dist/generator/generator.js.map +1 -0
  59. package/dist/generators/api-client-generator.d.ts +88 -0
  60. package/dist/generators/api-client-generator.d.ts.map +1 -0
  61. package/dist/generators/api-client-generator.js +920 -0
  62. package/dist/generators/api-client-generator.js.map +1 -0
  63. package/dist/generators/tsdoc-generator.d.ts +46 -0
  64. package/dist/generators/tsdoc-generator.d.ts.map +1 -0
  65. package/dist/generators/tsdoc-generator.js +233 -0
  66. package/dist/generators/tsdoc-generator.js.map +1 -0
  67. package/dist/index.d.ts +24 -12
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +64 -22
  70. package/dist/index.js.map +1 -0
  71. package/dist/ir/types.d.ts +250 -0
  72. package/dist/ir/types.d.ts.map +1 -0
  73. package/dist/ir/types.js +101 -0
  74. package/dist/ir/types.js.map +1 -0
  75. package/dist/loaders/ref-inliner.d.ts +71 -0
  76. package/dist/loaders/ref-inliner.d.ts.map +1 -0
  77. package/dist/loaders/ref-inliner.js +152 -0
  78. package/dist/loaders/ref-inliner.js.map +1 -0
  79. package/dist/loaders/ref-resolver.d.ts +86 -0
  80. package/dist/loaders/ref-resolver.d.ts.map +1 -0
  81. package/dist/loaders/ref-resolver.js +237 -0
  82. package/dist/loaders/ref-resolver.js.map +1 -0
  83. package/dist/loaders/spec-loader.d.ts +105 -0
  84. package/dist/loaders/spec-loader.d.ts.map +1 -0
  85. package/dist/loaders/spec-loader.js +335 -0
  86. package/dist/loaders/spec-loader.js.map +1 -0
  87. package/dist/parsers/crd-parser.d.ts +144 -0
  88. package/dist/parsers/crd-parser.d.ts.map +1 -0
  89. package/dist/parsers/crd-parser.js +298 -0
  90. package/dist/parsers/crd-parser.js.map +1 -0
  91. package/dist/parsers/crd-to-ir.d.ts +97 -0
  92. package/dist/parsers/crd-to-ir.d.ts.map +1 -0
  93. package/dist/parsers/crd-to-ir.js +354 -0
  94. package/dist/parsers/crd-to-ir.js.map +1 -0
  95. package/dist/parsers/json-schema-parser.d.ts +162 -0
  96. package/dist/parsers/json-schema-parser.d.ts.map +1 -0
  97. package/dist/parsers/json-schema-parser.js +424 -0
  98. package/dist/parsers/json-schema-parser.js.map +1 -0
  99. package/dist/parsers/openapi-parser.d.ts +188 -0
  100. package/dist/parsers/openapi-parser.d.ts.map +1 -0
  101. package/dist/parsers/openapi-parser.js +385 -0
  102. package/dist/parsers/openapi-parser.js.map +1 -0
  103. package/dist/plugins/class-transformer-plugin.d.ts +34 -0
  104. package/dist/plugins/class-transformer-plugin.d.ts.map +1 -0
  105. package/dist/plugins/class-transformer-plugin.js +96 -0
  106. package/dist/plugins/class-transformer-plugin.js.map +1 -0
  107. package/dist/plugins/class-validator-plugin.d.ts +43 -0
  108. package/dist/plugins/class-validator-plugin.d.ts.map +1 -0
  109. package/dist/plugins/class-validator-plugin.js +214 -0
  110. package/dist/plugins/class-validator-plugin.js.map +1 -0
  111. package/dist/plugins/nestjs-swagger-plugin.d.ts +47 -0
  112. package/dist/plugins/nestjs-swagger-plugin.d.ts.map +1 -0
  113. package/dist/plugins/nestjs-swagger-plugin.js +197 -0
  114. package/dist/plugins/nestjs-swagger-plugin.js.map +1 -0
  115. package/dist/plugins/plugin-interface.d.ts +116 -0
  116. package/dist/plugins/plugin-interface.d.ts.map +1 -0
  117. package/dist/plugins/plugin-interface.js +137 -0
  118. package/dist/plugins/plugin-interface.js.map +1 -0
  119. package/dist/runtime/response-transformer.d.ts +178 -0
  120. package/dist/runtime/response-transformer.d.ts.map +1 -0
  121. package/dist/runtime/response-transformer.js +316 -0
  122. package/dist/runtime/response-transformer.js.map +1 -0
  123. package/dist/templates/template-engine.d.ts +64 -0
  124. package/dist/templates/template-engine.d.ts.map +1 -0
  125. package/dist/templates/template-engine.js +292 -0
  126. package/dist/templates/template-engine.js.map +1 -0
  127. package/dist/utils/ir-merger.d.ts +76 -0
  128. package/dist/utils/ir-merger.d.ts.map +1 -0
  129. package/dist/utils/ir-merger.js +210 -0
  130. package/dist/utils/ir-merger.js.map +1 -0
  131. package/dist/utils/name-utils.d.ts +36 -0
  132. package/dist/utils/name-utils.d.ts.map +1 -0
  133. package/dist/utils/name-utils.js +77 -0
  134. package/dist/utils/name-utils.js.map +1 -0
  135. package/docs/ARCHITECTURE.md +845 -0
  136. package/docs/JSDOC_ESCAPING.md +280 -0
  137. package/docs/json-schema-support.md +353 -0
  138. package/docs/validation.md +350 -0
  139. package/package.json +26 -15
  140. package/templates/api-class.mustache +86 -0
  141. package/templates/configuration.mustache +225 -139
  142. package/templates/index.mustache +3 -0
  143. package/templates/model.mustache +33 -0
  144. package/.claude/settings.local.json +0 -34
  145. package/TEST_CHECKLIST.md +0 -536
  146. package/USAGE_EXAMPLES.md +0 -221
  147. package/dist/attribute-typemap-fixer.d.ts +0 -57
  148. package/dist/attribute-typemap-fixer.js +0 -164
  149. package/dist/cli.d.ts +0 -2
  150. package/dist/cli.js +0 -268
  151. package/dist/crd/crd-generator.d.ts +0 -149
  152. package/dist/crd/crd-generator.js +0 -481
  153. package/dist/crd/crd-parser.d.ts +0 -62
  154. package/dist/crd/crd-parser.js +0 -296
  155. package/dist/crd/crd-to-openapi.d.ts +0 -99
  156. package/dist/crd/crd-to-openapi.js +0 -341
  157. package/dist/crd/types.d.ts +0 -232
  158. package/dist/crd/types.js +0 -5
  159. package/dist/enum-order-fixer.d.ts +0 -28
  160. package/dist/enum-order-fixer.js +0 -141
  161. package/dist/esm-fixer.d.ts +0 -29
  162. package/dist/esm-fixer.js +0 -139
  163. package/dist/jsonschema/jsonschema-generator.d.ts +0 -108
  164. package/dist/jsonschema/jsonschema-generator.js +0 -318
  165. package/dist/jsonschema/jsonschema-parser.d.ts +0 -44
  166. package/dist/jsonschema/jsonschema-parser.js +0 -239
  167. package/dist/jsonschema/jsonschema-to-openapi.d.ts +0 -67
  168. package/dist/jsonschema/jsonschema-to-openapi.js +0 -284
  169. package/dist/jsonschema/types.d.ts +0 -118
  170. package/dist/jsonschema/types.js +0 -5
  171. package/dist/nestjs-type-fixer.d.ts +0 -77
  172. package/dist/nestjs-type-fixer.js +0 -265
  173. package/dist/openapi-client-generator.d.ts +0 -97
  174. package/dist/openapi-client-generator.js +0 -243
  175. package/dist/spec-downloader.d.ts +0 -84
  176. package/dist/spec-downloader.js +0 -403
  177. package/dist/utils/export-style.d.ts +0 -47
  178. package/dist/utils/export-style.js +0 -155
  179. package/example.md +0 -139
  180. package/openapitools.json +0 -0
  181. package/templates/apiInner.mustache +0 -526
  182. package/templates/modelGeneric.mustache +0 -137
  183. package/test-crd-fix/index.ts +0 -2
  184. package/test-crd-fix/v1alpha1/index.ts +0 -2
  185. package/test-crd-fix/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -83
  186. package/test-crd-fix/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -83
  187. package/test-crd-fix/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -83
  188. package/test-crd-fix/v1alpha1/models/app-project-spec-destinations-item.ts +0 -83
  189. package/test-crd-fix/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -65
  190. package/test-crd-fix/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -65
  191. package/test-crd-fix/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -83
  192. package/test-crd-fix/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -70
  193. package/test-crd-fix/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -85
  194. package/test-crd-fix/v1alpha1/models/app-project-spec-roles-item.ts +0 -124
  195. package/test-crd-fix/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -47
  196. package/test-crd-fix/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -209
  197. package/test-crd-fix/v1alpha1/models/app-project-spec.ts +0 -331
  198. package/test-crd-fix/v1alpha1/models/app-project.ts +0 -119
  199. package/test-crd-fix/v1alpha1/models/index.ts +0 -16
  200. package/test-crd-fix/v1alpha1/models/object-meta.ts +0 -212
  201. package/test-export-both/index.ts +0 -20
  202. package/test-export-both/v1alpha1/index.ts +0 -20
  203. package/test-export-both/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
  204. package/test-export-both/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
  205. package/test-export-both/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
  206. package/test-export-both/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
  207. package/test-export-both/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
  208. package/test-export-both/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
  209. package/test-export-both/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
  210. package/test-export-both/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
  211. package/test-export-both/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
  212. package/test-export-both/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
  213. package/test-export-both/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
  214. package/test-export-both/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
  215. package/test-export-both/v1alpha1/models/app-project-spec.ts +0 -259
  216. package/test-export-both/v1alpha1/models/app-project.ts +0 -96
  217. package/test-export-both/v1alpha1/models/index.ts +0 -16
  218. package/test-export-both/v1alpha1/models/object-meta.ts +0 -157
  219. package/test-export-direct/index.ts +0 -16
  220. package/test-export-direct/v1alpha1/index.ts +0 -16
  221. package/test-export-direct/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
  222. package/test-export-direct/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
  223. package/test-export-direct/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
  224. package/test-export-direct/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
  225. package/test-export-direct/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
  226. package/test-export-direct/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
  227. package/test-export-direct/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
  228. package/test-export-direct/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
  229. package/test-export-direct/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
  230. package/test-export-direct/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
  231. package/test-export-direct/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
  232. package/test-export-direct/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
  233. package/test-export-direct/v1alpha1/models/app-project-spec.ts +0 -259
  234. package/test-export-direct/v1alpha1/models/app-project.ts +0 -96
  235. package/test-export-direct/v1alpha1/models/index.ts +0 -16
  236. package/test-export-direct/v1alpha1/models/object-meta.ts +0 -157
  237. package/test-export-namespace/index.ts +0 -2
  238. package/test-export-namespace/v1alpha1/index.ts +0 -2
  239. package/test-export-namespace/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
  240. package/test-export-namespace/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
  241. package/test-export-namespace/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
  242. package/test-export-namespace/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
  243. package/test-export-namespace/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
  244. package/test-export-namespace/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
  245. package/test-export-namespace/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
  246. package/test-export-namespace/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
  247. package/test-export-namespace/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
  248. package/test-export-namespace/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
  249. package/test-export-namespace/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
  250. package/test-export-namespace/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
  251. package/test-export-namespace/v1alpha1/models/app-project-spec.ts +0 -259
  252. package/test-export-namespace/v1alpha1/models/app-project.ts +0 -96
  253. package/test-export-namespace/v1alpha1/models/index.ts +0 -16
  254. package/test-export-namespace/v1alpha1/models/object-meta.ts +0 -157
  255. package/test-export-none/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
  256. package/test-export-none/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
  257. package/test-export-none/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
  258. package/test-export-none/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
  259. package/test-export-none/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
  260. package/test-export-none/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
  261. package/test-export-none/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
  262. package/test-export-none/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
  263. package/test-export-none/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
  264. package/test-export-none/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
  265. package/test-export-none/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
  266. package/test-export-none/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
  267. package/test-export-none/v1alpha1/models/app-project-spec.ts +0 -259
  268. package/test-export-none/v1alpha1/models/app-project.ts +0 -96
  269. package/test-export-none/v1alpha1/models/index.ts +0 -16
  270. package/test-export-none/v1alpha1/models/object-meta.ts +0 -157
  271. package/test-fix-verification/index.ts +0 -27
  272. package/test-fix-verification/models/config-map-args.ts +0 -211
  273. package/test-fix-verification/models/field-selector.ts +0 -47
  274. package/test-fix-verification/models/field-spec.ts +0 -116
  275. package/test-fix-verification/models/generator-options.ts +0 -101
  276. package/test-fix-verification/models/helm-chart.ts +0 -241
  277. package/test-fix-verification/models/image.ts +0 -116
  278. package/test-fix-verification/models/inventory.ts +0 -70
  279. package/test-fix-verification/models/kustomization-helm-globals.ts +0 -65
  280. package/test-fix-verification/models/kustomization-legacy-sort-options.ts +0 -62
  281. package/test-fix-verification/models/kustomization-sort-options-one-of.ts +0 -75
  282. package/test-fix-verification/models/kustomization-sort-options-one-of1.ts +0 -52
  283. package/test-fix-verification/models/kustomization-sort-options.ts +0 -33
  284. package/test-fix-verification/models/kustomization.ts +0 -693
  285. package/test-fix-verification/models/kvsource.ts +0 -80
  286. package/test-fix-verification/models/labels.ts +0 -103
  287. package/test-fix-verification/models/metadata.ts +0 -98
  288. package/test-fix-verification/models/name-args.ts +0 -62
  289. package/test-fix-verification/models/patch-json6902-one-of.ts +0 -67
  290. package/test-fix-verification/models/patch-json6902-one-of1.ts +0 -67
  291. package/test-fix-verification/models/patch-json6902-one-of2-value.ts +0 -23
  292. package/test-fix-verification/models/patch-json6902-one-of2.ts +0 -116
  293. package/test-fix-verification/models/patch-json6902.ts +0 -38
  294. package/test-fix-verification/models/patch-target.ts +0 -116
  295. package/test-fix-verification/models/patches-inline-patch.ts +0 -90
  296. package/test-fix-verification/models/patches-options.ts +0 -62
  297. package/test-fix-verification/models/patches-patch-path.ts +0 -90
  298. package/test-fix-verification/models/replacements-inline-one-of.ts +0 -72
  299. package/test-fix-verification/models/replacements-inline-one-of1.ts +0 -67
  300. package/test-fix-verification/models/replacements-inline.ts +0 -35
  301. package/test-fix-verification/models/replacements-path.ts +0 -44
  302. package/test-fix-verification/models/replacements-source-options.ts +0 -80
  303. package/test-fix-verification/models/replacements-source.ts +0 -160
  304. package/test-fix-verification/models/replacements-target-options.ts +0 -80
  305. package/test-fix-verification/models/replacements-target.ts +0 -110
  306. package/test-fix-verification/models/replicas.ts +0 -62
  307. package/test-fix-verification/models/secret-args.ts +0 -229
  308. package/test-fix-verification/models/selector.ts +0 -155
  309. package/test-fix-verification/models/target.ts +0 -134
  310. package/test-fix-verification/models/var.ts +0 -93
  311. package/test-jsonschema-decorators/index.ts +0 -27
  312. package/test-jsonschema-decorators/models/config-map-args.ts +0 -211
  313. package/test-jsonschema-decorators/models/field-selector.ts +0 -47
  314. package/test-jsonschema-decorators/models/field-spec.ts +0 -116
  315. package/test-jsonschema-decorators/models/generator-options.ts +0 -101
  316. package/test-jsonschema-decorators/models/helm-chart.ts +0 -241
  317. package/test-jsonschema-decorators/models/image.ts +0 -116
  318. package/test-jsonschema-decorators/models/inventory.ts +0 -70
  319. package/test-jsonschema-decorators/models/kustomization-helm-globals.ts +0 -65
  320. package/test-jsonschema-decorators/models/kustomization-legacy-sort-options.ts +0 -62
  321. package/test-jsonschema-decorators/models/kustomization-sort-options-one-of.ts +0 -75
  322. package/test-jsonschema-decorators/models/kustomization-sort-options-one-of1.ts +0 -52
  323. package/test-jsonschema-decorators/models/kustomization-sort-options.ts +0 -33
  324. package/test-jsonschema-decorators/models/kustomization.ts +0 -693
  325. package/test-jsonschema-decorators/models/kvsource.ts +0 -80
  326. package/test-jsonschema-decorators/models/labels.ts +0 -103
  327. package/test-jsonschema-decorators/models/metadata.ts +0 -98
  328. package/test-jsonschema-decorators/models/name-args.ts +0 -62
  329. package/test-jsonschema-decorators/models/patch-json6902-one-of.ts +0 -67
  330. package/test-jsonschema-decorators/models/patch-json6902-one-of1.ts +0 -67
  331. package/test-jsonschema-decorators/models/patch-json6902-one-of2-value.ts +0 -23
  332. package/test-jsonschema-decorators/models/patch-json6902-one-of2.ts +0 -116
  333. package/test-jsonschema-decorators/models/patch-json6902.ts +0 -38
  334. package/test-jsonschema-decorators/models/patch-target.ts +0 -116
  335. package/test-jsonschema-decorators/models/patches-inline-patch.ts +0 -90
  336. package/test-jsonschema-decorators/models/patches-options.ts +0 -62
  337. package/test-jsonschema-decorators/models/patches-patch-path.ts +0 -90
  338. package/test-jsonschema-decorators/models/replacements-inline-one-of.ts +0 -72
  339. package/test-jsonschema-decorators/models/replacements-inline-one-of1.ts +0 -67
  340. package/test-jsonschema-decorators/models/replacements-inline.ts +0 -35
  341. package/test-jsonschema-decorators/models/replacements-path.ts +0 -44
  342. package/test-jsonschema-decorators/models/replacements-source-options.ts +0 -80
  343. package/test-jsonschema-decorators/models/replacements-source.ts +0 -160
  344. package/test-jsonschema-decorators/models/replacements-target-options.ts +0 -80
  345. package/test-jsonschema-decorators/models/replacements-target.ts +0 -110
  346. package/test-jsonschema-decorators/models/replicas.ts +0 -62
  347. package/test-jsonschema-decorators/models/secret-args.ts +0 -229
  348. package/test-jsonschema-decorators/models/selector.ts +0 -155
  349. package/test-jsonschema-decorators/models/target.ts +0 -134
  350. package/test-jsonschema-decorators/models/var.ts +0 -93
  351. package/test-jsonschema-output/index.ts +0 -27
  352. package/test-jsonschema-output/models/config-map-args.ts +0 -163
  353. package/test-jsonschema-output/models/field-selector.ts +0 -40
  354. package/test-jsonschema-output/models/field-spec.ts +0 -89
  355. package/test-jsonschema-output/models/generator-options.ts +0 -79
  356. package/test-jsonschema-output/models/helm-chart.ts +0 -163
  357. package/test-jsonschema-output/models/image.ts +0 -89
  358. package/test-jsonschema-output/models/inventory.ts +0 -58
  359. package/test-jsonschema-output/models/kustomization-helm-globals.ts +0 -53
  360. package/test-jsonschema-output/models/kustomization-legacy-sort-options.ts +0 -50
  361. package/test-jsonschema-output/models/kustomization-sort-options-one-of.ts +0 -62
  362. package/test-jsonschema-output/models/kustomization-sort-options-one-of1.ts +0 -44
  363. package/test-jsonschema-output/models/kustomization-sort-options.ts +0 -33
  364. package/test-jsonschema-output/models/kustomization.ts +0 -526
  365. package/test-jsonschema-output/models/kvsource.ts +0 -63
  366. package/test-jsonschema-output/models/labels.ts +0 -81
  367. package/test-jsonschema-output/models/metadata.ts +0 -76
  368. package/test-jsonschema-output/models/name-args.ts +0 -50
  369. package/test-jsonschema-output/models/patch-json6902-one-of.ts +0 -55
  370. package/test-jsonschema-output/models/patch-json6902-one-of1.ts +0 -55
  371. package/test-jsonschema-output/models/patch-json6902-one-of2-value.ts +0 -23
  372. package/test-jsonschema-output/models/patch-json6902-one-of2.ts +0 -93
  373. package/test-jsonschema-output/models/patch-json6902.ts +0 -38
  374. package/test-jsonschema-output/models/patch-target.ts +0 -89
  375. package/test-jsonschema-output/models/patches-inline-patch.ts +0 -73
  376. package/test-jsonschema-output/models/patches-options.ts +0 -50
  377. package/test-jsonschema-output/models/patches-patch-path.ts +0 -73
  378. package/test-jsonschema-output/models/replacements-inline-one-of.ts +0 -60
  379. package/test-jsonschema-output/models/replacements-inline-one-of1.ts +0 -55
  380. package/test-jsonschema-output/models/replacements-inline.ts +0 -35
  381. package/test-jsonschema-output/models/replacements-path.ts +0 -37
  382. package/test-jsonschema-output/models/replacements-source-options.ts +0 -63
  383. package/test-jsonschema-output/models/replacements-source.ts +0 -123
  384. package/test-jsonschema-output/models/replacements-target-options.ts +0 -63
  385. package/test-jsonschema-output/models/replacements-target.ts +0 -88
  386. package/test-jsonschema-output/models/replicas.ts +0 -50
  387. package/test-jsonschema-output/models/secret-args.ts +0 -176
  388. package/test-jsonschema-output/models/selector.ts +0 -118
  389. package/test-jsonschema-output/models/target.ts +0 -102
  390. package/test-jsonschema-output/models/var.ts +0 -76
  391. package/test-kebab-case/app-project/index.ts +0 -2
  392. package/test-kebab-case/app-project/v1alpha1/index.ts +0 -2
  393. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-cluster-resource-blacklist-item.ts +0 -66
  394. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-cluster-resource-whitelist-item.ts +0 -66
  395. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-destination-service-accounts-item.ts +0 -66
  396. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-destinations-item.ts +0 -66
  397. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-namespace-resource-blacklist-item.ts +0 -53
  398. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-namespace-resource-whitelist-item.ts +0 -53
  399. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-orphaned-resources-ignore-item.ts +0 -66
  400. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-orphaned-resources.ts +0 -58
  401. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-roles-item-jwt-tokens-item.ts +0 -66
  402. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-roles-item.ts +0 -97
  403. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-signature-keys-item.ts +0 -40
  404. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec-sync-windows-item.ts +0 -157
  405. package/test-kebab-case/app-project/v1alpha1/models/app-project-spec.ts +0 -259
  406. package/test-kebab-case/app-project/v1alpha1/models/app-project.ts +0 -96
  407. package/test-kebab-case/app-project/v1alpha1/models/index.ts +0 -16
  408. package/test-kebab-case/app-project/v1alpha1/models/object-meta.ts +0 -157
  409. package/test-kebab-case/application/index.ts +0 -2
  410. package/test-kebab-case/application/v1alpha1/index.ts +0 -2
  411. package/test-kebab-case/application/v1alpha1/models/application-spec-destination.ts +0 -66
  412. package/test-kebab-case/application/v1alpha1/models/application-spec-ignore-differences-item.ts +0 -118
  413. package/test-kebab-case/application/v1alpha1/models/application-spec-info-item.ts +0 -50
  414. package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet-ext-vars-item.ts +0 -66
  415. package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet-tlas-item.ts +0 -66
  416. package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory-jsonnet.ts +0 -76
  417. package/test-kebab-case/application/v1alpha1/models/application-spec-source-directory.ts +0 -84
  418. package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm-file-parameters-item.ts +0 -53
  419. package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm-parameters-item.ts +0 -66
  420. package/test-kebab-case/application/v1alpha1/models/application-spec-source-helm.ts +0 -118
  421. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet-ext-vars-item.ts +0 -66
  422. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet-tlas-item.ts +0 -66
  423. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory-jsonnet.ts +0 -76
  424. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-directory.ts +0 -84
  425. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm-file-parameters-item.ts +0 -53
  426. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm-parameters-item.ts +0 -66
  427. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-helm.ts +0 -118
  428. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-patches-item-target.ts +0 -115
  429. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-patches-item.ts +0 -81
  430. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize-replicas-item.ts +0 -56
  431. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-kustomize.ts +0 -132
  432. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin-env-item.ts +0 -53
  433. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin-parameters-item.ts +0 -76
  434. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source-plugin.ts +0 -76
  435. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-dry-source.ts +0 -138
  436. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-hydrate-to.ts +0 -40
  437. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator-sync-source.ts +0 -53
  438. package/test-kebab-case/application/v1alpha1/models/application-spec-source-hydrator.ts +0 -81
  439. package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-patches-item-target.ts +0 -115
  440. package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-patches-item.ts +0 -81
  441. package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize-replicas-item.ts +0 -51
  442. package/test-kebab-case/application/v1alpha1/models/application-spec-source-kustomize.ts +0 -132
  443. package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin-env-item.ts +0 -53
  444. package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin-parameters-item.ts +0 -76
  445. package/test-kebab-case/application/v1alpha1/models/application-spec-source-plugin.ts +0 -76
  446. package/test-kebab-case/application/v1alpha1/models/application-spec-source.ts +0 -177
  447. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet-ext-vars-item.ts +0 -66
  448. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet-tlas-item.ts +0 -66
  449. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory-jsonnet.ts +0 -76
  450. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-directory.ts +0 -84
  451. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm-file-parameters-item.ts +0 -53
  452. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm-parameters-item.ts +0 -66
  453. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-helm.ts +0 -118
  454. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-patches-item-target.ts +0 -115
  455. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-patches-item.ts +0 -81
  456. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize-replicas-item.ts +0 -56
  457. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-kustomize.ts +0 -132
  458. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin-env-item.ts +0 -53
  459. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin-parameters-item.ts +0 -76
  460. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item-plugin.ts +0 -76
  461. package/test-kebab-case/application/v1alpha1/models/application-spec-sources-item.ts +0 -177
  462. package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-automated.ts +0 -79
  463. package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-managed-namespace-metadata.ts +0 -53
  464. package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-retry-backoff.ts +0 -66
  465. package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy-retry.ts +0 -71
  466. package/test-kebab-case/application/v1alpha1/models/application-spec-sync-policy.ts +0 -94
  467. package/test-kebab-case/application/v1alpha1/models/application-spec.ts +0 -179
  468. package/test-kebab-case/application/v1alpha1/models/application.ts +0 -96
  469. package/test-kebab-case/application/v1alpha1/models/index.ts +0 -60
  470. package/test-kebab-case/application/v1alpha1/models/object-meta.ts +0 -157
  471. package/test-kebab-case/index.ts +0 -3
  472. package/test-multi-schemas/index.ts +0 -27
  473. package/test-multi-schemas/models/config-map-args.ts +0 -163
  474. package/test-multi-schemas/models/field-selector.ts +0 -40
  475. package/test-multi-schemas/models/field-spec.ts +0 -89
  476. package/test-multi-schemas/models/generator-options.ts +0 -79
  477. package/test-multi-schemas/models/helm-chart.ts +0 -163
  478. package/test-multi-schemas/models/image.ts +0 -89
  479. package/test-multi-schemas/models/inventory.ts +0 -58
  480. package/test-multi-schemas/models/kustomization-helm-globals.ts +0 -53
  481. package/test-multi-schemas/models/kustomization-legacy-sort-options.ts +0 -50
  482. package/test-multi-schemas/models/kustomization-sort-options-one-of.ts +0 -62
  483. package/test-multi-schemas/models/kustomization-sort-options-one-of1.ts +0 -44
  484. package/test-multi-schemas/models/kustomization-sort-options.ts +0 -33
  485. package/test-multi-schemas/models/kustomization.ts +0 -526
  486. package/test-multi-schemas/models/kvsource.ts +0 -63
  487. package/test-multi-schemas/models/labels.ts +0 -81
  488. package/test-multi-schemas/models/metadata.ts +0 -76
  489. package/test-multi-schemas/models/name-args.ts +0 -50
  490. package/test-multi-schemas/models/patch-json6902-one-of.ts +0 -55
  491. package/test-multi-schemas/models/patch-json6902-one-of1.ts +0 -55
  492. package/test-multi-schemas/models/patch-json6902-one-of2-value.ts +0 -23
  493. package/test-multi-schemas/models/patch-json6902-one-of2.ts +0 -93
  494. package/test-multi-schemas/models/patch-json6902.ts +0 -38
  495. package/test-multi-schemas/models/patch-target.ts +0 -89
  496. package/test-multi-schemas/models/patches-inline-patch.ts +0 -73
  497. package/test-multi-schemas/models/patches-options.ts +0 -50
  498. package/test-multi-schemas/models/patches-patch-path.ts +0 -73
  499. package/test-multi-schemas/models/replacements-inline-one-of.ts +0 -60
  500. package/test-multi-schemas/models/replacements-inline-one-of1.ts +0 -55
  501. package/test-multi-schemas/models/replacements-inline.ts +0 -35
  502. package/test-multi-schemas/models/replacements-path.ts +0 -37
  503. package/test-multi-schemas/models/replacements-source-options.ts +0 -63
  504. package/test-multi-schemas/models/replacements-source.ts +0 -123
  505. package/test-multi-schemas/models/replacements-target-options.ts +0 -63
  506. package/test-multi-schemas/models/replacements-target.ts +0 -88
  507. package/test-multi-schemas/models/replicas.ts +0 -50
  508. package/test-multi-schemas/models/secret-args.ts +0 -176
  509. package/test-multi-schemas/models/selector.ts +0 -118
  510. package/test-multi-schemas/models/target.ts +0 -102
  511. package/test-multi-schemas/models/var.ts +0 -76
package/README.md CHANGED
@@ -1,1328 +1,824 @@
1
- # klasik
1
+ # Klasik
2
2
 
3
- Download OpenAPI specifications from remote URLs and generate TypeScript clients with class-transformer support for Kubernetes and other APIs.
3
+ Generate TypeScript clients from OpenAPI specifications, Kubernetes CRDs, and JSON Schema with full type safety and class-transformer support.
4
+
5
+ Perfect for:
6
+ - 🚀 Kubernetes operators and controllers
7
+ - 🔧 REST API clients with type safety
8
+ - 📦 NestJS backend services
9
+ - 🎯 Type-safe microservice communication
4
10
 
5
11
  ## Features
6
12
 
7
- - 📥 **Download OpenAPI specs** from remote URLs or local files
8
- - ☸️ **Kubernetes CRD support** - Generate TypeScript models from CustomResourceDefinitions
9
- - 📋 **JSON Schema support** - Generate models from JSON Schema files (SchemaStore.org and more)
10
- - 📁 **Multiple input formats** - HTTP/HTTPS URLs, file:// URLs, absolute/relative paths
11
- - 📄 **JSON and YAML support** - Automatically parse and handle both formats (YAML specs are converted to JSON for code generation)
12
- - 🔐 **Authentication support** - Custom headers including Bearer tokens and API keys
13
- - 🔗 **External reference resolution** - Automatically download referenced schema files (`$ref`)
14
- - 📦 **ESM compatibility** - Automatic `.js` extension fixing for Node.js ESM projects
15
- - 🔄 **Automatic transformation** - Converts API responses to class instances using class-transformer
16
- - 🎯 **Type-safe** - Full TypeScript support with decorators
17
- - 🛠️ **Configurable** - Custom headers, timeouts, and templates
18
- - 🧪 **Well-tested** - Comprehensive test coverage
19
- - 📦 **Easy to use** - Simple CLI and programmatic API
13
+ **Easy to Use** - Single CLI command to generate types
14
+ 🎯 **Type-Safe** - Full TypeScript support with strict typing
15
+ 🔄 **class-transformer** - Automatic serialization/deserialization
16
+ **class-validator** - Built-in validation decorators
17
+ 🎨 **NestJS Ready** - @ApiProperty decorators out of the box
18
+ 📦 **Multiple Formats** - OpenAPI, Kubernetes CRDs, JSON Schema
19
+ 🌐 **ESM Support** - Modern JavaScript modules with .js extensions
20
+ 🔗 **External $refs** - Automatic resolution of external schemas
21
+ 🎭 **Custom Templates** - Mustache-based customization
22
+ ⚙️ **Flexible Output** - Multiple export styles (namespace, direct, both)
23
+ 🧪 **Well Tested** - Comprehensive test coverage (748 passing tests)
24
+ 🚀 **Production Ready** - Used in real-world projects
25
+ 📝 **Full CLI** - Rich command-line interface with 4 commands
26
+ 🔐 **Authentication** - Custom headers including Bearer tokens
20
27
 
21
28
  ## Installation
22
29
 
23
30
  ```bash
24
- npm install klasik
31
+ npm install -g klasik
32
+
33
+ # or use directly with npx
34
+ npx klasik <command>
25
35
  ```
26
36
 
27
37
  ## Quick Start
28
38
 
29
39
  ### CLI Usage
30
40
 
31
- Generate a TypeScript client from a remote OpenAPI spec:
41
+ Generate from OpenAPI spec:
32
42
 
33
43
  ```bash
34
- # JSON spec
35
- npx klasik generate \
36
- --url https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json \
37
- --output ./k8s-client
38
-
39
- # YAML spec
40
- npx klasik generate \
41
- --url https://api.example.com/openapi.yaml \
42
- --output ./client
44
+ klasik generate --url https://api.example.com/openapi.json --output ./src/generated
43
45
  ```
44
46
 
45
- Generate from a local OpenAPI spec file (JSON or YAML):
47
+ Generate from Kubernetes CRDs:
46
48
 
47
49
  ```bash
48
- # Absolute path
49
- npx klasik generate \
50
- --url /path/to/openapi.yaml \
51
- --output ./client
52
-
53
- # Relative path
54
- npx klasik generate \
55
- --url ./specs/openapi.json \
56
- --output ./client
57
-
58
- # file:// URL
59
- npx klasik generate \
60
- --url file:///path/to/openapi.yaml \
61
- --output ./client
50
+ klasik generate-crd \
51
+ --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
52
+ --output ./src/generated \
53
+ --class-validator \
54
+ --nestjs-swagger
62
55
  ```
63
56
 
64
- Download an OpenAPI spec without generating (supports JSON and YAML):
57
+ Generate from JSON Schema:
65
58
 
66
59
  ```bash
67
- # Download JSON spec
68
- npx klasik download \
69
- --url https://api.example.com/openapi.json \
70
- --output ./specs/api-spec.json
71
-
72
- # Download YAML spec
73
- npx klasik download \
74
- --url https://api.example.com/openapi.yaml \
75
- --output ./specs/api-spec.yaml
60
+ klasik generate-jsonschema \
61
+ --url ./schemas/user.json \
62
+ --output ./src/generated
76
63
  ```
77
64
 
78
65
  ### Programmatic Usage
79
66
 
80
67
  ```typescript
81
- import { OpenAPIClientGenerator } from 'klasik';
68
+ import { Generator, OpenAPIParser, SpecLoader } from 'klasik';
82
69
 
83
- const generator = new OpenAPIClientGenerator();
84
-
85
- await generator.generate({
86
- specUrl: 'https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json',
87
- outputDir: './k8s-client',
88
- });
89
- ```
70
+ // Load and parse OpenAPI spec
71
+ const loader = new SpecLoader();
72
+ const spec = await loader.load({ url: 'https://api.example.com/openapi.json' });
90
73
 
91
- ## Kubernetes CRD Support
74
+ const parser = new OpenAPIParser();
75
+ const ir = parser.parse(spec, { includeOperations: true });
92
76
 
93
- Klasik can generate TypeScript models directly from Kubernetes CustomResourceDefinitions (CRDs). This is perfect for working with custom Kubernetes resources like ArgoCD Applications, Cert-Manager Certificates, or your own custom resources.
77
+ // Generate TypeScript code
78
+ const generator = new Generator({
79
+ outputDir: './generated',
80
+ mode: 'full', // or 'models-only'
81
+ nestJsSwagger: true,
82
+ classValidator: true,
83
+ });
94
84
 
95
- ### Quick Start with CRDs
85
+ await generator.generate(ir);
86
+ ```
96
87
 
97
- Generate TypeScript models from a CRD:
88
+ ## Request and Response Validation
98
89
 
99
- ```bash
100
- # From a URL (e.g., ArgoCD AppProject CRD)
101
- npx klasik generate-crd \
102
- --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
103
- --output ./generated
90
+ Klasik supports automatic validation of both API requests and responses using class-validator. When enabled, requests and responses are validated against the decorators generated by the `--class-validator` plugin.
104
91
 
105
- # From multiple CRD URLs (merged into single output)
106
- npx klasik generate-crd \
107
- -u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
108
- -u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
109
- --output ./generated
92
+ ### Configuration
110
93
 
111
- # From a local CRD file
112
- npx klasik generate-crd \
113
- --url ./my-crd.yaml \
114
- --output ./generated
94
+ ```typescript
95
+ import { Configuration } from './generated/configuration';
96
+ import { TasksApi, NewTask } from './generated';
97
+ import axios from 'axios';
115
98
 
116
- # With status schemas
117
- npx klasik generate-crd \
118
- --url ./my-crd.yaml \
119
- --output ./generated \
120
- --include-status
99
+ const config = new Configuration({
100
+ basePath: 'https://api.example.com',
101
+ enableResponseTransformation: true, // Required for response validation
102
+ enableResponseValidation: true, // Enable response validation (default: false)
103
+ enableRequestValidation: true, // Enable request validation (default: false)
104
+ });
121
105
 
122
- # With NestJS and validation decorators
123
- npx klasik generate-crd \
124
- --url ./my-crd.yaml \
125
- --output ./src/generated \
126
- --nestjs-swagger \
127
- --class-validator
106
+ const api = new TasksApi(config, axios.create());
128
107
  ```
129
108
 
130
- ### CRD Features
109
+ ### Request Validation
131
110
 
132
- - **Automatic schema extraction** from `openAPIV3Schema`
133
- - **Multiple URL support** - Generate from multiple CRD sources in one command
134
- - **Version-based organization** - Each CRD version gets its own folder (e.g., `v1alpha1/`, `v1beta1/`)
135
- - ✅ **Multi-document YAML support** - Process multiple CRDs from a single file
136
- - ✅ **Nested type extraction** - Complex nested objects become separate TypeScript interfaces
137
- - ✅ **Full decorator support** - Works with `--nestjs-swagger`, `--class-validator`, `--esm`
138
- - ✅ **Spec and Status schemas** - Optional status model generation with `--include-status`
139
- - ✅ **Kubernetes metadata** - Standard ObjectMeta types included
111
+ Request validation ensures request bodies are:
112
+ 1. Instances of the expected class
113
+ 2. Valid according to class-validator decorators
140
114
 
141
- ### Generated CRD Structure
115
+ ```typescript
116
+ import { NewTask } from './generated/models';
142
117
 
143
- For a CRD with multiple versions, klasik generates:
118
+ // Create instance
119
+ const newTask = new NewTask();
120
+ newTask.title = 'My Task';
121
+ newTask.description = 'Task description';
144
122
 
145
- ```
146
- output/
147
- ├── v1alpha1/
148
- │ ├── models/
149
- │ │ ├── app-project.ts # Main resource
150
- │ │ ├── app-project-spec.ts # Spec definition
151
- │ │ ├── app-project-status.ts # Status (if --include-status)
152
- │ │ ├── object-meta.ts # Kubernetes metadata
153
- │ │ └── [nested-types].ts # Extracted nested types
154
- │ └── index.ts # Version exports
155
- ├── v1beta1/
156
- │ └── ... (same structure)
157
- └── index.ts # All versions
123
+ // This will validate before sending
124
+ const response = await api.createTask(newTask);
158
125
  ```
159
126
 
160
- ### Using Generated CRD Models
127
+ Request validation will throw if:
128
+ - Request body is not an instance: `RequestNotInstanceError`
129
+ - Request body fails validation: `ValidationError`
161
130
 
162
- ```typescript
163
- import { AppProject, AppProjectSpec } from './generated/v1alpha1';
164
-
165
- // Create a typed Kubernetes resource
166
- const project: AppProject = {
167
- apiVersion: 'argoproj.io/v1alpha1',
168
- kind: 'AppProject',
169
- metadata: {
170
- name: 'my-project',
171
- namespace: 'argocd'
172
- },
173
- spec: {
174
- description: 'My ArgoCD project',
175
- destinations: [
176
- { server: 'https://kubernetes.default.svc', namespace: '*' }
177
- ],
178
- sourceRepos: ['*']
179
- }
180
- };
131
+ ### Response Validation
181
132
 
182
- // Full TypeScript intellisense and type checking!
183
- ```
184
-
185
- ### CRD Programmatic API
133
+ Response validation ensures responses match the expected schema:
186
134
 
187
135
  ```typescript
188
- import { CRDGenerator } from 'klasik';
189
-
190
- const generator = new CRDGenerator();
191
-
192
- // Single URL
193
- await generator.generate({
194
- urls: './crds/my-resource.yaml',
195
- outputDir: './generated',
196
- includeStatus: true,
197
- nestJsSwagger: true,
198
- classValidator: true
199
- });
200
-
201
- // Multiple URLs (merged into single output)
202
- await generator.generate({
203
- urls: [
204
- 'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml',
205
- 'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml',
206
- './local/my-crd.yaml'
207
- ],
208
- outputDir: './generated',
209
- includeStatus: true,
210
- nestJsSwagger: true
211
- });
136
+ try {
137
+ const response = await api.getTasks();
138
+ // Response is validated
139
+ } catch (error) {
140
+ if (error instanceof ValidationError) {
141
+ console.error('Validation failed:', error.validationErrors);
142
+ }
143
+ }
212
144
  ```
213
145
 
214
- ### Multi-CRD YAML Files
215
-
216
- Klasik automatically handles multi-document YAML files (CRDs separated by `---`):
217
-
218
- ```yaml
219
- ---
220
- apiVersion: apiextensions.k8s.io/v1
221
- kind: CustomResourceDefinition
222
- metadata:
223
- name: appprojects.argoproj.io
224
- spec:
225
- # ... AppProject CRD
226
- ---
227
- apiVersion: apiextensions.k8s.io/v1
228
- kind: CustomResourceDefinition
229
- metadata:
230
- name: applications.argoproj.io
231
- spec:
232
- # ... Application CRD
233
- ```
146
+ ### Custom Error Handling
234
147
 
235
- Output will be organized by resource kind:
148
+ Use callbacks for custom error handling:
236
149
 
150
+ ```typescript
151
+ const config = new Configuration({
152
+ basePath: 'https://api.example.com',
153
+ enableRequestValidation: true,
154
+ onRequestValidationError: (errors, modelClass, instance) => {
155
+ console.error(`Request validation failed for ${modelClass.name}:`);
156
+ errors.forEach(err => {
157
+ console.error(` - ${err.property}: ${Object.values(err.constraints || {}).join(', ')}`);
158
+ });
159
+ },
160
+ enableResponseValidation: true,
161
+ onResponseValidationError: (errors, modelClass, instance) => {
162
+ console.error(`Response validation failed for ${modelClass.name}:`);
163
+ // Log to monitoring service
164
+ Sentry.captureException(new Error('API validation failed'));
165
+ }
166
+ });
237
167
  ```
238
- output/
239
- ├── AppProject/
240
- │ ├── v1alpha1/
241
- │ └── index.ts
242
- ├── Application/
243
- │ ├── v1alpha1/
244
- │ └── index.ts
245
- └── index.ts
246
- ```
247
-
248
- ## JSON Schema Support
249
168
 
250
- Klasik can generate TypeScript models from JSON Schema files (like those from [SchemaStore.org](https://schemastore.org)). This is perfect for working with configuration files, data formats, and schema definitions.
169
+ ### Requirements
251
170
 
252
- ### Quick Start with JSON Schema
171
+ - Models must be generated with `--class-validator` flag
172
+ - For response validation: `enableResponseTransformation` must be `true` (default)
173
+ - `class-validator` package must be installed
253
174
 
254
- Generate TypeScript models from a JSON Schema:
175
+ ### Example with CLI
255
176
 
256
177
  ```bash
257
- # From SchemaStore (kustomization.json schema)
258
- npx klasik generate-jsonschema \
259
- -u https://json.schemastore.org/kustomization.json \
260
- -o ./generated/kustomization
261
-
262
- # From multiple schemas (merged into single output)
263
- npx klasik generate-jsonschema \
264
- -u https://json.schemastore.org/kustomization.json \
265
- -u https://json.schemastore.org/package.json \
266
- -o ./generated/models
267
-
268
- # From a local file
269
- npx klasik generate-jsonschema \
270
- -u ./my-schema.json \
271
- -o ./generated
272
-
273
- # With NestJS and validation decorators
274
- npx klasik generate-jsonschema \
275
- -u ./schema.json \
276
- -o ./src/generated \
277
- --nestjs-swagger \
178
+ # Generate models with validation decorators
179
+ klasik generate \
180
+ --url https://api.example.com/openapi.json \
181
+ --output ./src/generated \
278
182
  --class-validator
279
- ```
280
183
 
281
- ### JSON Schema Features
184
+ # Use in your code
185
+ import { Configuration, TasksApi, NewTask } from './generated';
282
186
 
283
- - **All definitions generated** - Creates models for every definition in the schema
284
- - ✅ **Multiple URL support** - Merge models from multiple JSON Schema files
285
- - ✅ **Nested type extraction** - Complex nested objects become separate TypeScript interfaces
286
- - ✅ **Full decorator support** - Works with `--nestjs-swagger`, `--class-validator`, `--esm`
287
- - ✅ **Standards compliant** - Supports JSON Schema Draft 4 and Draft 7
288
- - ✅ **patternProperties handling** - Automatically converts to OpenAPI-compatible schemas
187
+ const config = new Configuration({
188
+ basePath: 'https://api.example.com',
189
+ enableRequestValidation: true,
190
+ enableResponseValidation: true
191
+ });
289
192
 
290
- ### Generated Structure
193
+ const api = new TasksApi(config);
291
194
 
292
- For a JSON Schema file with definitions:
195
+ // Request will be validated
196
+ const newTask = new NewTask();
197
+ newTask.title = 'My Task';
198
+ const created = await api.createTask(newTask);
293
199
 
200
+ // Response will be validated
201
+ const tasks = await api.listTasks();
294
202
  ```
295
- output/
296
- ├── models/
297
- │ ├── kustomization.ts
298
- │ ├── config-map-args.ts
299
- │ ├── helm-chart.ts
300
- │ └── ... (all definitions)
301
- └── index.ts
302
- ```
303
-
304
- **Naming convention:**
305
- - `ConfigMapArgs` → `config-map-args.ts`
306
- - `HelmChart` → `helm-chart.ts`
307
- - `Kustomization` → `kustomization.ts`
308
203
 
309
- ### Using Generated JSON Schema Models
204
+ For more details, see the [Validation Guide](./docs/validation.md).
310
205
 
311
- ```typescript
312
- import { Kustomization, ConfigMapArgs } from './generated/kustomization';
313
-
314
- // Create a typed kustomization file
315
- const kustomization: Kustomization = {
316
- apiVersion: 'kustomize.config.k8s.io/v1beta1',
317
- kind: 'Kustomization',
318
- resources: [
319
- './deployment.yaml',
320
- './service.yaml'
321
- ],
322
- configMapGenerator: [
323
- {
324
- name: 'my-config',
325
- literals: ['key=value']
326
- }
327
- ]
328
- };
329
-
330
- // Full TypeScript intellisense and type checking!
331
- ```
332
-
333
- ### JSON Schema Programmatic API
206
+ ## CLI Commands
334
207
 
335
- ```typescript
336
- import { JSONSchemaGenerator } from 'klasik';
208
+ ### `klasik generate`
337
209
 
338
- const generator = new JSONSchemaGenerator();
210
+ Generate TypeScript client from OpenAPI specification.
339
211
 
340
- // Single URL
341
- await generator.generate({
342
- urls: './schemas/my-schema.json',
343
- outputDir: './generated',
344
- nestJsSwagger: true,
345
- classValidator: true
346
- });
212
+ **Usage:**
347
213
 
348
- // Multiple URLs
349
- await generator.generate({
350
- urls: [
351
- 'https://json.schemastore.org/kustomization.json',
352
- './local-schema.json'
353
- ],
354
- outputDir: './generated',
355
- keepSpec: true // Keep intermediate OpenAPI specs
356
- });
214
+ ```bash
215
+ klasik generate [options]
357
216
  ```
358
217
 
359
- **JSONSchemaGeneratorOptions:**
360
- - `urls: string | string[]` - URL(s) or file path(s) to JSON Schema files (required)
361
- - `outputDir: string` - Output directory (required)
362
- - `headers?: Record<string, string>` - Custom HTTP headers
363
- - `timeout?: number` - Request timeout in milliseconds (default: 30000)
364
- - `fixEsmImports?: boolean` - Add .js extensions for ESM (default: false)
365
- - `nestJsSwagger?: boolean` - Include NestJS decorators (default: false)
366
- - `classValidator?: boolean` - Include validation decorators (default: false)
367
- - `skipJsExtensions?: boolean` - Skip .js extensions (default: false)
368
- - `templateDir?: string` - Custom template directory
369
- - `keepSpec?: boolean` - Keep intermediate OpenAPI specs (default: false)
370
-
371
- ## CLI Commands
372
-
373
- ### `generate`
374
-
375
- Generate a TypeScript client from an OpenAPI spec (remote URL or local file).
376
-
377
218
  **Options:**
378
- - `-u, --url <url>` - URL or file path to the OpenAPI spec (required)
379
- - Supports: `https://...`, `http://...`, `file://...`, `/absolute/path`, `./relative/path`
380
- - `-o, --output <dir>` - Output directory for generated client code (required)
381
- - `-m, --mode <mode>` - Generation mode: `full` (models + APIs + config) or `models-only` (default: `full`)
382
- - `full`: Generates complete axios client with APIs, models, and configuration
383
- - `models-only`: Generates only model classes with class-transformer decorators (no API client code)
384
- - `-H, --header <header...>` - Custom headers for HTTP requests (format: "Key: Value")
385
- - Can be used multiple times for multiple headers
386
- - Perfect for authorization: `--header "Authorization: Bearer token"`
387
- - `-r, --resolve-refs` - Resolve and download external `$ref` references
388
- - `--esm` - Add `.js` extensions to imports for ESM compatibility (Node.js modules)
389
- - `--nestjs-swagger` - Include NestJS Swagger `@ApiProperty` decorators in generated models
390
- - Automatically adds `@nestjs/swagger` to generated package.json
391
- - Ideal for NestJS applications with Swagger/OpenAPI documentation
392
- - Works with both `full` and `models-only` generation modes
393
- - `--class-validator` - Include class-validator decorators for runtime validation (requires openapi-class-transformer v2.0+)
394
- - Automatically adds `class-validator` and `class-transformer` to generated package.json
395
- - Enables runtime validation with decorators like `@IsString`, `@IsEmail`, `@Min`, `@Max`
396
- - Forward-compatible flag - full decorator generation coming in future version
397
- - `-t, --template <dir>` - Custom template directory (klasik includes enhanced TSDoc templates by default)
398
- - `-k, --keep-spec` - Keep the downloaded spec file after generation
399
- - `--timeout <ms>` - Request timeout in milliseconds for HTTP requests (default: 30000)
219
+
220
+ | Option | Description | Default |
221
+ |--------|-------------|---------|
222
+ | `-u, --url <url>` | OpenAPI spec URL or file path (required) | - |
223
+ | `-o, --output <dir>` | Output directory (required) | - |
224
+ | `-m, --mode <mode>` | Generation mode: `full` or `models-only` | `full` |
225
+ | `--resolve-refs` | Resolve external $ref files | `false` |
226
+ | `--esm` | Add .js extensions for ESM compatibility | `false` |
227
+ | `--skip-js-extensions` | Skip .js extensions (for bundlers) | `false` |
228
+ | `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
229
+ | `--class-validator` | Add class-validator decorators | `false` |
230
+ | `--header <header>` | Custom header (repeatable) | - |
231
+ | `--timeout <ms>` | Request timeout | `30000` |
232
+ | `--template <dir>` | Custom template directory | - |
233
+ | `--keep-spec` | Keep downloaded spec file(s) | `false` |
234
+ | `--export-style <style>` | Export style: `namespace`, `direct`, `both`, `none` | `namespace` |
400
235
 
401
236
  **Examples:**
402
237
 
403
238
  ```bash
404
- # From remote URL with authorization
405
- klasik generate \
406
- --url https://api.example.com/openapi.json \
407
- --output ./client \
408
- --header "Authorization: Bearer token123" \
409
- --timeout 60000
410
-
411
- # With external reference resolution
412
- klasik generate \
413
- --url https://api.example.com/openapi.json \
414
- --output ./client \
415
- --header "Authorization: Bearer token123" \
416
- --resolve-refs
239
+ # Basic generation
240
+ klasik generate --url ./openapi.yaml --output ./generated
417
241
 
418
- # NestJS integration with Swagger decorators
242
+ # Full client with API methods (default mode)
419
243
  klasik generate \
420
- --url https://api.example.com/openapi.json \
421
- --output ./src/generated \
422
- --mode models-only \
423
- --nestjs-swagger
244
+ --url https://petstore.swagger.io/v2/swagger.json \
245
+ --output ./src/api
424
246
 
425
- # With runtime validation decorators
247
+ # Models only (no API client)
426
248
  klasik generate \
427
249
  --url https://api.example.com/openapi.json \
428
- --output ./src/generated \
429
- --mode models-only \
430
- --class-validator
250
+ --output ./src/models \
251
+ --mode models-only
431
252
 
432
- # Full NestJS setup: Swagger docs + validation
253
+ # With NestJS and validation support
433
254
  klasik generate \
434
- --url https://api.example.com/openapi.json \
435
- --output ./src/generated \
436
- --mode models-only \
255
+ --url https://api.example.com/spec.json \
256
+ --output ./src/api \
437
257
  --nestjs-swagger \
438
258
  --class-validator
439
259
 
440
- # Multiple headers
260
+ # With external refs and authentication
441
261
  klasik generate \
442
- --url https://api.example.com/openapi.json \
443
- --output ./client \
444
- --header "Authorization: Bearer token" \
445
- --header "X-API-Version: v1"
262
+ --url https://api.example.com/spec.json \
263
+ --output ./generated \
264
+ --resolve-refs \
265
+ --header "Authorization: Bearer ${TOKEN}"
446
266
 
447
- # From local file
267
+ # ESM compatibility
448
268
  klasik generate \
449
- --url ./my-spec.json \
450
- --output ./client
269
+ --url ./openapi.yaml \
270
+ --output ./generated \
271
+ --esm
451
272
 
452
- # From file:// URL
273
+ # Custom templates
453
274
  klasik generate \
454
- --url file:///Users/me/specs/api.json \
455
- --output ./client
275
+ --url ./openapi.yaml \
276
+ --output ./generated \
277
+ --template ./my-templates
456
278
  ```
457
279
 
458
- ### `download`
280
+ ### `klasik download`
281
+
282
+ Download OpenAPI spec without generating code.
459
283
 
460
- Download an OpenAPI spec from a remote URL without generating code.
284
+ **Usage:**
285
+
286
+ ```bash
287
+ klasik download [options]
288
+ ```
461
289
 
462
290
  **Options:**
463
- - `-u, --url <url>` - Remote URL to download the OpenAPI spec from (required)
464
- - `-o, --output <file>` - Output file path for the downloaded spec (required)
465
- - `-H, --header <header...>` - Custom headers for the request
466
- - `-r, --resolve-refs` - Resolve and download external `$ref` references
467
- - `--timeout <ms>` - Request timeout in milliseconds (default: 30000)
291
+
292
+ | Option | Description | Default |
293
+ |--------|-------------|---------|
294
+ | `-u, --url <url>` | Remote spec URL (required) | - |
295
+ | `-o, --output <file>` | Output file path (required) | - |
296
+ | `--header <header>` | Custom header (repeatable) | - |
297
+ | `--resolve-refs` | Resolve external $ref files | `false` |
298
+ | `--timeout <ms>` | Request timeout | `30000` |
468
299
 
469
300
  **Examples:**
470
301
 
471
302
  ```bash
472
- # Download spec only
303
+ # Download spec
304
+ klasik download \
305
+ --url https://api.example.com/openapi.json \
306
+ --output ./specs/api-spec.json
307
+
308
+ # With authentication
473
309
  klasik download \
474
310
  --url https://api.example.com/openapi.json \
475
311
  --output ./specs/api-spec.json \
476
- --header "Authorization: Bearer token123"
312
+ --header "Authorization: Bearer ${TOKEN}"
477
313
 
478
- # Download spec with all external references
314
+ # Download with all external references
479
315
  klasik download \
480
316
  --url https://api.example.com/openapi.json \
481
317
  --output ./specs/api-spec.json \
482
- --header "Authorization: Bearer token123" \
483
318
  --resolve-refs
484
319
  ```
485
320
 
486
- ### `generate-crd`
487
-
488
- Generate TypeScript models from Kubernetes CustomResourceDefinition (CRD) YAML files.
321
+ ### `klasik generate-crd`
489
322
 
490
- **Options:**
491
- - `-u, --url <url...>` - URL(s) or file path(s) to CRD YAML files (required)
492
- - Can be specified multiple times: `-u url1 -u url2 -u url3`
493
- - All CRDs from all URLs are merged into a single output directory
494
- - Supports: `https://...`, `http://...`, `file://...`, `/absolute/path`, `./relative/path`
495
- - `-o, --output <dir>` - Output directory for generated models (required)
496
- - `--include-status` - Generate status schemas in addition to spec schemas (default: false)
497
- - By default, only spec models are generated
498
- - Enable this to also generate status models for reading resource status
499
- - `--nestjs-swagger` - Include NestJS Swagger `@ApiProperty` decorators
500
- - `--class-validator` - Include class-validator decorators
501
- - `--esm` - Add `.js` extensions to imports for ESM compatibility
502
- - `-H, --header <header...>` - Custom headers for HTTP requests (format: "Key: Value")
503
- - `-t, --template <dir>` - Custom template directory
504
- - `-k, --keep-spec` - Keep the generated OpenAPI spec files (for debugging)
505
- - `--crd-kind-case <format>` - Format for CRD kind names in folder names (default: pascal)
506
- - `pascal`: `AppProject` (default)
507
- - `snake`: `app_project`
508
- - `kebab`: `app-project`
509
- - `--timeout <ms>` - Request timeout in milliseconds (default: 30000)
323
+ Generate TypeScript models from Kubernetes CustomResourceDefinitions.
510
324
 
511
- **Examples:**
325
+ **Usage:**
512
326
 
513
327
  ```bash
514
- # Generate from ArgoCD AppProject CRD
515
- klasik generate-crd \
516
- --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
517
- --output ./generated/crds
328
+ klasik generate-crd [options]
329
+ ```
518
330
 
519
- # Generate from multiple CRD URLs (merged into single output)
520
- klasik generate-crd \
521
- -u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
522
- -u https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
523
- --output ./generated/argocd
331
+ **Options:**
524
332
 
525
- # Mix remote and local CRDs
526
- klasik generate-crd \
527
- -u https://example.com/crd1.yaml \
528
- -u ./crds/crd2.yaml \
529
- -u ./crds/crd3.yaml \
530
- --output ./src/generated
333
+ | Option | Description | Default |
334
+ |--------|-------------|---------|
335
+ | `-u, --url <url>` | CRD URL or file path (repeatable) | - |
336
+ | `-o, --output <dir>` | Output directory (required) | - |
337
+ | `--include-status` | Generate status schemas | `false` |
338
+ | `--crd-kind-case <format>` | Folder naming: `pascal`, `snake`, `kebab` | `pascal` |
339
+ | `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
340
+ | `--class-validator` | Add class-validator decorators | `false` |
341
+ | `--esm` | Add .js extensions for ESM | `false` |
342
+ | `--header <header>` | Custom header (repeatable) | - |
343
+ | `--resolve-refs` | Resolve external $ref files | `false` |
344
+ | `--template <dir>` | Custom template directory | - |
345
+ | `--keep-spec` | Keep downloaded spec file(s) | `false` |
346
+ | `--timeout <ms>` | Request timeout | `30000` |
347
+
348
+ **Examples:**
531
349
 
532
- # Generate with status models
350
+ ```bash
351
+ # Single CRD
533
352
  klasik generate-crd \
534
353
  --url ./my-crd.yaml \
535
- --output ./generated \
536
- --include-status
354
+ --output ./src/types
537
355
 
538
- # NestJS integration with validation
356
+ # Multiple CRDs (automatic deduplication)
539
357
  klasik generate-crd \
540
- --url ./crds/ \
541
- --output ./src/generated/k8s \
358
+ --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
359
+ --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
360
+ --output ./src/generated \
361
+ --crd-kind-case kebab \
542
362
  --nestjs-swagger \
543
363
  --class-validator
544
364
 
545
- # From local file with authentication (if downloading references)
546
- klasik generate-crd \
547
- --url ./local-crd.yaml \
548
- --output ./generated \
549
- --header "Authorization: Bearer token"
550
-
551
- # Multi-CRD file
552
- klasik generate-crd \
553
- --url ./all-crds.yaml \
554
- --output ./generated \
555
- --include-status \
556
- --nestjs-swagger
557
-
558
- # Generate with snake_case folder names
365
+ # With status schemas
559
366
  klasik generate-crd \
560
- --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
561
- --output ./generated \
562
- --crd-kind-case snake
367
+ --url ./operator-crd.yaml \
368
+ --output ./src/types \
369
+ --include-status
563
370
 
564
- # Generate with kebab-case folder names
371
+ # With authentication
565
372
  klasik generate-crd \
566
- --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml \
567
- --output ./generated \
568
- --crd-kind-case kebab
373
+ --url https://private-repo.com/crd.yaml \
374
+ --output ./src/types \
375
+ --header "Authorization: Bearer ${TOKEN}"
569
376
  ```
570
377
 
571
- **Output Structure:**
378
+ ### `klasik generate-jsonschema`
572
379
 
573
- For a single CRD:
574
- ```
575
- output/
576
- ├── v1alpha1/
577
- │ └── models/
578
- │ ├── my-resource.ts
579
- │ ├── my-resource-spec.ts
580
- │ ├── my-resource-status.ts (if --include-status)
581
- │ └── ...
582
- └── index.ts
583
- ```
380
+ Generate TypeScript models from JSON Schema files.
584
381
 
585
- For multiple CRDs with `--crd-kind-case pascal` (default):
586
- ```
587
- output/
588
- ├── AppProject/
589
- │ ├── v1alpha1/
590
- │ └── index.ts
591
- ├── Application/
592
- │ ├── v1alpha1/
593
- │ └── index.ts
594
- └── index.ts
595
- ```
382
+ **Usage:**
596
383
 
597
- With `--crd-kind-case snake`:
598
- ```
599
- output/
600
- ├── app_project/
601
- │ ├── v1alpha1/
602
- │ └── index.ts
603
- ├── application/
604
- │ ├── v1alpha1/
605
- │ └── index.ts
606
- └── index.ts
607
- ```
608
-
609
- With `--crd-kind-case kebab`:
610
- ```
611
- output/
612
- ├── app-project/
613
- │ ├── v1alpha1/
614
- │ └── index.ts
615
- ├── application/
616
- │ ├── v1alpha1/
617
- │ └── index.ts
618
- └── index.ts
384
+ ```bash
385
+ klasik generate-jsonschema [options]
619
386
  ```
620
387
 
621
- ### `generate-jsonschema`
622
-
623
- Generate TypeScript models from JSON Schema files.
624
-
625
388
  **Options:**
626
- - `-u, --url <url...>` - URL(s) or file path(s) to JSON Schema files (required)
627
- - Can be specified multiple times: `-u url1 -u url2 -u url3`
628
- - All schemas from all URLs are merged into a single output directory
629
- - Supports: `https://...`, `http://...`, `file://...`, `/absolute/path`, `./relative/path`
630
- - `-o, --output <dir>` - Output directory for generated models (required)
631
- - `--nestjs-swagger` - Include NestJS Swagger `@ApiProperty` decorators
632
- - `--class-validator` - Include class-validator decorators
633
- - `--esm` - Add `.js` extensions to imports for ESM compatibility
634
- - `-H, --header <header...>` - Custom headers for HTTP requests (format: "Key: Value")
635
- - `-t, --template <dir>` - Custom template directory
636
- - `-k, --keep-spec` - Keep the generated OpenAPI spec files (for debugging)
637
- - `--timeout <ms>` - Request timeout in milliseconds (default: 30000)
389
+
390
+ | Option | Description | Default |
391
+ |--------|-------------|---------|
392
+ | `-u, --url <url>` | JSON Schema URL or file path (repeatable) | - |
393
+ | `-o, --output <dir>` | Output directory (required) | - |
394
+ | `--nestjs-swagger` | Add @ApiProperty decorators | `false` |
395
+ | `--class-validator` | Add class-validator decorators | `false` |
396
+ | `--esm` | Add .js extensions for ESM | `false` |
397
+ | `--header <header>` | Custom header (repeatable) | - |
398
+ | `--resolve-refs` | Resolve external $ref files | `false` |
399
+ | `--template <dir>` | Custom template directory | - |
400
+ | `--keep-spec` | Keep intermediate OpenAPI specs | `false` |
401
+ | `--timeout <ms>` | Request timeout | `30000` |
638
402
 
639
403
  **Examples:**
640
404
 
641
405
  ```bash
642
- # Generate from SchemaStore
643
- klasik generate-jsonschema \
644
- --url https://json.schemastore.org/kustomization.json \
645
- --output ./generated/kustomization
646
-
647
- # Generate from multiple JSON Schema files (merged into single output)
406
+ # From SchemaStore
648
407
  klasik generate-jsonschema \
649
- -u https://json.schemastore.org/kustomization.json \
650
- -u https://json.schemastore.org/package.json \
651
- --output ./generated/schemas
408
+ --url https://json.schemastore.org/package.json \
409
+ --output ./src/types
652
410
 
653
- # Mix remote and local schemas
411
+ # Multiple schemas
654
412
  klasik generate-jsonschema \
655
- -u https://json.schemastore.org/kustomization.json \
656
- -u ./schemas/my-schema.json \
657
- -u ./schemas/another-schema.json \
413
+ --url https://json.schemastore.org/kustomization.json \
414
+ --url https://json.schemastore.org/package.json \
658
415
  --output ./src/generated
659
416
 
660
- # NestJS integration with validation
417
+ # From local file
661
418
  klasik generate-jsonschema \
662
- --url ./schemas/ \
663
- --output ./src/generated/models \
419
+ --url ./schemas/user.json \
420
+ --output ./src/types \
664
421
  --nestjs-swagger \
665
422
  --class-validator
666
-
667
- # From local file with ESM support
668
- klasik generate-jsonschema \
669
- --url ./local-schema.json \
670
- --output ./generated \
671
- --esm
672
-
673
- # Keep intermediate OpenAPI specs for debugging
674
- klasik generate-jsonschema \
675
- --url https://json.schemastore.org/kustomization.json \
676
- --output ./generated \
677
- --keep-spec
678
- ```
679
-
680
- **Output Structure:**
681
-
682
- ```
683
- output/
684
- ├── models/
685
- │ ├── type-a.ts
686
- │ ├── type-b.ts
687
- │ └── ... (all definitions from all schemas)
688
- └── index.ts
689
- ```
690
-
691
- ## Programmatic API
692
-
693
- ### OpenAPIClientGenerator
694
-
695
- ```typescript
696
- import { OpenAPIClientGenerator } from 'klasik';
697
-
698
- const generator = new OpenAPIClientGenerator();
699
-
700
- await generator.generate({
701
- specUrl: 'https://api.example.com/openapi.json',
702
- outputDir: './client',
703
- mode: 'models-only',
704
- headers: {
705
- 'Authorization': 'Bearer token123',
706
- 'X-Custom-Header': 'value'
707
- },
708
- resolveReferences: true, // Download external $ref files
709
- nestJsSwagger: true, // Include @ApiProperty decorators
710
- classValidator: true, // Include validation decorators
711
- templateDir: './custom-templates', // Optional
712
- keepSpec: true, // Keep downloaded spec file
713
- timeout: 60000 // Request timeout in ms
714
- });
715
423
  ```
716
424
 
717
- ### SpecDownloader
718
-
719
- ```typescript
720
- import { SpecDownloader } from 'klasik';
721
-
722
- const downloader = new SpecDownloader();
425
+ ## Kubernetes CRD Support
723
426
 
724
- const specPath = await downloader.download({
725
- url: 'https://api.example.com/openapi.json',
726
- outputPath: './specs/api-spec.json',
727
- headers: {
728
- 'Authorization': 'Bearer token123'
729
- },
730
- resolveReferences: true, // Download external $ref files
731
- timeout: 30000
732
- });
427
+ Klasik can generate TypeScript models directly from Kubernetes CustomResourceDefinitions (CRDs). Perfect for working with custom Kubernetes resources like ArgoCD Applications, Cert-Manager Certificates, or your own custom resources.
733
428
 
734
- console.log(`Spec downloaded to: ${specPath}`);
429
+ ### Features
735
430
 
736
- // Clean up temporary files
737
- downloader.cleanupTemp();
738
- ```
431
+ - **Automatic schema extraction** from `openAPIV3Schema`
432
+ - ✅ **Multiple URL support** - Generate from multiple CRDs in one command
433
+ - ✅ **Automatic deduplication** - Shared types (ObjectMeta, TypeMeta) generated once
434
+ - ✅ **Multi-document YAML** - Process multiple CRDs from a single file
435
+ - ✅ **Nested type extraction** - Complex objects become separate interfaces
436
+ - ✅ **Full decorator support** - NestJS, class-validator, class-transformer
437
+ - ✅ **Status schemas** - Optional with `--include-status`
438
+ - ✅ **Version support** - Handles multiple CRD versions (v1alpha1, v1, etc.)
739
439
 
740
- ### CRDGenerator
440
+ ### Automatic Deduplication
741
441
 
742
- Generate TypeScript models from Kubernetes CustomResourceDefinitions programmatically:
442
+ When generating from multiple CRDs, Klasik automatically deduplicates shared types by name:
743
443
 
744
- ```typescript
745
- import { CRDGenerator } from 'klasik';
746
-
747
- const generator = new CRDGenerator();
748
-
749
- await generator.generate({
750
- url: 'https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/appproject-crd.yaml',
751
- outputDir: './generated/crds',
752
- includeStatus: true, // Generate status models
753
- nestJsSwagger: true, // Include @ApiProperty decorators
754
- classValidator: true, // Include validation decorators
755
- fixEsmImports: false, // Add .js extensions
756
- headers: {
757
- 'Authorization': 'Bearer token123'
758
- },
759
- timeout: 60000
760
- });
444
+ ```bash
445
+ klasik generate-crd \
446
+ --url application-crd.yaml \ # Defines ObjectMeta
447
+ --url appproject-crd.yaml \ # Also defines ObjectMeta
448
+ --output ./generated
761
449
  ```
762
450
 
763
- **CRDGeneratorOptions:**
764
- - `url: string` - URL or file path to CRD YAML (required)
765
- - `outputDir: string` - Output directory (required)
766
- - `includeStatus?: boolean` - Generate status schemas (default: false)
767
- - `headers?: Record<string, string>` - Custom HTTP headers
768
- - `timeout?: number` - Request timeout in milliseconds (default: 30000)
769
- - `fixEsmImports?: boolean` - Add .js extensions for ESM (default: false)
770
- - `nestJsSwagger?: boolean` - Include NestJS decorators (default: false)
771
- - `classValidator?: boolean` - Include validation decorators (default: false)
772
- - `skipJsExtensions?: boolean` - Skip .js extensions (default: false)
773
- - `templateDir?: string` - Custom template directory
774
- - `keepSpec?: boolean` - Keep intermediate OpenAPI specs (default: false)
775
-
776
- **Multi-CRD YAML:**
777
-
778
- The CRDGenerator automatically handles multi-document YAML files:
779
-
780
- ```typescript
781
- // This YAML contains multiple CRDs separated by ---
782
- await generator.generate({
783
- url: './all-crds.yaml', // Contains AppProject, Application, etc.
784
- outputDir: './generated',
785
- includeStatus: true
786
- });
787
-
788
- // Output will be organized by CRD kind
789
- // ./generated/AppProject/v1alpha1/...
790
- // ./generated/Application/v1alpha1/...
791
- ```
451
+ **Result:** Only ONE `object-meta.ts` file is generated. The last CRD's definition is used (controllable via URL order).
792
452
 
793
- ## Generated Client Features
794
-
795
- The generated TypeScript client includes:
796
-
797
- - ✅ **Class-transformer decorators** - `@Expose()` and `@Type()` on all models
798
- - ✅ **Automatic response transformation** - API responses converted to class instances
799
- - ✅ **Runtime type metadata** - Static `attributeTypeMap` on all models
800
- - ✅ **Union type support** - `anyOf` schemas become TypeScript unions
801
- - ✅ **Rich TSDoc comments** - Comprehensive documentation from OpenAPI spec metadata
802
- - ✅ **Vendor extensions** - Preserved in JSDoc comments and metadata
803
- - ✅ **Error handling** - Configurable transformation error handlers
804
- - ✅ **Configuration options** - Enable/disable transformation, custom error handlers
805
- - ✅ **NestJS Swagger decorators** (optional) - `@ApiProperty` with type, description, example, required, and nullable when `--nestjs-swagger` is enabled
806
- - ✅ **class-validator decorators** (optional) - Runtime validation decorators when `--class-validator` is enabled (full support in v2.0+)
807
-
808
- ### Enhanced TSDoc Documentation
809
-
810
- Klasik includes enhanced Mustache templates that generate rich TSDoc comments from your OpenAPI specification. The generated code includes:
811
-
812
- **For Models:**
813
- - Class-level documentation with description
814
- - Property descriptions from OpenAPI schema
815
- - Type information with `@type` tags
816
- - Validation constraints (`@minimum`, `@maximum`, `@minLength`, `@maxLength`, `@pattern`)
817
- - Format specifications (`@format`)
818
- - Example values (`@example`)
819
- - Required field markers (`@required`)
820
- - Deprecation warnings (`@deprecated`)
821
-
822
- **For API Endpoints:**
823
- - Method name and HTTP verb (`@method`)
824
- - Summary and detailed descriptions
825
- - Parameter documentation with types and requirements
826
- - Return type information
827
- - Error scenarios (`@throws`)
828
- - Deprecation notices
829
-
830
- Example generated model with rich TSDoc:
453
+ ### Generated Structure
831
454
 
832
- ```typescript
833
- /**
834
- * User
835
- *
836
- * Represents a user in the system
837
- *
838
- * @export
839
- * @class User
840
- */
841
- export class User {
842
- /**
843
- * id - Unique identifier for the user
844
- *
845
- * @type {string}
846
- * @memberof User
847
- * @required
848
- * @format uuid
849
- * @example "550e8400-e29b-41d4-a716-446655440000"
850
- */
851
- @Expose()
852
- 'id': string;
853
-
854
- /**
855
- * email - User's email address
856
- *
857
- * @type {string}
858
- * @memberof User
859
- * @required
860
- * @format email
861
- * @pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
862
- */
863
- @Expose()
864
- 'email': string;
865
- }
866
455
  ```
867
-
868
- Example generated API method:
869
-
870
- ```typescript
871
- /**
872
- * getUserById - Get user by ID
873
- *
874
- * Retrieves a single user by their unique identifier
875
- *
876
- * @method GET
877
- * @summary Get user by ID
878
- * @param {string} userId - The user's unique identifier (required)
879
- * @param {RawAxiosRequestConfig} [options] Override http request option.
880
- * @throws {RequiredError} When required parameters are missing
881
- * @returns {Promise<AxiosResponse<User>>}
882
- */
883
- async getUserById(userId: string, options?: RawAxiosRequestConfig): Promise<AxiosResponse<User>>
456
+ src/generated/
457
+ └── models/
458
+ ├── application.ts # Main Application CRD
459
+ ├── application-spec.ts # Nested spec type
460
+ ├── application-status.ts # Status (with --include-status)
461
+ ├── app-project.ts # Main AppProject CRD
462
+ ├── object-meta.ts # SHARED (deduplicated)
463
+ ├── type-meta.ts # SHARED (deduplicated)
464
+ ├── package.json
465
+ ├── tsconfig.json
466
+ └── index.ts # Barrel exports
884
467
  ```
885
468
 
886
- These templates automatically extract metadata from your OpenAPI spec and format it as proper TSDoc comments, making your generated client code well-documented and IDE-friendly with IntelliSense support.
887
-
888
- **Note:** Klasik's templates automatically handle special characters in descriptions by using proper escaping, ensuring your TSDoc comments are always valid even when OpenAPI descriptions contain characters like `*`, `/`, `@`, etc.
889
-
890
- ### Using the Generated Client
469
+ ### Using Generated CRD Models
891
470
 
892
471
  ```typescript
893
- import { DefaultApi, Configuration } from './generated-client';
894
- import { plainToInstance } from 'class-transformer';
895
-
896
- // Create API client
897
- const config = new Configuration({
898
- basePath: 'https://api.example.com',
899
- enableResponseTransformation: true, // Default
900
- onTransformationError: (error, modelClass, data) => {
901
- console.error('Transformation failed:', error);
902
- }
903
- });
904
-
905
- const api = new DefaultApi(config);
906
-
907
- // Get user - response is automatically transformed to User class instance
908
- const response = await api.getUserById({ id: '123' });
909
- const user = response.data; // user is instanceof User ✅
472
+ import { Application } from './generated/models';
473
+
474
+ const app = new Application();
475
+ app.apiVersion = 'argoproj.io/v1alpha1';
476
+ app.kind = 'Application';
477
+ app.metadata = {
478
+ name: 'my-app',
479
+ namespace: 'default'
480
+ };
481
+ app.spec = {
482
+ project: 'default',
483
+ source: {
484
+ repoURL: 'https://github.com/example/repo',
485
+ path: '.',
486
+ targetRevision: 'HEAD'
487
+ },
488
+ destination: {
489
+ server: 'https://kubernetes.default.svc',
490
+ namespace: 'default'
491
+ }
492
+ };
910
493
 
911
- console.log(user.name); // Fully typed!
494
+ // Full TypeScript intellisense and type checking!
912
495
  ```
913
496
 
914
- ## External Reference Resolution
915
-
916
- Klasik can automatically resolve and download external `$ref` references in your OpenAPI specs. This is useful when your spec splits schemas across multiple files.
917
-
918
- ### How It Works
919
-
920
- When you enable `--resolve-refs` (CLI) or `resolveReferences: true` (programmatic), klasik will:
921
-
922
- 1. **Parse the main spec** for external `$ref` references
923
- 2. **Download all referenced files** preserving directory structure
924
- 3. **Recursively resolve nested references** in downloaded files
925
- 4. **Use the same authentication** for all downloads
926
-
927
- ### Example OpenAPI Spec with External References
497
+ ## JSON Schema Support
928
498
 
929
- ```json
930
- {
931
- "openapi": "3.0.0",
932
- "paths": {
933
- "/users": {
934
- "get": {
935
- "responses": {
936
- "200": {
937
- "content": {
938
- "application/json": {
939
- "schema": {
940
- "$ref": "./schemas/users-orgs.yaml#/components/schemas/Org"
941
- }
942
- }
943
- }
944
- }
945
- }
946
- }
947
- }
948
- }
949
- }
950
- ```
499
+ Klasik can generate TypeScript models from JSON Schema files (like those from [SchemaStore.org](https://schemastore.org)). Perfect for configuration files, data formats, and schema definitions.
951
500
 
952
- With `--resolve-refs`, klasik will automatically download `./schemas/users-orgs.yaml` and any files it references.
501
+ ### Features
953
502
 
954
- ### Output Structure
503
+ - **All definitions generated** - Creates models for every definition
504
+ - ✅ **Multiple URL support** - Merge models from multiple schemas
505
+ - ✅ **Standards compliant** - Supports JSON Schema Draft 4 and Draft 7
506
+ - ✅ **Nested type extraction** - Complex objects become separate interfaces
507
+ - ✅ **Full decorator support** - NestJS, class-validator, class-transformer
508
+ - ✅ **Automatic naming** - Schema title or filename becomes class name
955
509
 
956
- Referenced files are downloaded preserving the directory structure:
510
+ ### Generated Structure
957
511
 
958
512
  ```
959
513
  output/
960
- ├── openapi-spec.json # Main spec
961
- └── schemas/
962
- ├── users-orgs.yaml # Referenced schema
963
- └── common/
964
- └── types.yaml # Nested reference
965
- ```
966
-
967
- ### Supported Reference Types
968
-
969
- - **Relative paths**: `./schemas/user.yaml`, `../common/types.yaml`
970
- - When the main spec is from a remote URL, relative paths are resolved against the spec's URL
971
- - Example: spec at `https://raw.githubusercontent.com/org/repo/main/api/openapi.yaml` with ref `./schemas/user.yaml` resolves to `https://raw.githubusercontent.com/org/repo/main/api/schemas/user.yaml`
972
- - **Remote URLs**: `https://api.example.com/schemas/user.yaml`
973
- - **Mixed**: Main spec from HTTPS, references can be relative or absolute
974
-
975
- ### CLI Example
976
-
977
- ```bash
978
- # Download spec with all external references
979
- npx klasik generate \
980
- --url https://api.example.com/openapi.json \
981
- --output ./client \
982
- --header "Authorization: Bearer token" \
983
- --resolve-refs
514
+ ├── models/
515
+ │ ├── package.ts
516
+ ├── person.ts
517
+ │ ├── repository.ts
518
+ └── index.ts
519
+ ├── package.json
520
+ └── tsconfig.json
984
521
  ```
985
522
 
986
- ### Programmatic Example
523
+ ### Using Generated JSON Schema Models
987
524
 
988
525
  ```typescript
989
- import { OpenAPIClientGenerator } from 'klasik';
990
-
991
- await new OpenAPIClientGenerator().generate({
992
- specUrl: 'https://api.example.com/openapi.json',
993
- outputDir: './client',
994
- headers: { 'Authorization': 'Bearer token' },
995
- resolveReferences: true,
996
- keepSpec: true // Keep all downloaded files
997
- });
526
+ import { Package } from './generated/models';
527
+
528
+ const pkg: Package = {
529
+ name: 'my-package',
530
+ version: '1.0.0',
531
+ description: 'My awesome package',
532
+ author: {
533
+ name: 'John Doe',
534
+ email: 'john@example.com'
535
+ }
536
+ };
537
+
538
+ // Full TypeScript intellisense and type checking!
998
539
  ```
999
540
 
1000
541
  ## NestJS Integration
1001
542
 
1002
- ### Using with NestJS Applications
1003
-
1004
- Klasik-generated models integrate seamlessly with NestJS applications. Use `--mode models-only` with decorator flags for best results.
543
+ Klasik integrates seamlessly with NestJS, generating models with `@ApiProperty` decorators for automatic Swagger/OpenAPI documentation and `class-validator` decorators for runtime validation.
1005
544
 
1006
- #### Swagger Documentation Support
545
+ ### Setup
1007
546
 
1008
- Generate models with `@ApiProperty` decorators for automatic Swagger documentation:
547
+ Generate models with NestJS support:
1009
548
 
1010
549
  ```bash
1011
- npx klasik generate \
550
+ klasik generate \
1012
551
  --url https://api.example.com/openapi.json \
1013
- --output ./src/generated/dto \
552
+ --output ./src/generated \
1014
553
  --mode models-only \
1015
- --nestjs-swagger
1016
- ```
1017
-
1018
- This generates DTOs like:
1019
-
1020
- ```typescript
1021
- import { Expose } from 'class-transformer';
1022
- import { ApiProperty } from '@nestjs/swagger';
1023
-
1024
- export class UserDto {
1025
- @ApiProperty({
1026
- type: String,
1027
- description: 'Unique identifier',
1028
- required: true,
1029
- example: '123e4567-e89b-41d3-a456-426614174000',
1030
- })
1031
- @Expose()
1032
- id: string;
1033
-
1034
- @ApiProperty({
1035
- type: String,
1036
- description: 'User email address',
1037
- required: true,
1038
- format: 'email',
1039
- })
1040
- @Expose()
1041
- email: string;
1042
- }
554
+ --nestjs-swagger \
555
+ --class-validator
1043
556
  ```
1044
557
 
1045
- Use in your NestJS controllers:
558
+ ### Using in NestJS Controllers
1046
559
 
1047
560
  ```typescript
1048
- import { Controller, Get, Post, Body } from '@nestjs/common';
1049
- import { ApiTags, ApiResponse } from '@nestjs/swagger';
1050
- import { UserDto } from './generated/dto';
561
+ import { Controller, Post, Body } from '@nestjs/common';
562
+ import { ApiTags, ApiOperation } from '@nestjs/swagger';
563
+ import { CreateUserDto } from './generated/models';
1051
564
 
1052
565
  @ApiTags('users')
1053
566
  @Controller('users')
1054
567
  export class UsersController {
1055
- @Get()
1056
- @ApiResponse({ type: [UserDto], status: 200 })
1057
- async findAll(): Promise<UserDto[]> {
1058
- // Your implementation
1059
- }
1060
-
1061
568
  @Post()
1062
- @ApiResponse({ type: UserDto, status: 201 })
1063
- async create(@Body() createUserDto: UserDto): Promise<UserDto> {
1064
- // Your implementation
569
+ @ApiOperation({ summary: 'Create user' })
570
+ async create(@Body() createUserDto: CreateUserDto) {
571
+ // Automatic validation via class-validator
572
+ // Automatic Swagger docs via @ApiProperty
573
+ return this.usersService.create(createUserDto);
1065
574
  }
1066
575
  }
1067
576
  ```
1068
577
 
1069
- Your Swagger UI automatically displays complete documentation from the `@ApiProperty` decorators.
1070
-
1071
- #### Runtime Validation Support
1072
-
1073
- Add the `--class-validator` flag for runtime validation decorators:
1074
-
1075
- ```bash
1076
- npx klasik generate \
1077
- --url https://api.example.com/openapi.json \
1078
- --output ./src/generated/dto \
1079
- --mode models-only \
1080
- --nestjs-swagger \
1081
- --class-validator
1082
- ```
1083
-
1084
- **Note**: Full decorator generation requires openapi-class-transformer v2.0+. For now, the dependencies are added to package.json, and you can manually add validation decorators:
578
+ ### Generated Model Example
1085
579
 
1086
580
  ```typescript
1087
- import { Expose } from 'class-transformer';
1088
581
  import { ApiProperty } from '@nestjs/swagger';
1089
- import { IsString, IsEmail } from 'class-validator';
1090
-
1091
- export class UserDto {
1092
- @ApiProperty({ type: String, required: true })
1093
- @IsString()
1094
- @Expose()
1095
- id: string;
1096
-
1097
- @ApiProperty({ type: String, required: true, format: 'email' })
1098
- @IsEmail()
1099
- @Expose()
1100
- email: string;
1101
- }
1102
- ```
582
+ import { IsString, IsEmail, MinLength, IsOptional } from 'class-validator';
583
+ import { Expose } from 'class-transformer';
1103
584
 
1104
- Use with NestJS ValidationPipe:
585
+ export class CreateUserDto {
586
+ @Expose()
587
+ @ApiProperty({
588
+ type: String,
589
+ description: 'User email address',
590
+ required: true,
591
+ format: 'email'
592
+ })
593
+ @IsEmail()
594
+ email: string;
595
+
596
+ @Expose()
597
+ @ApiProperty({
598
+ type: String,
599
+ description: 'User password',
600
+ required: true,
601
+ minLength: 8
602
+ })
603
+ @IsString()
604
+ @MinLength(8)
605
+ password: string;
1105
606
 
1106
- ```typescript
1107
- import { ValidationPipe } from '@nestjs/common';
1108
-
1109
- // In main.ts
1110
- app.useGlobalPipes(new ValidationPipe({
1111
- transform: true,
1112
- whitelist: true,
1113
- }));
1114
-
1115
- // In controller
1116
- @Post()
1117
- async create(@Body() dto: UserDto): Promise<UserDto> {
1118
- // dto is already validated and transformed to UserDto instance!
607
+ @Expose()
608
+ @ApiProperty({
609
+ type: String,
610
+ description: 'User display name',
611
+ required: false
612
+ })
613
+ @IsString()
614
+ @IsOptional()
615
+ name?: string;
1119
616
  }
1120
617
  ```
1121
618
 
1122
- #### Required Dependencies for NestJS
619
+ ## Advanced Topics
620
+
621
+ ### External Reference Resolution
1123
622
 
1124
- When using `--nestjs-swagger` or `--class-validator`, ensure your project has these peer dependencies:
623
+ When your OpenAPI spec uses external `$ref`, Klasik can automatically download and inline them:
1125
624
 
1126
625
  ```bash
1127
- npm install @nestjs/swagger swagger-ui-express
1128
- npm install class-validator class-transformer
1129
- npm install reflect-metadata
626
+ klasik generate \
627
+ --url ./api-spec.yaml \
628
+ --output ./generated \
629
+ --resolve-refs
1130
630
  ```
1131
631
 
1132
- Update your `tsconfig.json`:
632
+ **What it does:**
633
+ 1. Discovers all external `$ref` recursively
634
+ 2. Downloads referenced files (with auth if needed)
635
+ 3. Inlines them into the main spec
636
+ 4. Generates complete TypeScript types
1133
637
 
1134
- ```json
1135
- {
1136
- "compilerOptions": {
1137
- "experimentalDecorators": true,
1138
- "emitDecoratorMetadata": true
1139
- }
1140
- }
638
+ **Supported formats:**
639
+ - ✅ Relative paths: `./schemas/User.yaml`
640
+ - ✅ Absolute paths: `/path/to/schema.yaml`
641
+ - ✅ Remote URLs: `https://api.example.com/schemas/User.yaml`
642
+ - ✅ With fragments: `./User.yaml#/definitions/User`
643
+ - ✅ Nested refs (ref within ref)
644
+ - ✅ Circular reference detection
645
+
646
+ **Example spec with external refs:**
647
+
648
+ ```yaml
649
+ # main-spec.yaml
650
+ components:
651
+ schemas:
652
+ User:
653
+ $ref: './schemas/user.yaml' # Local file
654
+ Post:
655
+ $ref: 'https://api.example.com/schemas/post.yaml' # Remote URL
656
+ Comment:
657
+ $ref: './schemas/comment.yaml#/Comment' # With fragment
658
+ ```
659
+
660
+ **With authentication:**
661
+ ```bash
662
+ klasik generate \
663
+ --url https://private-api.com/spec.yaml \
664
+ --resolve-refs \
665
+ --header "Authorization: Bearer ${TOKEN}"
1141
666
  ```
1142
667
 
1143
- #### Best Practices
668
+ ### Authentication Headers
1144
669
 
1145
- 1. **Use models-only mode**: Generate only DTOs, keep your NestJS business logic separate
1146
- 2. **Separate directories**: Generate into `src/generated/dto` or similar
1147
- 3. **Extend generated classes**: For complex validation, extend generated DTOs
1148
- 4. **Version control**: Commit generated files or regenerate in CI/CD
670
+ Access private API specs with custom headers:
1149
671
 
1150
- ```typescript
1151
- // Custom DTO extending generated model
1152
- import { UserDto } from '../generated/dto';
1153
- import { IsStrongPassword } from 'class-validator';
672
+ ```bash
673
+ # Bearer token
674
+ klasik generate \
675
+ --url https://internal-api.company.com/spec.json \
676
+ --header "Authorization: Bearer ${API_TOKEN}" \
677
+ --output ./generated
1154
678
 
1155
- export class CreateUserDto extends UserDto {
1156
- @IsStrongPassword()
1157
- password: string;
1158
- }
1159
- ```
679
+ # API key
680
+ klasik generate \
681
+ --url https://api.example.com/spec.json \
682
+ --header "X-API-Key: ${API_KEY}" \
683
+ --output ./generated
1160
684
 
1161
- ## Best Practices for Existing Projects
685
+ # Multiple headers
686
+ klasik generate \
687
+ --url https://api.example.com/spec.json \
688
+ --header "Authorization: Bearer ${TOKEN}" \
689
+ --header "X-Custom-Header: value" \
690
+ --output ./generated
691
+ ```
1162
692
 
1163
- When integrating klasik into an existing TypeScript project, follow these best practices to avoid conflicts:
693
+ ### ESM Support
1164
694
 
1165
- ### Generate into a Subdirectory
695
+ For Node.js ESM projects, use the `--esm` flag to add `.js` extensions to imports:
1166
696
 
1167
697
  ```bash
1168
- # Generate models into src/generated to avoid overwriting project files
1169
- npx klasik generate \
1170
- --url https://api.example.com/openapi.yaml \
1171
- --output ./src/generated \
1172
- --mode models-only \
1173
- --resolve-refs
698
+ klasik generate \
699
+ --url ./openapi.yaml \
700
+ --output ./generated \
701
+ --esm
1174
702
  ```
1175
703
 
1176
- ### Clean Up Generated Config Files
704
+ **Generated imports:**
1177
705
 
1178
- klasik generates `package.json` and `tsconfig.json` files. Remove them after generation:
706
+ ```typescript
707
+ // With --esm
708
+ import { User } from './user.js';
709
+ import { Post } from './post.js';
1179
710
 
1180
- ```json
1181
- // package.json
1182
- {
1183
- "scripts": {
1184
- "generate-client": "npx klasik generate --url $API_URL --output ./src/generated --mode models-only --resolve-refs && npm run cleanup-generated",
1185
- "cleanup-generated": "rm -f ./src/generated/package.json ./src/generated/tsconfig*.json ./src/generated/.openapi-generator*"
1186
- }
1187
- }
711
+ // Without --esm
712
+ import { User } from './user';
713
+ import { Post } from './post';
1188
714
  ```
1189
715
 
1190
- ### TypeScript Configuration for class-transformer
716
+ **For bundlers (webpack, vite, esbuild):**
1191
717
 
1192
- Add these settings to your `tsconfig.json` for compatibility:
718
+ Use `--skip-js-extensions` to omit extensions:
1193
719
 
1194
- ```json
1195
- {
1196
- "compilerOptions": {
1197
- "experimentalDecorators": true,
1198
- "emitDecoratorMetadata": true,
1199
- "skipLibCheck": true // Skip type checking in node_modules (recommended for class-transformer)
1200
- }
1201
- }
720
+ ```bash
721
+ klasik generate \
722
+ --url ./openapi.yaml \
723
+ --output ./generated \
724
+ --esm \
725
+ --skip-js-extensions
1202
726
  ```
1203
727
 
1204
- ### Models-Only Mode
728
+ ### Custom Templates
1205
729
 
1206
- Use `--mode models-only` when you:
1207
- - Only need data models with class-transformer decorators
1208
- - Want to use your own API client (axios, fetch, etc.)
1209
- - Are integrating into an existing project with its own HTTP layer
1210
- - Want to avoid package.json/tsconfig.json conflicts
730
+ Klasik uses Mustache templates for code generation. You can provide custom templates:
1211
731
 
1212
732
  ```bash
1213
- npx klasik generate \
1214
- --url https://api.example.com/openapi.yaml \
1215
- --output ./src/generated \
1216
- --mode models-only # ✅ Generates only models, no API client
733
+ klasik generate \
734
+ --url ./openapi.yaml \
735
+ --output ./generated \
736
+ --template ./my-templates
1217
737
  ```
1218
738
 
1219
- ### Full Mode
739
+ **Template structure:**
1220
740
 
1221
- Use `--mode full` (default) when you:
1222
- - Want a complete ready-to-use axios client
1223
- - Are starting a new project from scratch
1224
- - Want automatic response transformation with class-transformer
1225
-
1226
- ```bash
1227
- npx klasik generate \
1228
- --url https://api.example.com/openapi.yaml \
1229
- --output ./api-client \
1230
- --mode full # Generates complete client with APIs
741
+ ```
742
+ my-templates/
743
+ ├── model.mustache # Model class template
744
+ ├── api-class.mustache # API class template (full mode)
745
+ ├── configuration.mustache # Configuration class template
746
+ └── index.mustache # Barrel export template
1231
747
  ```
1232
748
 
1233
- ### ESM (ECMAScript Modules) Support
749
+ ### Best Practices
1234
750
 
1235
- If your project uses ECMAScript Modules (`"type": "module"` in package.json), use the `--esm` flag to automatically add `.js` extensions to all relative imports:
751
+ #### 1. Use Version Pinning
1236
752
 
1237
- ```bash
1238
- # Generate ESM-compatible code
1239
- npx klasik generate \
1240
- --url https://api.example.com/openapi.yaml \
1241
- --output ./src/generated \
1242
- --mode models-only \
1243
- --esm # ✅ Adds .js extensions to imports
1244
- ```
753
+ For production projects, pin to specific spec versions:
1245
754
 
1246
- **What `--esm` does:**
1247
- - Adds `.js` extensions to all relative imports: `from './user'` → `from './user.js'`
1248
- - Adds `.js` extensions to all relative exports: `export * from './api'` → `export * from './api.js'`
1249
- - Handles directory imports: `from './models'` → `from './models/index.js'`
1250
- - Only affects relative imports (doesn't touch external packages like `axios`, `class-transformer`)
755
+ ```bash
756
+ # Good: Specific commit hash
757
+ klasik generate-crd \
758
+ --url https://raw.githubusercontent.com/argoproj/argo-cd/v2.8.0/manifests/crds/application-crd.yaml \
759
+ --output ./src/types
1251
760
 
1252
- **Before `--esm`:**
1253
- ```typescript
1254
- import { User } from './models/user';
1255
- import { Cluster } from '../models/cluster';
1256
- export * from './api/orgs-api';
761
+ # ❌ Bad: Using master/main branch
762
+ klasik generate-crd \
763
+ --url https://raw.githubusercontent.com/argoproj/argo-cd/master/manifests/crds/application-crd.yaml \
764
+ --output ./src/types
1257
765
  ```
1258
766
 
1259
- **After `--esm`:**
1260
- ```typescript
1261
- import { User } from './models/user.js';
1262
- import { Cluster } from '../models/cluster.js';
1263
- export * from './api/orgs-api.js';
1264
- ```
767
+ #### 2. Keep Generated Code Separate
1265
768
 
1266
- **When to use `--esm`:**
1267
- - Your package.json has `"type": "module"`
1268
- - You're using Node.js native ESM
1269
- - You're targeting modern JavaScript environments
1270
- - You want to eliminate post-processing scripts
769
+ Store generated code in a dedicated directory:
1271
770
 
1272
- **package.json setup for ESM:**
1273
- ```json
1274
- {
1275
- "type": "module",
1276
- "scripts": {
1277
- "generate-client": "npx klasik generate --url $API_URL --output src/generated --mode models-only --esm"
1278
- }
1279
- }
771
+ ```
772
+ src/
773
+ ├── api/
774
+ │ └── generated/ # Generated code here
775
+ │ ├── models/
776
+ │ ├── apis/
777
+ │ └── index.ts
778
+ ├── services/ # Your business logic
779
+ └── controllers/ # Your controllers
1280
780
  ```
1281
781
 
1282
- ## Advanced Configuration
782
+ Add to `.gitignore`:
1283
783
 
1284
- ### Custom Error Handling
1285
-
1286
- ```typescript
1287
- const config = new Configuration({
1288
- basePath: 'https://api.example.com',
1289
- onTransformationError: (error, modelClass, data) => {
1290
- // Log to custom logger
1291
- logger.error('Failed to transform response', {
1292
- error: error.message,
1293
- modelClass: modelClass.name,
1294
- rawData: data
1295
- });
1296
-
1297
- // Send to error tracking
1298
- Sentry.captureException(error);
1299
- }
1300
- });
784
+ ```gitignore
785
+ src/api/generated/
1301
786
  ```
1302
787
 
1303
- ### Disable Transformation
788
+ Regenerate in CI/CD:
1304
789
 
1305
- ```typescript
1306
- const config = new Configuration({
1307
- basePath: 'https://api.example.com',
1308
- enableResponseTransformation: false // Get plain objects
1309
- });
790
+ ```yaml
791
+ # .github/workflows/ci.yml
792
+ - name: Generate API Client
793
+ run: |
794
+ npx klasik generate \
795
+ --url https://api.example.com/openapi.json \
796
+ --output ./src/api/generated \
797
+ --nestjs-swagger \
798
+ --class-validator
1310
799
  ```
1311
800
 
1312
- ## Requirements
801
+ #### 3. Validate After Generation
802
+
803
+ Always compile generated code to catch issues early:
1313
804
 
1314
- - Node.js >= 16
1315
- - TypeScript >= 5.0 (for experimentalDecorators support)
805
+ ```bash
806
+ klasik generate --url ./spec.yaml --output ./generated
807
+ cd ./generated
808
+ npm install
809
+ npm run build
810
+ ```
1316
811
 
1317
- ### TypeScript Configuration
812
+ #### 4. Use Consistent Options
1318
813
 
1319
- Your `tsconfig.json` must include:
814
+ Create a script or Makefile for consistent generation:
1320
815
 
1321
816
  ```json
817
+ // package.json
1322
818
  {
1323
- "compilerOptions": {
1324
- "experimentalDecorators": true,
1325
- "emitDecoratorMetadata": true
819
+ "scripts": {
820
+ "generate": "klasik generate --url https://api.example.com/openapi.json --output ./src/generated --nestjs-swagger --class-validator",
821
+ "generate:crds": "klasik generate-crd --url https://example.com/crd.yaml --output ./src/k8s --include-status"
1326
822
  }
1327
823
  }
1328
824
  ```
@@ -1330,6 +826,10 @@ Your `tsconfig.json` must include:
1330
826
  ## Development
1331
827
 
1332
828
  ```bash
829
+ # Clone the repository
830
+ git clone https://github.com/yourusername/klasik-2.git
831
+ cd klasik-2
832
+
1333
833
  # Install dependencies
1334
834
  npm install
1335
835
 
@@ -1339,20 +839,25 @@ npm run build
1339
839
  # Run tests
1340
840
  npm test
1341
841
 
1342
- # Watch mode
1343
- npm run dev
842
+ # Run CLI locally
843
+ node dist/cli/index.js generate --url ./test-spec.yaml --output ./test-output
1344
844
  ```
1345
845
 
846
+ For more details, see [CONTRIBUTING.md](CONTRIBUTING.md) and [ARCHITECTURE.md](ARCHITECTURE.md).
847
+
1346
848
  ## License
1347
849
 
1348
850
  MIT
1349
851
 
1350
- ## Related Projects
852
+ ## Credits
1351
853
 
1352
- - [openapi-class-transformer](https://github.com/example/openapi-class-transformer) - The underlying generator used by this package
1353
- - [class-transformer](https://github.com/typestack/class-transformer) - Transformation library
1354
- - [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) - OpenAPI code generator
854
+ Built with:
855
+ - [ts-morph](https://github.com/dsherret/ts-morph) - TypeScript Compiler API wrapper
856
+ - [class-transformer](https://github.com/typestack/class-transformer) - Object transformation
857
+ - [class-validator](https://github.com/typestack/class-validator) - Runtime validation
858
+ - [mustache](https://github.com/janl/mustache.js) - Template engine
859
+ - [commander](https://github.com/tj/commander.js) - CLI framework
1355
860
 
1356
- ## Contributing
861
+ ---
1357
862
 
1358
- Contributions are welcome! Please open an issue or submit a pull request.
863
+ **Note:** Klasik is a complete rebuild with AST-based code generation, replacing the string manipulation approach from v1. See [ARCHITECTURE.md](ARCHITECTURE.md) for technical details.