swagger-sdk-generator 0.0.0-stage → 3.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 (217) hide show
  1. package/README.md +58 -2
  2. package/dist/cli/commands/generate.d.ts +2 -0
  3. package/dist/cli/commands/generate.js +196 -0
  4. package/dist/cli/commands/init.d.ts +2 -0
  5. package/dist/cli/commands/init.js +130 -0
  6. package/dist/cli/commands/inspect.d.ts +2 -0
  7. package/dist/cli/commands/inspect.js +164 -0
  8. package/dist/cli/commands/templates.d.ts +2 -0
  9. package/dist/cli/commands/templates.js +126 -0
  10. package/dist/cli/context.d.ts +16 -0
  11. package/dist/cli/context.js +85 -0
  12. package/dist/cli/main.d.ts +2 -0
  13. package/dist/cli/main.js +25 -0
  14. package/dist/config/dotenv.d.ts +2 -0
  15. package/dist/config/dotenv.js +82 -0
  16. package/dist/config/interpolate.d.ts +8 -0
  17. package/dist/config/interpolate.js +85 -0
  18. package/dist/config/load.d.ts +11 -0
  19. package/dist/config/load.js +182 -0
  20. package/dist/config/migrate-v3.d.ts +5 -0
  21. package/dist/config/migrate-v3.js +6 -0
  22. package/dist/config/mode-compatibility.d.ts +9 -0
  23. package/dist/config/mode-compatibility.js +17 -0
  24. package/dist/config/modes.d.ts +13 -0
  25. package/dist/config/modes.js +27 -0
  26. package/dist/config/preset-definitions.d.ts +2 -0
  27. package/dist/config/preset-definitions.js +4 -0
  28. package/dist/config/presets.d.ts +25 -0
  29. package/dist/config/presets.js +36 -0
  30. package/dist/config/resolve.d.ts +32 -0
  31. package/dist/config/resolve.js +288 -0
  32. package/dist/config/schema.d.ts +93 -0
  33. package/dist/config/schema.js +173 -0
  34. package/dist/config/types.d.ts +42 -0
  35. package/dist/config/types.js +2 -0
  36. package/dist/config/workspace.d.ts +30 -0
  37. package/dist/config/workspace.js +95 -0
  38. package/dist/core/case-align.d.ts +5 -0
  39. package/dist/core/case-align.js +90 -0
  40. package/dist/core/deep-merge.d.ts +2 -0
  41. package/dist/core/deep-merge.js +21 -0
  42. package/dist/core/file-set.d.ts +10 -0
  43. package/dist/core/file-set.js +31 -0
  44. package/dist/core/import-module.d.ts +1 -0
  45. package/dist/core/import-module.js +61 -0
  46. package/dist/core/log.d.ts +9 -0
  47. package/dist/core/log.js +24 -0
  48. package/dist/core/manifest.d.ts +17 -0
  49. package/dist/core/manifest.js +195 -0
  50. package/dist/core/overlaps.d.ts +6 -0
  51. package/dist/core/overlaps.js +67 -0
  52. package/dist/core/package-version.d.ts +1 -0
  53. package/dist/core/package-version.js +44 -0
  54. package/dist/core/pipeline.d.ts +30 -0
  55. package/dist/core/pipeline.js +335 -0
  56. package/dist/core/plugin.d.ts +72 -0
  57. package/dist/core/plugin.js +2 -0
  58. package/dist/core/targets.d.ts +14 -0
  59. package/dist/core/targets.js +120 -0
  60. package/dist/core/unmanaged.d.ts +3 -0
  61. package/dist/core/unmanaged.js +101 -0
  62. package/dist/core/writer.d.ts +28 -0
  63. package/dist/core/writer.js +148 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +37 -0
  66. package/dist/ir/casing.d.ts +5 -0
  67. package/dist/ir/casing.js +22 -0
  68. package/dist/ir/graph.d.ts +8 -0
  69. package/dist/ir/graph.js +95 -0
  70. package/dist/ir/operations/grouping.d.ts +17 -0
  71. package/dist/ir/operations/grouping.js +39 -0
  72. package/dist/ir/operations/legacy-naming.d.ts +2 -0
  73. package/dist/ir/operations/legacy-naming.js +8 -0
  74. package/dist/ir/operations/naming.d.ts +6 -0
  75. package/dist/ir/operations/naming.js +54 -0
  76. package/dist/ir/option-errors.d.ts +3 -0
  77. package/dist/ir/option-errors.js +68 -0
  78. package/dist/ir/transforms/builtins.d.ts +2 -0
  79. package/dist/ir/transforms/builtins.js +4 -0
  80. package/dist/ir/transforms/index.d.ts +10 -0
  81. package/dist/ir/transforms/index.js +39 -0
  82. package/dist/ir/transforms/types.d.ts +9 -0
  83. package/dist/ir/transforms/types.js +2 -0
  84. package/dist/ir/types.d.ts +140 -0
  85. package/dist/ir/types.js +2 -0
  86. package/dist/runtime/axios.d.ts +28 -0
  87. package/dist/runtime/axios.js +132 -0
  88. package/dist/runtime/fetch.d.ts +6 -0
  89. package/dist/runtime/fetch.js +38 -0
  90. package/dist/runtime/index.d.ts +54 -0
  91. package/dist/runtime/index.js +167 -0
  92. package/dist/runtime/rtk.d.ts +35 -0
  93. package/dist/runtime/rtk.js +36 -0
  94. package/dist/runtime/transport.d.ts +38 -0
  95. package/dist/runtime/transport.js +30 -0
  96. package/dist/runtime/wire.d.ts +27 -0
  97. package/dist/runtime/wire.js +148 -0
  98. package/dist/spec/html-entities.d.ts +1 -0
  99. package/dist/spec/html-entities.js +25 -0
  100. package/dist/spec/load.d.ts +26 -0
  101. package/dist/spec/load.js +130 -0
  102. package/dist/spec/openapi/all-of.d.ts +3 -0
  103. package/dist/spec/openapi/all-of.js +9 -0
  104. package/dist/spec/openapi/normalize.d.ts +4 -0
  105. package/dist/spec/openapi/normalize.js +31 -0
  106. package/dist/spec/openapi/operations.d.ts +4 -0
  107. package/dist/spec/openapi/operations.js +173 -0
  108. package/dist/spec/openapi/schema.d.ts +51 -0
  109. package/dist/spec/openapi/schema.js +307 -0
  110. package/dist/targets/declarative/config.d.ts +533 -0
  111. package/dist/targets/declarative/config.js +280 -0
  112. package/dist/targets/declarative/extensions.d.ts +45 -0
  113. package/dist/targets/declarative/extensions.js +123 -0
  114. package/dist/targets/declarative/files.d.ts +13 -0
  115. package/dist/targets/declarative/files.js +127 -0
  116. package/dist/targets/declarative/format.d.ts +4 -0
  117. package/dist/targets/declarative/format.js +104 -0
  118. package/dist/targets/declarative/index.d.ts +9 -0
  119. package/dist/targets/declarative/index.js +170 -0
  120. package/dist/targets/declarative/liquid.d.ts +8 -0
  121. package/dist/targets/declarative/liquid.js +57 -0
  122. package/dist/targets/declarative/naming-case.d.ts +3 -0
  123. package/dist/targets/declarative/naming-case.js +31 -0
  124. package/dist/targets/declarative/naming.d.ts +42 -0
  125. package/dist/targets/declarative/naming.js +174 -0
  126. package/dist/targets/declarative/scaffold.d.ts +5 -0
  127. package/dist/targets/declarative/scaffold.js +146 -0
  128. package/dist/targets/declarative/types.d.ts +52 -0
  129. package/dist/targets/declarative/types.js +287 -0
  130. package/dist/targets/declarative/views.d.ts +180 -0
  131. package/dist/targets/declarative/views.js +447 -0
  132. package/dist/targets/python/extensions.js +152 -0
  133. package/dist/targets/python/target.json +549 -0
  134. package/dist/targets/python/templates/client/client.liquid +114 -0
  135. package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
  136. package/dist/targets/python/templates/client/init.liquid +20 -0
  137. package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
  138. package/dist/targets/python/templates/client/resource.liquid +28 -0
  139. package/dist/targets/python/templates/client/runtime.liquid +133 -0
  140. package/dist/targets/python/templates/client/transport.liquid +62 -0
  141. package/dist/targets/python/templates/models/module.liquid +48 -0
  142. package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
  143. package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
  144. package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
  145. package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
  146. package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
  147. package/dist/targets/typescript/compatibility-naming.js +28 -0
  148. package/dist/targets/typescript/compatibility-options.d.ts +5 -0
  149. package/dist/targets/typescript/compatibility-options.js +8 -0
  150. package/dist/targets/typescript/compatibility-target.d.ts +5 -0
  151. package/dist/targets/typescript/compatibility-target.js +10 -0
  152. package/dist/targets/typescript/http-operations.d.ts +34 -0
  153. package/dist/targets/typescript/http-operations.js +155 -0
  154. package/dist/targets/typescript/imports.d.ts +43 -0
  155. package/dist/targets/typescript/imports.js +154 -0
  156. package/dist/targets/typescript/index.d.ts +7 -0
  157. package/dist/targets/typescript/index.js +52 -0
  158. package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
  159. package/dist/targets/typescript/mock-compatibility.js +6 -0
  160. package/dist/targets/typescript/mock-hints.d.ts +13 -0
  161. package/dist/targets/typescript/mock-hints.js +75 -0
  162. package/dist/targets/typescript/mock-reachability.d.ts +12 -0
  163. package/dist/targets/typescript/mock-reachability.js +87 -0
  164. package/dist/targets/typescript/model-compatibility.d.ts +14 -0
  165. package/dist/targets/typescript/model-compatibility.js +16 -0
  166. package/dist/targets/typescript/naming.d.ts +13 -0
  167. package/dist/targets/typescript/naming.js +50 -0
  168. package/dist/targets/typescript/options.d.ts +124 -0
  169. package/dist/targets/typescript/options.js +90 -0
  170. package/dist/targets/typescript/outputs/client.d.ts +67 -0
  171. package/dist/targets/typescript/outputs/client.js +187 -0
  172. package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
  173. package/dist/targets/typescript/outputs/mocks.js +371 -0
  174. package/dist/targets/typescript/outputs/models.d.ts +85 -0
  175. package/dist/targets/typescript/outputs/models.js +246 -0
  176. package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
  177. package/dist/targets/typescript/outputs/rtk-query.js +266 -0
  178. package/dist/targets/typescript/prettier.d.ts +7 -0
  179. package/dist/targets/typescript/prettier.js +44 -0
  180. package/dist/targets/typescript/templates/client/client.liquid +30 -0
  181. package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
  182. package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
  183. package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
  184. package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
  185. package/dist/targets/typescript/templates/client/resource.liquid +34 -0
  186. package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
  187. package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
  188. package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
  189. package/dist/targets/typescript/templates/models/alias.liquid +16 -0
  190. package/dist/targets/typescript/templates/models/enum.liquid +27 -0
  191. package/dist/targets/typescript/templates/models/index.liquid +14 -0
  192. package/dist/targets/typescript/templates/models/model.liquid +25 -0
  193. package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
  194. package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
  195. package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
  196. package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
  197. package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
  198. package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
  199. package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
  200. package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
  201. package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
  202. package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
  203. package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
  204. package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
  205. package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
  206. package/dist/targets/typescript/ts-type.d.ts +70 -0
  207. package/dist/targets/typescript/ts-type.js +62 -0
  208. package/dist/targets/typescript/type-printer.d.ts +21 -0
  209. package/dist/targets/typescript/type-printer.js +115 -0
  210. package/dist/templates/engine.d.ts +20 -0
  211. package/dist/templates/engine.js +161 -0
  212. package/dist/templates/inspect.d.ts +27 -0
  213. package/dist/templates/inspect.js +331 -0
  214. package/package.json +65 -4
  215. package/schema/sdk-gen.local.schema.json +75 -0
  216. package/schema/sdk-gen.schema.json +980 -0
  217. package/schema/sdk-gen.target.schema.json +1384 -0
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isIdentifier = isIdentifier;
4
+ exports.upperFirst = upperFirst;
5
+ exports.propertyKey = propertyKey;
6
+ exports.propertyEnumName = propertyEnumName;
7
+ exports.literal = literal;
8
+ exports.docLines = docLines;
9
+ exports.constMembers = constMembers;
10
+ exports.constEnumValues = constEnumValues;
11
+ const imports_1 = require("./imports");
12
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
13
+ function isIdentifier(name) {
14
+ return IDENTIFIER.test(name);
15
+ }
16
+ function upperFirst(s) {
17
+ return s.charAt(0).toUpperCase() + s.slice(1);
18
+ }
19
+ function propertyKey(name) {
20
+ return isIdentifier(name) ? name : JSON.stringify(name);
21
+ }
22
+ function propertyEnumName(typeName, propertyName) {
23
+ return (0, imports_1.toIdentifier)(`${typeName}${upperFirst(propertyName)}`);
24
+ }
25
+ function literal(value) {
26
+ return typeof value === 'string' ? JSON.stringify(value) : String(value);
27
+ }
28
+ function docLines(description) {
29
+ if (!description)
30
+ return null;
31
+ return description.replace(/\*\//g, '*\\/').split('\n').map((line) => line.trimEnd());
32
+ }
33
+ function constMembers(values) {
34
+ return constEnumValues(values).map((raw) => ({ key: enumKeyFor(raw), value: literal(raw) }));
35
+ }
36
+ function constEnumValues(values) {
37
+ const seen = new Set();
38
+ return values.filter((raw) => {
39
+ const key = enumKeyFor(raw);
40
+ if (seen.has(key))
41
+ return false;
42
+ seen.add(key);
43
+ return true;
44
+ });
45
+ }
46
+ function enumKeyFor(raw) {
47
+ if (typeof raw === 'number')
48
+ return raw >= 0 && Number.isInteger(raw) ? String(raw) : JSON.stringify(String(raw));
49
+ return propertyKey(String(raw));
50
+ }
@@ -0,0 +1,124 @@
1
+ import { engineSchema } from './compatibility-options';
2
+ import { z } from 'zod';
3
+ export declare const outputBaseSchema: z.ZodObject<{
4
+ dir: z.ZodString;
5
+ format: z.ZodOptional<z.ZodBoolean>;
6
+ }, z.core.$strict>;
7
+ export declare const operationNamingSchema: z.ZodEnum<{
8
+ "operation-id": "operation-id";
9
+ path: "path";
10
+ "path-last-param": "path-last-param";
11
+ }>;
12
+ export declare const operationGroupingSchema: z.ZodObject<{
13
+ stripPrefixes: z.ZodArray<z.ZodString>;
14
+ folders: z.ZodBoolean;
15
+ }, z.core.$strict>;
16
+ export type Engine = z.infer<typeof engineSchema>;
17
+ export declare const modelsOptionsSchema: z.ZodObject<{
18
+ dir: z.ZodString;
19
+ format: z.ZodOptional<z.ZodBoolean>;
20
+ engine: z.ZodLiteral<"ir">;
21
+ layout: z.ZodEnum<{
22
+ flat: "flat";
23
+ namespace: "namespace";
24
+ }>;
25
+ importPath: z.ZodOptional<z.ZodString>;
26
+ index: z.ZodBoolean;
27
+ inlineEnums: z.ZodEnum<{
28
+ const: "const";
29
+ union: "union";
30
+ }>;
31
+ strictEnums: z.ZodBoolean;
32
+ enumSchemas: z.ZodEnum<{
33
+ const: "const";
34
+ enum: "enum";
35
+ union: "union";
36
+ }>;
37
+ objectTypeConst: z.ZodLiteral<false>;
38
+ arrayStyle: z.ZodEnum<{
39
+ brackets: "brackets";
40
+ generic: "generic";
41
+ }>;
42
+ untyped: z.ZodEnum<{
43
+ any: "any";
44
+ object: "object";
45
+ unknown: "unknown";
46
+ }>;
47
+ nestedArrays: z.ZodEnum<{
48
+ any: "any";
49
+ preserve: "preserve";
50
+ }>;
51
+ nullable: z.ZodEnum<{
52
+ ignore: "ignore";
53
+ property: "property";
54
+ union: "union";
55
+ }>;
56
+ inlineObjects: z.ZodEnum<{
57
+ literal: "literal";
58
+ object: "object";
59
+ }>;
60
+ typeImports: z.ZodBoolean;
61
+ legacyQuirks: z.ZodOptional<z.ZodLiteral<false>>;
62
+ header: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strict>;
64
+ export type ModelsOptions = z.infer<typeof modelsOptionsSchema>;
65
+ export type OperationNaming = z.infer<typeof operationNamingSchema>;
66
+ export type OperationGrouping = z.infer<typeof operationGroupingSchema>;
67
+ export declare const transportChoiceSchema: z.ZodEnum<{
68
+ fetch: "fetch";
69
+ none: "none";
70
+ }>;
71
+ export declare const rtkQueryRuntimeImportsSchema: z.ZodObject<{
72
+ baseApi: z.ZodString;
73
+ }, z.core.$strict>;
74
+ export declare const rtkQueryOptionsSchema: z.ZodObject<{
75
+ dir: z.ZodString;
76
+ format: z.ZodOptional<z.ZodBoolean>;
77
+ stripPrefixes: z.ZodArray<z.ZodString>;
78
+ folders: z.ZodBoolean;
79
+ reducerPath: z.ZodOptional<z.ZodString>;
80
+ naming: z.ZodEnum<{
81
+ "operation-id": "operation-id";
82
+ path: "path";
83
+ "path-last-param": "path-last-param";
84
+ }>;
85
+ basePath: z.ZodString;
86
+ runtime: z.ZodUnion<readonly [z.ZodLiteral<"transport">, z.ZodLiteral<"toolkit">, z.ZodObject<{
87
+ imports: z.ZodObject<{
88
+ baseApi: z.ZodString;
89
+ }, z.core.$strict>;
90
+ }, z.core.$strict>]>;
91
+ transport: z.ZodEnum<{
92
+ fetch: "fetch";
93
+ none: "none";
94
+ }>;
95
+ }, z.core.$strict>;
96
+ export type RtkQueryOptions = z.infer<typeof rtkQueryOptionsSchema>;
97
+ export declare const clientOptionsSchema: z.ZodObject<{
98
+ dir: z.ZodString;
99
+ format: z.ZodOptional<z.ZodBoolean>;
100
+ stripPrefixes: z.ZodArray<z.ZodString>;
101
+ folders: z.ZodBoolean;
102
+ naming: z.ZodEnum<{
103
+ "operation-id": "operation-id";
104
+ path: "path";
105
+ "path-last-param": "path-last-param";
106
+ }>;
107
+ basePath: z.ZodString;
108
+ transport: z.ZodEnum<{
109
+ fetch: "fetch";
110
+ none: "none";
111
+ }>;
112
+ }, z.core.$strict>;
113
+ export type ClientOptions = z.infer<typeof clientOptionsSchema>;
114
+ export declare const mocksOptionsSchema: z.ZodObject<{
115
+ dir: z.ZodString;
116
+ format: z.ZodOptional<z.ZodBoolean>;
117
+ engine: z.ZodLiteral<"ir">;
118
+ subdir: z.ZodString;
119
+ style: z.ZodLiteral<"seeded">;
120
+ arrayLength: z.ZodNumber;
121
+ maxDepth: z.ZodNumber;
122
+ reachableFrom: z.ZodOptional<z.ZodArray<z.ZodString>>;
123
+ }, z.core.$strict>;
124
+ export type MocksOptions = z.infer<typeof mocksOptionsSchema>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mocksOptionsSchema = exports.clientOptionsSchema = exports.rtkQueryOptionsSchema = exports.rtkQueryRuntimeImportsSchema = exports.transportChoiceSchema = exports.modelsOptionsSchema = exports.operationGroupingSchema = exports.operationNamingSchema = exports.outputBaseSchema = void 0;
4
+ const naming_1 = require("../../ir/operations/naming");
5
+ const compatibility_options_1 = require("./compatibility-options");
6
+ const zod_1 = require("zod");
7
+ exports.outputBaseSchema = zod_1.z
8
+ .object({
9
+ dir: zod_1.z.string().describe('Output directory (resolved against cwd by the core).'),
10
+ format: zod_1.z.boolean().optional().describe("Run the target formatter over this output's files (default true)."),
11
+ })
12
+ .strict();
13
+ exports.operationNamingSchema = zod_1.z.enum(naming_1.OPERATION_NAMING);
14
+ exports.operationGroupingSchema = zod_1.z
15
+ .object({
16
+ stripPrefixes: zod_1.z.array(zod_1.z.string()).describe('Leading path prefixes ignored when deriving resource names (legacy: `/app/api`).'),
17
+ folders: zod_1.z.boolean().describe('First segment becomes a folder, second names the resource (legacy `useFolders`).'),
18
+ })
19
+ .strict();
20
+ exports.modelsOptionsSchema = exports.outputBaseSchema
21
+ .extend({
22
+ engine: compatibility_options_1.engineSchema,
23
+ layout: zod_1.z
24
+ .enum(['namespace', 'flat'])
25
+ .describe('`namespace`: `App.Domain.User` -> `App/Domain/User.ts` exporting `User`. `flat`: `App_Domain_User.ts`.'),
26
+ importPath: zod_1.z
27
+ .string()
28
+ .optional()
29
+ .describe('Non-relative module prefix for model imports (`@models/swagger`). Unset -> relative imports.'),
30
+ index: zod_1.z.boolean().describe('Emit a barrel `index.ts`.'),
31
+ inlineEnums: zod_1.z
32
+ .enum(['const', 'union'])
33
+ .describe('Property-level enums: hoisted `export const <Model><Prop> = {...}` objects, or inline literal unions. `const` is the legacy dialect: enums that cannot be hoisted (array items, union members) are spelled by their base type (`string`, or the schema `title`), exactly as legacy did.'),
34
+ strictEnums: zod_1.z.boolean().describe('With `inlineEnums: \'const\'`: also emit `<Name>Strict = {...} as const`.'),
35
+ enumSchemas: zod_1.z.enum(['enum', 'union', 'const']).describe('Top-level enum components: `export enum`, literal-union alias, or const object.'),
36
+ objectTypeConst: compatibility_options_1.objectTypeSchema,
37
+ arrayStyle: zod_1.z.enum(['brackets', 'generic']).describe('TypeScript array spelling.'),
38
+ untyped: zod_1.z.enum(['unknown', 'any', 'object']).describe('Spelling of a type with no information.'),
39
+ nestedArrays: zod_1.z.enum(['preserve', 'any']).describe('`any`: nested arrays collapse to `any[]` (legacy).'),
40
+ nullable: zod_1.z
41
+ .enum(['ignore', 'union', 'property'])
42
+ .describe("`ignore`: drop `nullable`. `union`: append `| null` to every nullable type. `property` (legacy): append `| null` to an object property's own type only (not array items, union members, aliases or parameters)."),
43
+ inlineObjects: zod_1.z
44
+ .enum(['literal', 'object'])
45
+ .describe('Inline (non-component) object schemas. `literal`: printed as type literals, free-form ones as `Record<string, unknown>`. `object` (legacy): spelled `object` - the legacy generator never printed inline object shapes; a model-level free-form object is `{}`.'),
46
+ typeImports: zod_1.z.boolean().describe('Import model types with `import type` (legacy: plain `import { ... }`).'),
47
+ legacyQuirks: compatibility_options_1.legacyQuirksSchema,
48
+ header: zod_1.z
49
+ .string()
50
+ .optional()
51
+ .describe('Optional banner at the top of every model file: verbatim when it is already a comment, else `// `-prefixed per line.'),
52
+ })
53
+ .strict();
54
+ exports.transportChoiceSchema = zod_1.z
55
+ .enum(['fetch', 'none'])
56
+ .describe('`fetch`: default to the package Fetch adapter. `none`: require an injected Transport (for example, your Axios instance).');
57
+ exports.rtkQueryRuntimeImportsSchema = zod_1.z
58
+ .object({
59
+ baseApi: zod_1.z.string().describe('Module specifier for the RTK Query base api runtime import.'),
60
+ })
61
+ .strict();
62
+ exports.rtkQueryOptionsSchema = exports.outputBaseSchema
63
+ .extend(Object.assign(Object.assign({ reducerPath: zod_1.z.string().min(1).optional().describe('Redux reducer key of the generated API. Defaults to the source name.') }, exports.operationGroupingSchema.shape), { naming: exports.operationNamingSchema.describe('Operation naming strategy.'), basePath: zod_1.z.string().describe('Prefixed to every endpoint URL.'), runtime: zod_1.z
64
+ .union([
65
+ zod_1.z.literal('transport'),
66
+ zod_1.z.literal('toolkit'),
67
+ zod_1.z.object({ imports: exports.rtkQueryRuntimeImportsSchema.describe('Runtime import module specifiers.') }).strict(),
68
+ ])
69
+ .describe('`toolkit`: thin Redux Toolkit wrapper. `transport`: use the configurable package runtime. `{ imports: { baseApi } }`: use your own Redux Toolkit base API (relative to the output root).'), transport: exports.transportChoiceSchema }))
70
+ .strict();
71
+ exports.clientOptionsSchema = exports.outputBaseSchema
72
+ .extend(Object.assign(Object.assign({}, exports.operationGroupingSchema.shape), { naming: exports.operationNamingSchema.describe('Operation (method) naming strategy.'), basePath: zod_1.z.string().describe('Prefixed to every request path.'), transport: exports.transportChoiceSchema }))
73
+ .strict();
74
+ exports.mocksOptionsSchema = exports.outputBaseSchema
75
+ .extend({
76
+ engine: compatibility_options_1.engineSchema,
77
+ subdir: zod_1.z.string().describe('Mock files live under `<dir>/<subdir>/` (legacy `__model_mocks__`).'),
78
+ style: compatibility_options_1.mockStyleSchema,
79
+ arrayLength: zod_1.z.number().int().describe('Items generated per array.'),
80
+ maxDepth: zod_1.z
81
+ .number()
82
+ .int()
83
+ .min(0)
84
+ .describe('Ref levels composed below a get/create call. Deeper, a ref is `undefined` when optional, `null` when nullable, `[]` for a list of refs, else `undefined as any`. Bounds the mock as a TREE: shared refs would otherwise expand exponentially (and so would toEqual / JSON.stringify / RTK serializable checks walking it).'),
85
+ reachableFrom: zod_1.z
86
+ .array(zod_1.z.string())
87
+ .optional()
88
+ .describe('Only generate mocks your code imports (plus the mocks they compose): source dirs scanned for `<subdir>/…mock` imports, relative to the config. Unset = every model.'),
89
+ })
90
+ .strict();
@@ -0,0 +1,67 @@
1
+ import type { OutputPlugin } from '../../../core/plugin';
2
+ import { type ResourceGroup } from '../../../ir/operations/grouping';
3
+ import type { Operation } from '../../../ir/types';
4
+ import { type HeaderParamView, type HttpVerb, type ResponseKind } from '../http-operations';
5
+ import { ImportCollector } from '../imports';
6
+ import { type ClientOptions } from '../options';
7
+ import { type PrintContext } from '../type-printer';
8
+ import { type ImportView } from './models';
9
+ export interface ClientParamView {
10
+ name: string;
11
+ type: string;
12
+ optional: boolean;
13
+ }
14
+ export interface ClientQueryFieldView {
15
+ key: string;
16
+ type: string;
17
+ optional: boolean;
18
+ doc: string[];
19
+ }
20
+ export interface ClientMethodView {
21
+ name: string;
22
+ operation: string;
23
+ doc: string[];
24
+ params: ClientParamView[];
25
+ queryType: string | null;
26
+ queryFields: ClientQueryFieldView[];
27
+ successType: string;
28
+ method: HttpVerb;
29
+ path: string;
30
+ hasBody: boolean;
31
+ contentType: string | null;
32
+ responseType: ResponseKind;
33
+ headerParams: HeaderParamView[];
34
+ }
35
+ export interface ClientResourceView {
36
+ banner: string;
37
+ factoryName: string;
38
+ typeName: string;
39
+ imports: ImportView[];
40
+ methods: ClientMethodView[];
41
+ }
42
+ export interface ClientApiMemberView {
43
+ key: string;
44
+ factoryName: string | null;
45
+ children: ClientApiMemberView[];
46
+ }
47
+ export interface ClientApiView {
48
+ banner: string;
49
+ defaultBaseUrl: string;
50
+ fetchTransport: boolean;
51
+ resources: Array<{
52
+ factoryName: string;
53
+ specifier: string;
54
+ }>;
55
+ members: ClientApiMemberView[];
56
+ }
57
+ export declare const clientOutput: OutputPlugin<ClientOptions>;
58
+ export interface ClientBuildContext {
59
+ factoryName: string;
60
+ typeName: string;
61
+ imports: ImportCollector;
62
+ printOptions: PrintContext['options'];
63
+ options: ClientOptions;
64
+ warn?: (message: string) => void;
65
+ }
66
+ export declare function buildClientResourceView(group: ResourceGroup, build: ClientBuildContext): ClientResourceView;
67
+ export declare function buildClientMethodView(declared: Operation, name: string, options: ClientOptions, print: PrintContext): ClientMethodView;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.clientOutput = void 0;
37
+ exports.buildClientResourceView = buildClientResourceView;
38
+ exports.buildClientMethodView = buildClientMethodView;
39
+ const path = __importStar(require("path"));
40
+ const casing_1 = require("../../../ir/casing");
41
+ const grouping_1 = require("../../../ir/operations/grouping");
42
+ const naming_1 = require("../../../ir/operations/naming");
43
+ const http_operations_1 = require("../http-operations");
44
+ const imports_1 = require("../imports");
45
+ const naming_2 = require("../naming");
46
+ const options_1 = require("../options");
47
+ const type_printer_1 = require("../type-printer");
48
+ const models_1 = require("./models");
49
+ const BANNER = '/*\n * WARNING THIS FILE IS AUTO-GENERATED DO NOT MODIFY YOUR CHANGES WILL BE OVERWRITTEN!\n */';
50
+ const CLIENT_FILE = 'client';
51
+ const RESERVED_ROOT_STEMS = [CLIENT_FILE, 'transport', 'index'];
52
+ const LOCAL_PARAM_RESERVED = ['query', 'body', 'options', 'send'];
53
+ exports.clientOutput = {
54
+ name: 'client',
55
+ description: 'Promise API client per resource over package runtime (configurable Fetch, injected Axios or custom transport)',
56
+ optionsSchema: options_1.clientOptionsSchema,
57
+ defaults: {
58
+ dir: './client',
59
+ naming: 'path',
60
+ folders: false,
61
+ stripPrefixes: ['/app/api'],
62
+ basePath: '',
63
+ transport: 'fetch',
64
+ },
65
+ generate(ctx) {
66
+ var _a;
67
+ const { options } = ctx;
68
+ const locator = (0, imports_1.locatorFromPeers)(ctx.api, (0, http_operations_1.modelPeersWithFallback)(ctx));
69
+ const printOptions = Object.assign(Object.assign({}, (0, models_1.printOptionsFor)(ctx.peers.models)), { typeImports: true });
70
+ const warn = (message) => ctx.log.warn(message);
71
+ const stems = new Set(RESERVED_ROOT_STEMS.map((stem) => `/${stem}`));
72
+ const factories = new Set(['createApi']);
73
+ const rootKeys = new Set();
74
+ const folderMembers = new Map();
75
+ const members = [];
76
+ const resources = [];
77
+ for (const group of (0, grouping_1.groupOperations)(ctx.api.operations, options)) {
78
+ const base = (0, casing_1.lowerFirst)((0, imports_1.toIdentifier)((0, casing_1.upperFirst)(group.resource)));
79
+ const stem = (0, http_operations_1.claimUnique)(base, stems, (name) => `${group.folder}/${name}`);
80
+ if (stem !== base)
81
+ warn(`client: resource "${group.key}" clashes with another name; emitted as "${stem}"`);
82
+ const pascal = (0, casing_1.upperFirst)(stem);
83
+ const folderPascal = group.folder ? (0, casing_1.upperFirst)((0, imports_1.toIdentifier)((0, casing_1.upperFirst)(group.folder))) : '';
84
+ const factoryName = (0, http_operations_1.claimUnique)(`create${folderPascal}${pascal}Api`, factories);
85
+ const typeName = `${factoryName.slice('create'.length)}`;
86
+ const filePath = group.folder ? `${group.folder}/${stem}.ts` : `${stem}.ts`;
87
+ const imports = new imports_1.ImportCollector(path.join(options.dir, ...filePath.split('/')), locator);
88
+ const view = buildClientResourceView(group, { factoryName, typeName, imports, printOptions, options, warn });
89
+ ctx.emit({ path: filePath, content: ctx.templates.render('client/resource', view) });
90
+ resources.push({ factoryName, specifier: `./${filePath.replace(/\.ts$/, '')}` });
91
+ const member = { key: (0, naming_2.propertyKey)(stem), factoryName, children: [] };
92
+ if (!group.folder) {
93
+ members.push(Object.assign(Object.assign({}, member), { key: (0, naming_2.propertyKey)((0, http_operations_1.claimUnique)(stem, rootKeys)) }));
94
+ continue;
95
+ }
96
+ let folder = folderMembers.get(group.folder);
97
+ if (!folder) {
98
+ const folderKey = (0, http_operations_1.claimUnique)((0, casing_1.lowerFirst)((0, imports_1.toIdentifier)((0, casing_1.upperFirst)(group.folder))), rootKeys);
99
+ folder = { key: (0, naming_2.propertyKey)(folderKey), factoryName: null, children: [] };
100
+ folderMembers.set(group.folder, folder);
101
+ members.push(folder);
102
+ }
103
+ folder.children.push(member);
104
+ }
105
+ const api = {
106
+ banner: BANNER,
107
+ defaultBaseUrl: (_a = ctx.api.info.servers[0]) !== null && _a !== void 0 ? _a : '',
108
+ fetchTransport: options.transport !== 'none',
109
+ resources,
110
+ members,
111
+ };
112
+ ctx.emit({ path: `${CLIENT_FILE}.ts`, content: ctx.templates.render('client/client', api) });
113
+ },
114
+ };
115
+ function buildClientResourceView(group, build) {
116
+ var _a;
117
+ const { imports, options } = build;
118
+ const operations = (0, http_operations_1.supportedOperations)('client', group.operations, group, (_a = build.warn) !== null && _a !== void 0 ? _a : (() => undefined));
119
+ const names = (0, naming_1.uniqueOperationNames)(operations, options.naming, []);
120
+ const methodNames = operations.map((operation) => { var _a; return (_a = names.get(operation)) !== null && _a !== void 0 ? _a : operation.id; });
121
+ imports.reserve(build.factoryName, build.typeName, 'Send', 'RequestOptions', 'FormData', 'Blob', ...methodNames.map((name) => `${(0, casing_1.upperFirst)(name)}Query`));
122
+ const print = { imports, options: build.printOptions };
123
+ const methods = operations.map((operation, index) => buildClientMethodView(operation, methodNames[index], options, print));
124
+ return {
125
+ banner: BANNER,
126
+ factoryName: build.factoryName,
127
+ typeName: build.typeName,
128
+ imports: (0, models_1.importViews)(imports.list()),
129
+ methods,
130
+ };
131
+ }
132
+ function buildClientMethodView(declared, name, options, print) {
133
+ var _a;
134
+ const operation = (0, http_operations_1.withUndeclaredPathParams)(declared, false);
135
+ const responseType = (0, http_operations_1.responseKind)(operation.responses);
136
+ const content = (0, http_operations_1.successContent)(operation.responses);
137
+ const successType = responseType === 'blob' ? 'Blob' : content ? (0, type_printer_1.printType)(content.type, print) : 'void';
138
+ const body = operation.requestBody && operation.requestBody.contents.length ? operation.requestBody : undefined;
139
+ const media = body ? (0, http_operations_1.requestMedia)(body.contents, print) : undefined;
140
+ const locals = (0, http_operations_1.pathParamLocals)(operation, LOCAL_PARAM_RESERVED);
141
+ const queryParams = operation.parameters.filter((param) => param.in === 'query' || param.in === 'header');
142
+ const headerKeys = (0, http_operations_1.headerParamKeys)(operation.parameters);
143
+ const queryFields = queryParams.map((param) => { var _a; return ({
144
+ key: (0, naming_2.propertyKey)((_a = headerKeys.get(param)) !== null && _a !== void 0 ? _a : param.name),
145
+ type: (0, type_printer_1.printType)(param.type, print),
146
+ optional: !param.required,
147
+ doc: [...(0, http_operations_1.renamedHeaderDoc)(param, headerKeys.get(param)), ...(0, http_operations_1.docLines)(param.description)],
148
+ }); });
149
+ const queryType = queryFields.length ? `${(0, casing_1.upperFirst)(name)}Query` : null;
150
+ const params = [
151
+ ...operation.parameters
152
+ .filter((param) => param.in === 'path')
153
+ .map((param) => { var _a; return ({ name: (_a = locals.get(param.name)) !== null && _a !== void 0 ? _a : param.name, type: (0, type_printer_1.printType)(param.type, print), optional: false }); }),
154
+ ...(queryType ? [{ name: 'query', type: queryType, optional: queryFields.every((field) => field.optional) }] : []),
155
+ ...(media ? [{ name: 'body', type: media.type || 'unknown', optional: !(body === null || body === void 0 ? void 0 : body.required) }] : []),
156
+ { name: 'options', type: 'RequestOptions', optional: true },
157
+ ];
158
+ return {
159
+ name,
160
+ operation: (_a = declared.operationId) !== null && _a !== void 0 ? _a : name,
161
+ doc: [...(0, http_operations_1.docLines)(operation.summary), ...(0, http_operations_1.docLines)(operation.description), ...(operation.deprecated ? ['@deprecated'] : [])],
162
+ params: trailingOptionals(params),
163
+ queryType,
164
+ queryFields,
165
+ successType,
166
+ method: operation.method,
167
+ path: (0, http_operations_1.pathTemplateWithLocals)((0, http_operations_1.endpointFullPath)(operation.path, options), locals, true),
168
+ hasBody: media !== undefined,
169
+ contentType: media ? media.contentType : null,
170
+ responseType,
171
+ headerParams: [...headerKeys].map(([param, key]) => ({ key, name: param.name })),
172
+ };
173
+ }
174
+ function trailingOptionals(params) {
175
+ let tail = true;
176
+ return params
177
+ .slice()
178
+ .reverse()
179
+ .map((param) => {
180
+ if (!param.optional) {
181
+ tail = false;
182
+ return param;
183
+ }
184
+ return tail ? param : Object.assign(Object.assign({}, param), { type: `${param.type} | undefined`, optional: false });
185
+ })
186
+ .reverse();
187
+ }
@@ -0,0 +1,32 @@
1
+ import type { OutputPlugin } from '../../../core/plugin';
2
+ import type { Model, ModelId } from '../../../ir/types';
3
+ import { type ModelLocator } from '../imports';
4
+ import { type MockHints } from '../mock-hints';
5
+ import { type MocksOptions } from '../options';
6
+ import type { TsType } from '../ts-type';
7
+ import { type ImportView } from './models';
8
+ export interface MockFileView {
9
+ header: string;
10
+ imports: ImportView[];
11
+ refImports: ImportView[];
12
+ depthParam: string;
13
+ createName: string;
14
+ exportName: string;
15
+ typeName: string;
16
+ seed: number;
17
+ valueExpression: string;
18
+ }
19
+ export declare const mocksOutput: OutputPlugin<MocksOptions>;
20
+ export declare function hashSeed(name: string): number;
21
+ interface MockFileContext {
22
+ fromFile: string;
23
+ mockRoot: string;
24
+ arrayLength: number;
25
+ maxDepth: number;
26
+ cuts: Set<string>;
27
+ locator: ModelLocator;
28
+ shapeOf(id: ModelId): TsType | undefined;
29
+ hints: MockHints;
30
+ }
31
+ export declare function buildMockView(model: Model, file: MockFileContext): MockFileView;
32
+ export {};