@kattebak/openapi-generator-ts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/dist/cli/commands/generate.d.ts +23 -0
  4. package/dist/cli/commands/generate.d.ts.map +1 -0
  5. package/dist/cli/commands/generate.js +116 -0
  6. package/dist/cli/commands/generate.js.map +1 -0
  7. package/dist/cli/commands/list.d.ts +2 -0
  8. package/dist/cli/commands/list.d.ts.map +1 -0
  9. package/dist/cli/commands/list.js +26 -0
  10. package/dist/cli/commands/list.js.map +1 -0
  11. package/dist/cli/commands/validate.d.ts +6 -0
  12. package/dist/cli/commands/validate.d.ts.map +1 -0
  13. package/dist/cli/commands/validate.js +80 -0
  14. package/dist/cli/commands/validate.js.map +1 -0
  15. package/dist/cli/convert-template.d.ts +31 -0
  16. package/dist/cli/convert-template.d.ts.map +1 -0
  17. package/dist/cli/convert-template.js +204 -0
  18. package/dist/cli/convert-template.js.map +1 -0
  19. package/dist/cli/convert-template.test.d.ts +2 -0
  20. package/dist/cli/convert-template.test.d.ts.map +1 -0
  21. package/dist/cli/convert-template.test.js +74 -0
  22. package/dist/cli/convert-template.test.js.map +1 -0
  23. package/dist/cli/index.d.ts +3 -0
  24. package/dist/cli/index.d.ts.map +1 -0
  25. package/dist/cli/index.js +246 -0
  26. package/dist/cli/index.js.map +1 -0
  27. package/dist/core/config.d.ts +252 -0
  28. package/dist/core/config.d.ts.map +1 -0
  29. package/dist/core/config.js +31 -0
  30. package/dist/core/config.js.map +1 -0
  31. package/dist/core/generator.d.ts +99 -0
  32. package/dist/core/generator.d.ts.map +1 -0
  33. package/dist/core/generator.js +492 -0
  34. package/dist/core/generator.js.map +1 -0
  35. package/dist/core/index.d.ts +4 -0
  36. package/dist/core/index.d.ts.map +1 -0
  37. package/dist/core/index.js +4 -0
  38. package/dist/core/index.js.map +1 -0
  39. package/dist/core/types.d.ts +47 -0
  40. package/dist/core/types.d.ts.map +1 -0
  41. package/dist/core/types.js +5 -0
  42. package/dist/core/types.js.map +1 -0
  43. package/dist/generators/generators.test.d.ts +6 -0
  44. package/dist/generators/generators.test.d.ts.map +1 -0
  45. package/dist/generators/generators.test.js +247 -0
  46. package/dist/generators/generators.test.js.map +1 -0
  47. package/dist/generators/go.d.ts +10 -0
  48. package/dist/generators/go.d.ts.map +1 -0
  49. package/dist/generators/go.js +327 -0
  50. package/dist/generators/go.js.map +1 -0
  51. package/dist/generators/index.d.ts +29 -0
  52. package/dist/generators/index.d.ts.map +1 -0
  53. package/dist/generators/index.js +58 -0
  54. package/dist/generators/index.js.map +1 -0
  55. package/dist/generators/php.d.ts +14 -0
  56. package/dist/generators/php.d.ts.map +1 -0
  57. package/dist/generators/php.js +241 -0
  58. package/dist/generators/php.js.map +1 -0
  59. package/dist/generators/python.d.ts +10 -0
  60. package/dist/generators/python.d.ts.map +1 -0
  61. package/dist/generators/python.js +273 -0
  62. package/dist/generators/python.js.map +1 -0
  63. package/dist/generators/typescript-fetch.d.ts +14 -0
  64. package/dist/generators/typescript-fetch.d.ts.map +1 -0
  65. package/dist/generators/typescript-fetch.js +217 -0
  66. package/dist/generators/typescript-fetch.js.map +1 -0
  67. package/dist/index.d.ts +14 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +16 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/models/codegen-model.d.ts +123 -0
  72. package/dist/models/codegen-model.d.ts.map +1 -0
  73. package/dist/models/codegen-model.js +64 -0
  74. package/dist/models/codegen-model.js.map +1 -0
  75. package/dist/models/codegen-model.test.d.ts +6 -0
  76. package/dist/models/codegen-model.test.d.ts.map +1 -0
  77. package/dist/models/codegen-model.test.js +143 -0
  78. package/dist/models/codegen-model.test.js.map +1 -0
  79. package/dist/models/codegen-operation.d.ts +95 -0
  80. package/dist/models/codegen-operation.d.ts.map +1 -0
  81. package/dist/models/codegen-operation.js +54 -0
  82. package/dist/models/codegen-operation.js.map +1 -0
  83. package/dist/models/codegen-parameter.d.ts +86 -0
  84. package/dist/models/codegen-parameter.d.ts.map +1 -0
  85. package/dist/models/codegen-parameter.js +47 -0
  86. package/dist/models/codegen-parameter.js.map +1 -0
  87. package/dist/models/codegen-property.d.ts +95 -0
  88. package/dist/models/codegen-property.d.ts.map +1 -0
  89. package/dist/models/codegen-property.js +47 -0
  90. package/dist/models/codegen-property.js.map +1 -0
  91. package/dist/models/codegen-response.d.ts +64 -0
  92. package/dist/models/codegen-response.d.ts.map +1 -0
  93. package/dist/models/codegen-response.js +42 -0
  94. package/dist/models/codegen-response.js.map +1 -0
  95. package/dist/models/codegen-security.d.ts +34 -0
  96. package/dist/models/codegen-security.d.ts.map +1 -0
  97. package/dist/models/codegen-security.js +18 -0
  98. package/dist/models/codegen-security.js.map +1 -0
  99. package/dist/models/index.d.ts +8 -0
  100. package/dist/models/index.d.ts.map +1 -0
  101. package/dist/models/index.js +7 -0
  102. package/dist/models/index.js.map +1 -0
  103. package/dist/parser/index.d.ts +4 -0
  104. package/dist/parser/index.d.ts.map +1 -0
  105. package/dist/parser/index.js +4 -0
  106. package/dist/parser/index.js.map +1 -0
  107. package/dist/parser/openapi-parser.d.ts +71 -0
  108. package/dist/parser/openapi-parser.d.ts.map +1 -0
  109. package/dist/parser/openapi-parser.js +195 -0
  110. package/dist/parser/openapi-parser.js.map +1 -0
  111. package/dist/parser/openapi-parser.test.d.ts +6 -0
  112. package/dist/parser/openapi-parser.test.d.ts.map +1 -0
  113. package/dist/parser/openapi-parser.test.js +238 -0
  114. package/dist/parser/openapi-parser.test.js.map +1 -0
  115. package/dist/parser/operation-transformer.d.ts +95 -0
  116. package/dist/parser/operation-transformer.d.ts.map +1 -0
  117. package/dist/parser/operation-transformer.js +634 -0
  118. package/dist/parser/operation-transformer.js.map +1 -0
  119. package/dist/parser/schema-transformer.d.ts +134 -0
  120. package/dist/parser/schema-transformer.d.ts.map +1 -0
  121. package/dist/parser/schema-transformer.js +557 -0
  122. package/dist/parser/schema-transformer.js.map +1 -0
  123. package/dist/template/engine-adapter.d.ts +55 -0
  124. package/dist/template/engine-adapter.d.ts.map +1 -0
  125. package/dist/template/engine-adapter.js +178 -0
  126. package/dist/template/engine-adapter.js.map +1 -0
  127. package/dist/template/engine-adapter.test.d.ts +6 -0
  128. package/dist/template/engine-adapter.test.d.ts.map +1 -0
  129. package/dist/template/engine-adapter.test.js +186 -0
  130. package/dist/template/engine-adapter.test.js.map +1 -0
  131. package/dist/template/index.d.ts +5 -0
  132. package/dist/template/index.d.ts.map +1 -0
  133. package/dist/template/index.js +5 -0
  134. package/dist/template/index.js.map +1 -0
  135. package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
  136. package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
  137. package/dist/template/lambdas/indent-lambdas.js +98 -0
  138. package/dist/template/lambdas/indent-lambdas.js.map +1 -0
  139. package/dist/template/lambdas/index.d.ts +44 -0
  140. package/dist/template/lambdas/index.d.ts.map +1 -0
  141. package/dist/template/lambdas/index.js +79 -0
  142. package/dist/template/lambdas/index.js.map +1 -0
  143. package/dist/template/lambdas/string-lambdas.d.ts +78 -0
  144. package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
  145. package/dist/template/lambdas/string-lambdas.js +148 -0
  146. package/dist/template/lambdas/string-lambdas.js.map +1 -0
  147. package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
  148. package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
  149. package/dist/template/lambdas/string-lambdas.test.js +158 -0
  150. package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
  151. package/dist/template/template-locator.d.ts +72 -0
  152. package/dist/template/template-locator.d.ts.map +1 -0
  153. package/dist/template/template-locator.js +173 -0
  154. package/dist/template/template-locator.js.map +1 -0
  155. package/dist/template/template-manager.d.ts +65 -0
  156. package/dist/template/template-manager.d.ts.map +1 -0
  157. package/dist/template/template-manager.js +185 -0
  158. package/dist/template/template-manager.js.map +1 -0
  159. package/package.json +67 -0
  160. package/templates/go/.travis.yml +8 -0
  161. package/templates/go/README.mustache +236 -0
  162. package/templates/go/api.mustache +452 -0
  163. package/templates/go/api_doc.mustache +92 -0
  164. package/templates/go/api_test.mustache +59 -0
  165. package/templates/go/client.mustache +761 -0
  166. package/templates/go/configuration.mustache +332 -0
  167. package/templates/go/git_push.sh.mustache +57 -0
  168. package/templates/go/gitignore.mustache +24 -0
  169. package/templates/go/go.mod.mustache +16 -0
  170. package/templates/go/go.sum.mustache +19 -0
  171. package/templates/go/model.mustache +21 -0
  172. package/templates/go/model_anyof.mustache +93 -0
  173. package/templates/go/model_doc.mustache +97 -0
  174. package/templates/go/model_enum.mustache +101 -0
  175. package/templates/go/model_oneof.mustache +160 -0
  176. package/templates/go/model_simple.mustache +572 -0
  177. package/templates/go/nullable_model.mustache +35 -0
  178. package/templates/go/openapi.mustache +1 -0
  179. package/templates/go/partial_header.mustache +18 -0
  180. package/templates/go/response.mustache +38 -0
  181. package/templates/go/signing.mustache +453 -0
  182. package/templates/go/utils.mustache +352 -0
  183. package/templates/php/.php-cs-fixer.dist.php +29 -0
  184. package/templates/php/.travis.yml +8 -0
  185. package/templates/php/ApiException.mustache +111 -0
  186. package/templates/php/Configuration.mustache +606 -0
  187. package/templates/php/FormDataProcessor.mustache +238 -0
  188. package/templates/php/HeaderSelector.mustache +265 -0
  189. package/templates/php/ModelInterface.mustache +103 -0
  190. package/templates/php/ObjectSerializer.mustache +591 -0
  191. package/templates/php/README.mustache +151 -0
  192. package/templates/php/api.mustache +891 -0
  193. package/templates/php/api_doc.mustache +105 -0
  194. package/templates/php/api_test.mustache +80 -0
  195. package/templates/php/composer.mustache +44 -0
  196. package/templates/php/git_push.sh.mustache +57 -0
  197. package/templates/php/gitignore +15 -0
  198. package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
  199. package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
  200. package/templates/php/libraries/psr-18/README.mustache +161 -0
  201. package/templates/php/libraries/psr-18/api.mustache +833 -0
  202. package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
  203. package/templates/php/libraries/psr-18/composer.mustache +56 -0
  204. package/templates/php/model.mustache +47 -0
  205. package/templates/php/model_doc.mustache +10 -0
  206. package/templates/php/model_enum.mustache +33 -0
  207. package/templates/php/model_generic.mustache +565 -0
  208. package/templates/php/model_test.mustache +88 -0
  209. package/templates/php/partial_header.mustache +18 -0
  210. package/templates/php/php_doc_auth_partial.mustache +23 -0
  211. package/templates/php/phpunit.xml.mustache +18 -0
  212. package/templates/python/README.mustache +60 -0
  213. package/templates/python/README_onlypackage.mustache +50 -0
  214. package/templates/python/__init__.mustache +1 -0
  215. package/templates/python/__init__api.mustache +19 -0
  216. package/templates/python/__init__model.mustache +22 -0
  217. package/templates/python/__init__package.mustache +49 -0
  218. package/templates/python/api.mustache +244 -0
  219. package/templates/python/api_client.mustache +822 -0
  220. package/templates/python/api_doc.mustache +81 -0
  221. package/templates/python/api_doc_example.mustache +38 -0
  222. package/templates/python/api_response.mustache +21 -0
  223. package/templates/python/api_test.mustache +48 -0
  224. package/templates/python/asyncio/rest.mustache +209 -0
  225. package/templates/python/common_README.mustache +85 -0
  226. package/templates/python/configuration.mustache +806 -0
  227. package/templates/python/exceptions.mustache +210 -0
  228. package/templates/python/exports_api.mustache +3 -0
  229. package/templates/python/exports_model.mustache +3 -0
  230. package/templates/python/exports_package.mustache +20 -0
  231. package/templates/python/git_push.sh.mustache +57 -0
  232. package/templates/python/github-workflow.mustache +35 -0
  233. package/templates/python/gitignore.mustache +66 -0
  234. package/templates/python/gitlab-ci.mustache +31 -0
  235. package/templates/python/httpx/rest.mustache +190 -0
  236. package/templates/python/model.mustache +16 -0
  237. package/templates/python/model_anyof.mustache +182 -0
  238. package/templates/python/model_doc.mustache +40 -0
  239. package/templates/python/model_enum.mustache +36 -0
  240. package/templates/python/model_generic.mustache +403 -0
  241. package/templates/python/model_oneof.mustache +209 -0
  242. package/templates/python/model_test.mustache +60 -0
  243. package/templates/python/partial_api.mustache +52 -0
  244. package/templates/python/partial_api_args.mustache +18 -0
  245. package/templates/python/partial_header.mustache +19 -0
  246. package/templates/python/py.typed.mustache +1 -0
  247. package/templates/python/pyproject.mustache +172 -0
  248. package/templates/python/python_doc_auth_partial.mustache +108 -0
  249. package/templates/python/requirements.mustache +23 -0
  250. package/templates/python/rest.mustache +254 -0
  251. package/templates/python/setup.mustache +60 -0
  252. package/templates/python/setup_cfg.mustache +2 -0
  253. package/templates/python/signing.mustache +422 -0
  254. package/templates/python/test-requirements.mustache +6 -0
  255. package/templates/python/tornado/rest.mustache +148 -0
  256. package/templates/python/tox.mustache +9 -0
  257. package/templates/python/travis.mustache +17 -0
  258. package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
  259. package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
  260. package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
  261. package/templates/typescript-fetch/README.mustache +127 -0
  262. package/templates/typescript-fetch/allSagas.mustache +19 -0
  263. package/templates/typescript-fetch/api_doc.mustache +63 -0
  264. package/templates/typescript-fetch/api_example.mustache +44 -0
  265. package/templates/typescript-fetch/apis.index.mustache +16 -0
  266. package/templates/typescript-fetch/apis.mustache +483 -0
  267. package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
  268. package/templates/typescript-fetch/gitignore +4 -0
  269. package/templates/typescript-fetch/index.mustache +17 -0
  270. package/templates/typescript-fetch/licenseInfo.mustache +11 -0
  271. package/templates/typescript-fetch/modelEnum.mustache +28 -0
  272. package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
  273. package/templates/typescript-fetch/modelGeneric.mustache +261 -0
  274. package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
  275. package/templates/typescript-fetch/modelOneOf.mustache +255 -0
  276. package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
  277. package/templates/typescript-fetch/model_doc.mustache +41 -0
  278. package/templates/typescript-fetch/models.index.mustache +32 -0
  279. package/templates/typescript-fetch/models.mustache +24 -0
  280. package/templates/typescript-fetch/npmignore.mustache +1 -0
  281. package/templates/typescript-fetch/package.mustache +43 -0
  282. package/templates/typescript-fetch/recordGeneric.mustache +295 -0
  283. package/templates/typescript-fetch/records.mustache +17 -0
  284. package/templates/typescript-fetch/runtime.mustache +424 -0
  285. package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
  286. package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
  287. package/templates/typescript-fetch/sagas.mustache +245 -0
  288. package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
  289. package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
  290. package/templates/typescript-fetch/tsconfig.mustache +25 -0
@@ -0,0 +1,72 @@
1
+ import type { TemplatePathLocator } from "../core/types.js";
2
+ /**
3
+ * Locator that searches for templates in a custom directory with library support
4
+ */
5
+ export declare class CustomLibraryLocator implements TemplatePathLocator {
6
+ private customDir;
7
+ private library?;
8
+ constructor(customDir: string, library?: string | undefined);
9
+ getFullTemplatePath(name: string): string | null;
10
+ private existsWithExtensions;
11
+ }
12
+ /**
13
+ * Locator that searches for templates in a custom directory
14
+ */
15
+ export declare class CustomGeneratorLocator implements TemplatePathLocator {
16
+ private customDir;
17
+ constructor(customDir: string);
18
+ getFullTemplatePath(name: string): string | null;
19
+ private existsWithExtensions;
20
+ }
21
+ /**
22
+ * Locator that searches for templates in embedded resources with library support
23
+ */
24
+ export declare class EmbeddedLibraryLocator implements TemplatePathLocator {
25
+ private embeddedDir;
26
+ private generatorName;
27
+ private library?;
28
+ constructor(embeddedDir: string, generatorName: string, library?: string | undefined);
29
+ getFullTemplatePath(name: string): string | null;
30
+ private existsWithExtensions;
31
+ }
32
+ /**
33
+ * Locator that searches for templates in embedded generator resources
34
+ */
35
+ export declare class EmbeddedGeneratorLocator implements TemplatePathLocator {
36
+ private embeddedDir;
37
+ private generatorName;
38
+ constructor(embeddedDir: string, generatorName: string);
39
+ getFullTemplatePath(name: string): string | null;
40
+ private existsWithExtensions;
41
+ }
42
+ /**
43
+ * Locator that searches for templates in common embedded resources
44
+ */
45
+ export declare class CommonEmbeddedLocator implements TemplatePathLocator {
46
+ private embeddedDir;
47
+ constructor(embeddedDir: string);
48
+ getFullTemplatePath(name: string): string | null;
49
+ private existsWithExtensions;
50
+ }
51
+ export interface TemplateLocatorChainOptions {
52
+ customDir?: string;
53
+ embeddedDir: string;
54
+ generatorName: string;
55
+ library?: string;
56
+ }
57
+ /**
58
+ * Create a chain of template locators with the correct priority order
59
+ *
60
+ * Resolution priority:
61
+ * 1. custom/libraries/{library}/{template}
62
+ * 2. custom/{template}
63
+ * 3. embedded/{generator}/libraries/{library}/{template}
64
+ * 4. embedded/{generator}/{template}
65
+ * 5. embedded/_common/{template}
66
+ */
67
+ export declare function createTemplateLocatorChain(options: TemplateLocatorChainOptions): TemplatePathLocator[];
68
+ /**
69
+ * Resolve a template name using a chain of locators
70
+ */
71
+ export declare function resolveTemplatePath(templateName: string, locators: TemplatePathLocator[]): string | null;
72
+ //# sourceMappingURL=template-locator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-locator.d.ts","sourceRoot":"","sources":["../../src/template/template-locator.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;GAEG;AACH,qBAAa,oBAAqB,YAAW,mBAAmB;IAE9D,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,OAAO,CAAC;gBADR,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,YAAA;IAGzB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAYhD,OAAO,CAAC,oBAAoB;CAU5B;AAED;;GAEG;AACH,qBAAa,sBAAuB,YAAW,mBAAmB;IACrD,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IAErC,mBAAmB,CAAC,IAA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
2
+ * Template path resolution system
3
+ * Implements the same priority chain as the Java implementation
4
+ */
5
+ import * as fs from "node:fs";
6
+ import * as path from "node:path";
7
+ /**
8
+ * Locator that searches for templates in a custom directory with library support
9
+ */
10
+ export class CustomLibraryLocator {
11
+ customDir;
12
+ library;
13
+ constructor(customDir, library) {
14
+ this.customDir = customDir;
15
+ this.library = library;
16
+ }
17
+ getFullTemplatePath(name) {
18
+ if (!this.library)
19
+ return null;
20
+ const templatePath = path.join(this.customDir, "libraries", this.library, name);
21
+ return this.existsWithExtensions(templatePath);
22
+ }
23
+ existsWithExtensions(basePath) {
24
+ const extensions = ["", ".mustache", ".handlebars", ".hbs"];
25
+ for (const ext of extensions) {
26
+ const fullPath = basePath + ext;
27
+ if (fs.existsSync(fullPath)) {
28
+ return fullPath;
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Locator that searches for templates in a custom directory
36
+ */
37
+ export class CustomGeneratorLocator {
38
+ customDir;
39
+ constructor(customDir) {
40
+ this.customDir = customDir;
41
+ }
42
+ getFullTemplatePath(name) {
43
+ const templatePath = path.join(this.customDir, name);
44
+ return this.existsWithExtensions(templatePath);
45
+ }
46
+ existsWithExtensions(basePath) {
47
+ const extensions = ["", ".mustache", ".handlebars", ".hbs"];
48
+ for (const ext of extensions) {
49
+ const fullPath = basePath + ext;
50
+ if (fs.existsSync(fullPath)) {
51
+ return fullPath;
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Locator that searches for templates in embedded resources with library support
59
+ */
60
+ export class EmbeddedLibraryLocator {
61
+ embeddedDir;
62
+ generatorName;
63
+ library;
64
+ constructor(embeddedDir, generatorName, library) {
65
+ this.embeddedDir = embeddedDir;
66
+ this.generatorName = generatorName;
67
+ this.library = library;
68
+ }
69
+ getFullTemplatePath(name) {
70
+ if (!this.library)
71
+ return null;
72
+ const templatePath = path.join(this.embeddedDir, this.generatorName, "libraries", this.library, name);
73
+ return this.existsWithExtensions(templatePath);
74
+ }
75
+ existsWithExtensions(basePath) {
76
+ const extensions = ["", ".mustache", ".handlebars", ".hbs"];
77
+ for (const ext of extensions) {
78
+ const fullPath = basePath + ext;
79
+ if (fs.existsSync(fullPath)) {
80
+ return fullPath;
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+ }
86
+ /**
87
+ * Locator that searches for templates in embedded generator resources
88
+ */
89
+ export class EmbeddedGeneratorLocator {
90
+ embeddedDir;
91
+ generatorName;
92
+ constructor(embeddedDir, generatorName) {
93
+ this.embeddedDir = embeddedDir;
94
+ this.generatorName = generatorName;
95
+ }
96
+ getFullTemplatePath(name) {
97
+ const templatePath = path.join(this.embeddedDir, this.generatorName, name);
98
+ return this.existsWithExtensions(templatePath);
99
+ }
100
+ existsWithExtensions(basePath) {
101
+ const extensions = ["", ".mustache", ".handlebars", ".hbs"];
102
+ for (const ext of extensions) {
103
+ const fullPath = basePath + ext;
104
+ if (fs.existsSync(fullPath)) {
105
+ return fullPath;
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ }
111
+ /**
112
+ * Locator that searches for templates in common embedded resources
113
+ */
114
+ export class CommonEmbeddedLocator {
115
+ embeddedDir;
116
+ constructor(embeddedDir) {
117
+ this.embeddedDir = embeddedDir;
118
+ }
119
+ getFullTemplatePath(name) {
120
+ const templatePath = path.join(this.embeddedDir, "_common", name);
121
+ return this.existsWithExtensions(templatePath);
122
+ }
123
+ existsWithExtensions(basePath) {
124
+ const extensions = ["", ".mustache", ".handlebars", ".hbs"];
125
+ for (const ext of extensions) {
126
+ const fullPath = basePath + ext;
127
+ if (fs.existsSync(fullPath)) {
128
+ return fullPath;
129
+ }
130
+ }
131
+ return null;
132
+ }
133
+ }
134
+ /**
135
+ * Create a chain of template locators with the correct priority order
136
+ *
137
+ * Resolution priority:
138
+ * 1. custom/libraries/{library}/{template}
139
+ * 2. custom/{template}
140
+ * 3. embedded/{generator}/libraries/{library}/{template}
141
+ * 4. embedded/{generator}/{template}
142
+ * 5. embedded/_common/{template}
143
+ */
144
+ export function createTemplateLocatorChain(options) {
145
+ const locators = [];
146
+ // Custom templates (highest priority)
147
+ if (options.customDir) {
148
+ if (options.library) {
149
+ locators.push(new CustomLibraryLocator(options.customDir, options.library));
150
+ }
151
+ locators.push(new CustomGeneratorLocator(options.customDir));
152
+ }
153
+ // Embedded templates
154
+ if (options.library) {
155
+ locators.push(new EmbeddedLibraryLocator(options.embeddedDir, options.generatorName, options.library));
156
+ }
157
+ locators.push(new EmbeddedGeneratorLocator(options.embeddedDir, options.generatorName));
158
+ locators.push(new CommonEmbeddedLocator(options.embeddedDir));
159
+ return locators;
160
+ }
161
+ /**
162
+ * Resolve a template name using a chain of locators
163
+ */
164
+ export function resolveTemplatePath(templateName, locators) {
165
+ for (const locator of locators) {
166
+ const path = locator.getFullTemplatePath(templateName);
167
+ if (path) {
168
+ return path;
169
+ }
170
+ }
171
+ return null;
172
+ }
173
+ //# sourceMappingURL=template-locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-locator.js","sourceRoot":"","sources":["../../src/template/template-locator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAEvB;IACA;IAFT,YACS,SAAiB,EACjB,OAAgB;QADhB,cAAS,GAAT,SAAS,CAAQ;QACjB,YAAO,GAAP,OAAO,CAAS;IACtB,CAAC;IAEJ,mBAAmB,CAAC,IAAY;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE/B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAC7B,IAAI,CAAC,SAAS,EACd,WAAW,EACX,IAAI,CAAC,OAAO,EACZ,IAAI,CACJ,CAAC;QACF,OAAO,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAEO,oBAAoB,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AC,CAAC;IAC9D,CAAC;IAED,qBAAqB;IACrB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CACZ,IAAI,sBAAsB,CACzB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,OAAO,CACf,CACD,CAAC;IACH,CAAC;IACD,QAAQ,CAAC,IAAI,CACZ,IAAI,wBAAwB,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,CACxE,CAAC;IACF,QAAQ,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9D,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAClC,YAAoB,EACpB,QAA+B;IAE/B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { CompiledTemplate, GeneratedFile, TemplateData, TemplateManagerOptions, WriteOptions } from "../core/types.js";
2
+ import { type HandlebarsAdapter } from "./engine-adapter.js";
3
+ import { type TemplateLocatorChainOptions } from "./template-locator.js";
4
+ export interface TemplateManagerConfig {
5
+ options: TemplateManagerOptions;
6
+ locatorOptions: TemplateLocatorChainOptions;
7
+ }
8
+ export declare class TemplateManager {
9
+ private engine;
10
+ private locators;
11
+ private options;
12
+ private compiledTemplates;
13
+ private loadedPartials;
14
+ constructor(config: TemplateManagerConfig);
15
+ /**
16
+ * Get the path to a template file
17
+ */
18
+ getTemplatePath(templateName: string): string | null;
19
+ /**
20
+ * Load and compile a template
21
+ */
22
+ compile(templateName: string): Promise<CompiledTemplate>;
23
+ /**
24
+ * Render a template with data
25
+ */
26
+ render(templateName: string, data: TemplateData): Promise<string>;
27
+ /**
28
+ * Register partials referenced in a template
29
+ * Partials are referenced as {{> partialName}}
30
+ */
31
+ private registerPartialsFromTemplate;
32
+ /**
33
+ * Write generated content to a file
34
+ */
35
+ writeFile(filePath: string, content: string, options?: WriteOptions): Promise<GeneratedFile>;
36
+ /**
37
+ * Find all templates in a directory matching a pattern
38
+ */
39
+ findTemplates(_pattern: string): Promise<string[]>;
40
+ /**
41
+ * Find all template files in the embedded templates directory
42
+ */
43
+ findEmbeddedTemplates(embeddedDir: string, generatorName: string): Promise<string[]>;
44
+ /**
45
+ * Get the template engine
46
+ */
47
+ getEngine(): HandlebarsAdapter;
48
+ /**
49
+ * Register a custom helper
50
+ */
51
+ registerHelper(name: string, fn: (...args: unknown[]) => string): void;
52
+ /**
53
+ * Register a partial template
54
+ */
55
+ registerPartial(name: string, source: string): void;
56
+ /**
57
+ * Clear compiled template cache
58
+ */
59
+ clearCache(): void;
60
+ }
61
+ /**
62
+ * Create a TemplateManager with default options
63
+ */
64
+ export declare function createTemplateManager(config: TemplateManagerConfig): TemplateManager;
65
+ //# sourceMappingURL=template-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-manager.d.ts","sourceRoot":"","sources":["../../src/template/template-manager.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACX,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,sBAAsB,EAEtB,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,KAAK,iBAAiB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGN,KAAK,2BAA2B,EAChC,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,sBAAsB,CAAC;IAChC,cAAc,EAAE,2BAA2B,CAAC;CAC5C;AAED,qBAAa,eAAe;IAC3B,OAAO,CAAC,MAAM,CAAoB;IAClC,OA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fs from "node:fs";
6
+ import * as path from "node:path";
7
+ import fg from "fast-glob";
8
+ import fsExtra from "fs-extra";
9
+ import { createTemplateEngine, } from "./engine-adapter.js";
10
+ import { createTemplateLocatorChain, resolveTemplatePath, } from "./template-locator.js";
11
+ export class TemplateManager {
12
+ engine;
13
+ locators;
14
+ options;
15
+ compiledTemplates = new Map();
16
+ loadedPartials = new Set();
17
+ constructor(config) {
18
+ this.options = config.options;
19
+ this.engine = createTemplateEngine();
20
+ this.locators = createTemplateLocatorChain(config.locatorOptions);
21
+ }
22
+ /**
23
+ * Get the path to a template file
24
+ */
25
+ getTemplatePath(templateName) {
26
+ return resolveTemplatePath(templateName, this.locators);
27
+ }
28
+ /**
29
+ * Load and compile a template
30
+ */
31
+ async compile(templateName) {
32
+ // Check cache first
33
+ const cached = this.compiledTemplates.get(templateName);
34
+ if (cached) {
35
+ return cached;
36
+ }
37
+ // Resolve template path
38
+ const templatePath = this.getTemplatePath(templateName);
39
+ if (!templatePath) {
40
+ throw new Error(`Template not found: ${templateName}`);
41
+ }
42
+ console.log(`Compiling template: ${templateName} -> ${templatePath}`);
43
+ // Load and compile
44
+ const source = await fs.promises.readFile(templatePath, "utf-8");
45
+ // Register any partials referenced in the template
46
+ await this.registerPartialsFromTemplate(source, path.dirname(templatePath));
47
+ const compiled = this.engine.compile(source);
48
+ this.compiledTemplates.set(templateName, compiled);
49
+ return compiled;
50
+ }
51
+ /**
52
+ * Render a template with data
53
+ */
54
+ async render(templateName, data) {
55
+ const template = await this.compile(templateName);
56
+ return template(data);
57
+ }
58
+ /**
59
+ * Register partials referenced in a template
60
+ * Partials are referenced as {{> partialName}}
61
+ */
62
+ async registerPartialsFromTemplate(source, _templateDir) {
63
+ // Match partial references: {{> partialName}} or {{>partialName}}
64
+ const partialRegex = /\{\{>\s*([a-zA-Z0-9_\-./]+)\s*\}\}/g;
65
+ let match = partialRegex.exec(source);
66
+ while (match !== null) {
67
+ const partialName = match[1];
68
+ if (this.loadedPartials.has(partialName)) {
69
+ match = partialRegex.exec(source);
70
+ continue;
71
+ }
72
+ // Try to find the partial
73
+ const partialPath = this.getTemplatePath(partialName);
74
+ if (partialPath) {
75
+ const partialSource = await fs.promises.readFile(partialPath, "utf-8");
76
+ this.engine.registerPartial(partialName, partialSource);
77
+ this.loadedPartials.add(partialName);
78
+ // Recursively register partials from this partial
79
+ await this.registerPartialsFromTemplate(partialSource, path.dirname(partialPath));
80
+ }
81
+ match = partialRegex.exec(source);
82
+ }
83
+ }
84
+ /**
85
+ * Write generated content to a file
86
+ */
87
+ async writeFile(filePath, content, options) {
88
+ const opts = { ...this.options, ...options };
89
+ // Dry run - don't write
90
+ if (opts.dryRun) {
91
+ return {
92
+ path: filePath,
93
+ content,
94
+ skipped: false,
95
+ reason: "dry-run",
96
+ };
97
+ }
98
+ // Check if file exists
99
+ const exists = await fsExtra.pathExists(filePath);
100
+ // Skip overwrite if configured
101
+ if (exists && opts.skipOverwrite) {
102
+ return {
103
+ path: filePath,
104
+ content,
105
+ skipped: true,
106
+ reason: "skip-overwrite",
107
+ };
108
+ }
109
+ // Minimal update - only write if content changed
110
+ if (exists && opts.minimalUpdate) {
111
+ const existingContent = await fs.promises.readFile(filePath, "utf-8");
112
+ if (existingContent === content) {
113
+ return {
114
+ path: filePath,
115
+ content,
116
+ skipped: true,
117
+ reason: "unchanged",
118
+ };
119
+ }
120
+ }
121
+ // Ensure directory exists and write file
122
+ await fsExtra.ensureDir(path.dirname(filePath));
123
+ await fs.promises.writeFile(filePath, content, "utf-8");
124
+ return {
125
+ path: filePath,
126
+ content,
127
+ skipped: false,
128
+ };
129
+ }
130
+ /**
131
+ * Find all templates in a directory matching a pattern
132
+ */
133
+ async findTemplates(_pattern) {
134
+ // This is a simplified approach - in production you might want to
135
+ // expose the base path from locators for more efficient searching
136
+ return [];
137
+ }
138
+ /**
139
+ * Find all template files in the embedded templates directory
140
+ */
141
+ async findEmbeddedTemplates(embeddedDir, generatorName) {
142
+ const searchPath = path.join(embeddedDir, generatorName);
143
+ if (!fs.existsSync(searchPath)) {
144
+ return [];
145
+ }
146
+ const templates = await fg("**/*.{mustache,handlebars,hbs}", {
147
+ cwd: searchPath,
148
+ absolute: false,
149
+ });
150
+ return templates;
151
+ }
152
+ /**
153
+ * Get the template engine
154
+ */
155
+ getEngine() {
156
+ return this.engine;
157
+ }
158
+ /**
159
+ * Register a custom helper
160
+ */
161
+ registerHelper(name, fn) {
162
+ this.engine.registerHelper(name, fn);
163
+ }
164
+ /**
165
+ * Register a partial template
166
+ */
167
+ registerPartial(name, source) {
168
+ this.engine.registerPartial(name, source);
169
+ this.loadedPartials.add(name);
170
+ }
171
+ /**
172
+ * Clear compiled template cache
173
+ */
174
+ clearCache() {
175
+ this.compiledTemplates.clear();
176
+ this.loadedPartials.clear();
177
+ }
178
+ }
179
+ /**
180
+ * Create a TemplateManager with default options
181
+ */
182
+ export function createTemplateManager(config) {
183
+ return new TemplateManager(config);
184
+ }
185
+ //# sourceMappingURL=template-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-manager.js","sourceRoot":"","sources":["../../src/template/template-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,OAAO,MAAM,UAAU,CAAC;AAS/B,OAAO,EACN,oBAAoB,GAEpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,0BAA0B,EAC1B,mBAAmB,GAEnB,MAAM,uBAAuB,CAAC;AAO/B,MAAM,OAAO,eAAe;IACnB,MAAM,CAAoB;IAC1B,QAAQ,CAAwB;IAChC,OAAO,CAAyB;IAChC,iBAAiB,GAAkC,IAAI,GAAG,EAAE,CAAC;IAC7D,cAAc,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEhD,YAAY,MAA6B;QACxC,IAAI,CAAC,OAAO,GAAG,MAAM,C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IACX,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB,CAC1B,WAAmB,EACnB,aAAqB;QAErB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,OAAO,EAAE,CAAC;QACX,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,gCAAgC,EAAE;YAC5D,GAAG,EAAE,UAAU;YACf,QAAQ,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,IAAY,EAAE,EAAkC;QAC9D,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,IAAY,EAAE,MAAc;QAC3C,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU;QACT,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACpC,MAA6B;IAE7B,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@kattebak/openapi-generator-ts",
3
+ "version": "1.0.0",
4
+ "description": "OpenAPI Generator - Generate code from OpenAPI specifications",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "ts-openapi-generator": "./dist/cli/index.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "watch": "tsc --watch",
20
+ "test": "npm run lint && npm run typecheck && npm run test:unit && npm run test:build-samples",
21
+ "test:unit": "node --import tsx --test 'src/**/*.test.ts'",
22
+ "test:unit:verbose": "node --import tsx --test --test-reporter=spec 'src/**/*.test.ts'",
23
+ "test:build-samples": "make -C samples clean all",
24
+ "lint": "npx @biomejs/biome check",
25
+ "fix": "npx @biomejs/biome check --write",
26
+ "typecheck": "tsc --noEmit",
27
+ "sync-templates": "./scripts/sync-templates.sh",
28
+ "sync-templates:clean": "./scripts/sync-templates.sh --clean"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "templates"
36
+ ],
37
+ "keywords": [
38
+ "openapi",
39
+ "swagger",
40
+ "codegen",
41
+ "generator",
42
+ "api",
43
+ "typescript"
44
+ ],
45
+ "author": "",
46
+ "license": "Apache-2.0",
47
+ "engines": {
48
+ "node": ">=22.0.0"
49
+ },
50
+ "dependencies": {
51
+ "@apidevtools/swagger-parser": "^10.1.0",
52
+ "es-toolkit": "^1.31.0",
53
+ "fast-glob": "^3.3.2",
54
+ "fs-extra": "^11.2.0",
55
+ "handlebars": "^4.7.8",
56
+ "js-yaml": "^4.1.0"
57
+ },
58
+ "devDependencies": {
59
+ "@biomejs/biome": "^2.3.7",
60
+ "@types/fs-extra": "^11.0.4",
61
+ "@types/js-yaml": "^4.0.9",
62
+ "@types/node": "^22.0.0",
63
+ "prettier": "^3.7.4",
64
+ "tsx": "^4.19.0",
65
+ "typescript": "^5.7.0"
66
+ }
67
+ }
@@ -0,0 +1,8 @@
1
+ language: go
2
+
3
+ install:
4
+ - go get -d -v .
5
+
6
+ script:
7
+ - go build -v ./
8
+