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,246 @@
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.modelsOutput = void 0;
37
+ exports.printOptionsFor = printOptionsFor;
38
+ exports.resolveModelShape = resolveModelShape;
39
+ exports.buildModelView = buildModelView;
40
+ exports.importViews = importViews;
41
+ exports.buildIndexView = buildIndexView;
42
+ const path = __importStar(require("path"));
43
+ const imports_1 = require("../imports");
44
+ const naming_1 = require("../naming");
45
+ const options_1 = require("../options");
46
+ const type_printer_1 = require("../type-printer");
47
+ const ts_type_1 = require("../ts-type");
48
+ const compatibility_naming_1 = require("../compatibility-naming");
49
+ const model_compatibility_1 = require("../model-compatibility");
50
+ exports.modelsOutput = {
51
+ name: 'models',
52
+ description: 'TypeScript types for every schema component',
53
+ optionsSchema: options_1.modelsOptionsSchema,
54
+ defaults: {
55
+ dir: './models',
56
+ engine: 'ir',
57
+ layout: 'namespace',
58
+ index: false,
59
+ inlineEnums: 'union',
60
+ strictEnums: false,
61
+ enumSchemas: 'union',
62
+ objectTypeConst: false,
63
+ arrayStyle: 'brackets',
64
+ untyped: 'unknown',
65
+ nestedArrays: 'preserve',
66
+ nullable: 'union',
67
+ inlineObjects: 'literal',
68
+ typeImports: true,
69
+ legacyQuirks: false,
70
+ },
71
+ generate(ctx) {
72
+ const { api, options } = ctx;
73
+ if ((0, model_compatibility_1.generateCompatibilityModels)(ctx))
74
+ return;
75
+ const baseLocator = (0, imports_1.createModelLocator)(api, { dir: options.dir, layout: options.layout, importPath: options.importPath });
76
+ const locator = options.legacyQuirks ? (0, model_compatibility_1.doubleSlashLocator)(baseLocator, options.importPath) : baseLocator;
77
+ const overrides = options.legacyQuirks ? (0, model_compatibility_1.legacyModelOverrides)(api) : undefined;
78
+ const indexEntries = [];
79
+ for (const model of api.models) {
80
+ const filePath = `${locator.modulePath(model.id)}.ts`;
81
+ const override = overrides === null || overrides === void 0 ? void 0 : overrides.get(model.id);
82
+ const seed = override
83
+ ? (imports) => { var _a; return (0, model_compatibility_1.seedLegacyImports)(imports, override.imports, locator, { importPath: options.importPath, typeOnly: (_a = options.typeImports) !== null && _a !== void 0 ? _a : true }, model.id); }
84
+ : undefined;
85
+ const view = buildModelView(override ? Object.assign(Object.assign({}, model), { type: override.type }) : model, locator, options, path.join(options.dir, ...filePath.split('/')), seed);
86
+ ctx.emit({ path: filePath, content: ctx.templates.render(`models/${view.kind === 'object' ? 'model' : view.kind}`, view) });
87
+ indexEntries.push(Object.assign({ modulePath: locator.modulePath(model.id) }, exportedNames(view)));
88
+ }
89
+ if (options.index) {
90
+ const view = buildIndexView(indexEntries, options, (msg) => ctx.log.warn(msg));
91
+ ctx.emit({ path: 'index.ts', content: ctx.templates.render('models/index', view) });
92
+ }
93
+ },
94
+ };
95
+ function printOptionsFor(options) {
96
+ var _a, _b;
97
+ return {
98
+ arrayStyle: options.arrayStyle,
99
+ untyped: options.untyped,
100
+ nestedArrays: options.nestedArrays,
101
+ nullable: options.nullable,
102
+ enums: options.inlineEnums === 'const' ? 'base' : 'union',
103
+ objects: (_a = options.inlineObjects) !== null && _a !== void 0 ? _a : 'literal',
104
+ typeImports: (_b = options.typeImports) !== null && _b !== void 0 ? _b : true,
105
+ };
106
+ }
107
+ function resolveModelShape(model, locator, options, imports = new imports_1.ImportCollector(path.join(options.dir, ...`${locator.modulePath(model.id)}.ts`.split('/')), locator)) {
108
+ const name = locator.typeName(model.id);
109
+ imports.reserve(name);
110
+ const ctx = { imports, options: printOptionsFor(options), selfId: model.id };
111
+ const type = model.type;
112
+ if (type.kind === 'object' && (type.properties.length > 0 || options.inlineObjects === 'object')) {
113
+ return resolveObjectShape(model, type, name, ctx, options);
114
+ }
115
+ if (type.kind === 'enum')
116
+ return resolveEnumShape(model, type, name, ctx, options);
117
+ return { kind: 'alias', type: (0, type_printer_1.resolveType)(type, ctx) };
118
+ }
119
+ function resolveObjectShape(model, type, name, ctx, options) {
120
+ const hoist = options.inlineEnums === 'const';
121
+ const objectTypeProp = options.objectTypeConst || undefined;
122
+ const consts = [];
123
+ const constNames = (constName) => (options.strictEnums ? [constName, `${constName}Strict`] : [constName]);
124
+ for (const property of type.properties) {
125
+ if (property.name === objectTypeProp || (hoist && property.type.kind === 'enum')) {
126
+ ctx.imports.reserve(...constNames((0, naming_1.propertyEnumName)(name, property.name)));
127
+ }
128
+ }
129
+ const hoisted = (constName, members) => {
130
+ consts.push({ name: constName, asConst: false, members });
131
+ if (options.strictEnums)
132
+ consts.push({ name: `${constName}Strict`, asConst: true, members });
133
+ return { kind: 'const', name: constName, members };
134
+ };
135
+ const properties = type.properties.map((property) => {
136
+ if (property.name === objectTypeProp) {
137
+ const ref = hoisted((0, naming_1.propertyEnumName)(name, property.name), [(0, compatibility_naming_1.objectTypeMember)(model.id)]);
138
+ return { name: property.name, optional: false, type: (0, type_printer_1.propertyType)(property.type, ref, ctx.options) };
139
+ }
140
+ if (hoist && property.type.kind === 'enum') {
141
+ const ref = hoisted((0, naming_1.propertyEnumName)(name, property.name), (0, compatibility_naming_1.legacyConstMembers)(property.type));
142
+ return { name: property.name, optional: !property.required, type: (0, type_printer_1.propertyType)(property.type, ref, ctx.options) };
143
+ }
144
+ return { name: property.name, optional: !property.required, type: (0, type_printer_1.propertyType)(property.type, (0, type_printer_1.resolveType)(property.type, ctx), ctx.options) };
145
+ });
146
+ const object = { kind: 'object', properties };
147
+ const additional = options.inlineObjects === 'literal' && type.additionalProperties ? (0, type_printer_1.resolveType)(type.additionalProperties, ctx) : undefined;
148
+ return {
149
+ kind: 'object',
150
+ type: additional === undefined ? object : { kind: 'intersection', members: [object, { kind: 'record', values: additional }] },
151
+ object,
152
+ additional,
153
+ consts,
154
+ };
155
+ }
156
+ function resolveEnumShape(model, type, name, ctx, options) {
157
+ const style = options.enumSchemas;
158
+ if (style === 'enum') {
159
+ const members = (0, compatibility_naming_1.tsEnumMembers)(type);
160
+ return { kind: 'enum', style, members, type: { kind: 'enum', id: model.id, name, members } };
161
+ }
162
+ if (style === 'const') {
163
+ const values = (0, naming_1.constEnumValues)(type.values);
164
+ return { kind: 'enum', style, members: (0, naming_1.constMembers)(type.values), type: (0, ts_type_1.union)(values.map(ts_type_1.literalType)) };
165
+ }
166
+ return { kind: 'enum', style, members: [], type: (0, type_printer_1.resolveType)(type, Object.assign(Object.assign({}, ctx), { options: Object.assign(Object.assign({}, ctx.options), { enums: 'union' }) })) };
167
+ }
168
+ function buildModelView(model, locator, options, fromFile, seedImports) {
169
+ const imports = new imports_1.ImportCollector(fromFile, locator);
170
+ imports.reserve(locator.typeName(model.id));
171
+ seedImports === null || seedImports === void 0 ? void 0 : seedImports(imports);
172
+ const shape = resolveModelShape(model, locator, options, imports);
173
+ const base = { header: headerComment(options.header), name: locator.typeName(model.id), doc: (0, naming_1.docLines)(model.description) };
174
+ if (shape.kind === 'object') {
175
+ const declared = model.type.properties;
176
+ return Object.assign(Object.assign({ kind: 'object' }, base), { imports: importViews(imports.list()), consts: shape.consts, properties: shape.object.properties.map((p, i) => { var _a; return ({
177
+ key: options.legacyQuirks ? (0, compatibility_naming_1.legacyPropertyKey)(p.name) : (0, naming_1.propertyKey)(p.name),
178
+ optional: p.optional,
179
+ type: (0, ts_type_1.printTsType)(p.type),
180
+ doc: (0, naming_1.docLines)(options.legacyQuirks ? (_a = declared[i].description) === null || _a === void 0 ? void 0 : _a.split('*/').join('') : declared[i].description),
181
+ }); }), suffix: shape.additional !== undefined ? ` & Record<string, ${(0, ts_type_1.printTsType)(shape.additional)}>` : '' });
182
+ }
183
+ if (shape.kind === 'enum') {
184
+ const union = shape.style === 'union' ? (0, ts_type_1.printTsType)(shape.type) : '';
185
+ return Object.assign(Object.assign({ kind: 'enum' }, base), { imports: [], style: shape.style, members: shape.members, union });
186
+ }
187
+ return Object.assign(Object.assign({ kind: 'alias' }, base), { type: (0, ts_type_1.printTsType)(shape.type), imports: importViews(imports.list()) });
188
+ }
189
+ function importViews(decls) {
190
+ return decls.map((d) => ({
191
+ specifier: d.specifier,
192
+ typeOnly: d.typeOnly,
193
+ names: d.names.map((n) => (n.alias ? `${n.name} as ${n.alias}` : n.name)).join(', '),
194
+ }));
195
+ }
196
+ function headerComment(header) {
197
+ if (!header)
198
+ return null;
199
+ const trimmed = header.trimEnd();
200
+ if (trimmed.startsWith('//') || trimmed.startsWith('/*'))
201
+ return trimmed;
202
+ return trimmed
203
+ .split('\n')
204
+ .map((line) => (line ? `// ${line}` : '//'))
205
+ .join('\n');
206
+ }
207
+ function exportedNames(view) {
208
+ const typeNames = [view.name];
209
+ const valueNames = [];
210
+ if (view.kind === 'object')
211
+ valueNames.push(...view.consts.map((c) => c.name));
212
+ if (view.kind === 'enum' && view.style !== 'union') {
213
+ typeNames.length = 0;
214
+ valueNames.push(view.name);
215
+ }
216
+ return { typeNames, valueNames };
217
+ }
218
+ function buildIndexView(entries, options, warn) {
219
+ var _a;
220
+ const taken = new Map();
221
+ const exports = [];
222
+ const keep = (names, modulePath) => names.filter((n) => {
223
+ const owner = taken.get(n);
224
+ if (owner !== undefined) {
225
+ warn(`models index: "${n}" from ${modulePath} not exported (already exported from ${owner})`);
226
+ return false;
227
+ }
228
+ taken.set(n, modulePath);
229
+ return true;
230
+ });
231
+ for (const entry of entries) {
232
+ const specifier = `./${entry.modulePath}`;
233
+ const types = keep(entry.typeNames, entry.modulePath);
234
+ const values = keep(entry.valueNames, entry.modulePath);
235
+ if ((_a = options.typeImports) !== null && _a !== void 0 ? _a : true) {
236
+ if (types.length)
237
+ exports.push({ keyword: 'export type', names: types.join(', '), specifier });
238
+ if (values.length)
239
+ exports.push({ keyword: 'export', names: values.join(', '), specifier });
240
+ }
241
+ else if (types.length || values.length) {
242
+ exports.push({ keyword: 'export', names: [...types, ...values].join(', '), specifier });
243
+ }
244
+ }
245
+ return { header: headerComment(options.header), exports };
246
+ }
@@ -0,0 +1,69 @@
1
+ import type { OutputPlugin } from '../../../core/plugin';
2
+ import { type ResourceGroup } from '../../../ir/operations/grouping';
3
+ import type { Operation } from '../../../ir/types';
4
+ import { ImportCollector } from '../imports';
5
+ import { type RtkQueryOptions } from '../options';
6
+ import { type PrintContext } from '../type-printer';
7
+ import { type ImportView } from './models';
8
+ export interface RtkArgFieldView {
9
+ key: string;
10
+ optional: boolean;
11
+ type: string;
12
+ }
13
+ export interface RtkQueryParamView {
14
+ key: string;
15
+ accessor: string;
16
+ }
17
+ export interface RtkHeaderParamView {
18
+ key: string;
19
+ accessor: string;
20
+ required: boolean;
21
+ }
22
+ export interface RtkUrlPartView {
23
+ text: string;
24
+ accessor: string | null;
25
+ }
26
+ export interface RtkEndpointViewModel {
27
+ name: string;
28
+ builder: 'query' | 'mutation';
29
+ httpMethod: string;
30
+ emitMethod: boolean;
31
+ responseAlias: string;
32
+ responseType: string;
33
+ argAlias: string;
34
+ argFields: RtkArgFieldView[];
35
+ path: string;
36
+ hasPathParams: boolean;
37
+ urlParts: RtkUrlPartView[];
38
+ queryParams: RtkQueryParamView[];
39
+ headerParams: RtkHeaderParamView[];
40
+ contentType: string | null;
41
+ readAs: string | null;
42
+ toolkitHandler: 'text' | 'blob' | null;
43
+ body: {
44
+ accessor: string;
45
+ } | null;
46
+ idParam: {
47
+ accessor: string;
48
+ } | null;
49
+ hookName: string;
50
+ }
51
+ export interface RtkResourceViewModel {
52
+ apiConstName: string;
53
+ tagType: string;
54
+ baseApiImport: string;
55
+ imports: ImportView[];
56
+ endpoints: RtkEndpointViewModel[];
57
+ }
58
+ export declare const rtkQueryOutput: OutputPlugin<RtkQueryOptions>;
59
+ export interface RtkBuildContext {
60
+ resourceName: string;
61
+ apiConstName: string;
62
+ imports: ImportCollector;
63
+ printOptions: PrintContext['options'];
64
+ options: RtkQueryOptions;
65
+ }
66
+ export declare function resourceNameOf(group: ResourceGroup): string;
67
+ export declare function uniqueResourceName(group: ResourceGroup, claimed: Set<string>, warn: (message: string) => void): string;
68
+ export declare function buildRtkResourceViewModel(group: ResourceGroup, build: RtkBuildContext): RtkResourceViewModel;
69
+ export declare function buildRtkEndpointViewModel(operation: Operation, name: string, print: PrintContext, options: RtkQueryOptions): RtkEndpointViewModel;
@@ -0,0 +1,266 @@
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.rtkQueryOutput = void 0;
37
+ exports.resourceNameOf = resourceNameOf;
38
+ exports.uniqueResourceName = uniqueResourceName;
39
+ exports.buildRtkResourceViewModel = buildRtkResourceViewModel;
40
+ exports.buildRtkEndpointViewModel = buildRtkEndpointViewModel;
41
+ const path = __importStar(require("path"));
42
+ const casing_1 = require("../../../ir/casing");
43
+ const grouping_1 = require("../../../ir/operations/grouping");
44
+ const naming_1 = require("../../../ir/operations/naming");
45
+ const imports_1 = require("../imports");
46
+ const naming_2 = require("../naming");
47
+ const options_1 = require("../options");
48
+ const type_printer_1 = require("../type-printer");
49
+ const models_1 = require("./models");
50
+ const http_operations_1 = require("../http-operations");
51
+ exports.rtkQueryOutput = {
52
+ name: 'rtkQuery',
53
+ description: 'RTK Query: one base createApi + injectEndpoints per resource, typed hooks, tag invalidation',
54
+ optionsSchema: options_1.rtkQueryOptionsSchema,
55
+ defaults: {
56
+ dir: './rtk-query',
57
+ naming: 'path',
58
+ folders: false,
59
+ stripPrefixes: ['/app/api'],
60
+ basePath: '',
61
+ runtime: 'transport',
62
+ transport: 'fetch',
63
+ },
64
+ generate(ctx) {
65
+ var _a, _b;
66
+ const { options } = ctx;
67
+ if (options.runtime === 'transport' || options.runtime === 'toolkit') {
68
+ ctx.emit({ path: 'api.ts', content: ctx.templates.render('rtk-query/api', {
69
+ defaultBaseUrl: (_a = ctx.api.info.servers[0]) !== null && _a !== void 0 ? _a : '',
70
+ fetchTransport: options.transport !== 'none',
71
+ toolkit: options.runtime === 'toolkit',
72
+ reducerPath: (_b = options.reducerPath) !== null && _b !== void 0 ? _b : ctx.source.name,
73
+ }) });
74
+ }
75
+ const peers = modelPeers(ctx);
76
+ const locator = (0, imports_1.locatorFromPeers)(ctx.api, peers);
77
+ const printOptions = Object.assign(Object.assign({}, (0, models_1.printOptionsFor)(peers.models)), { typeImports: true });
78
+ const claimed = new Set();
79
+ for (const group of (0, grouping_1.groupOperations)(ctx.api.operations, options)) {
80
+ const resourceName = uniqueResourceName(group, claimed, (message) => ctx.log.warn(message));
81
+ const apiConstName = `${(0, casing_1.lowerFirst)(resourceName)}Api`;
82
+ const filePath = group.folder ? `${group.folder}/${apiConstName}.ts` : `${apiConstName}.ts`;
83
+ const fromFile = path.join(options.dir, ...filePath.split('/'));
84
+ const imports = new imports_1.ImportCollector(fromFile, locator);
85
+ const view = buildRtkResourceViewModel(group, { resourceName, apiConstName, imports, printOptions, options });
86
+ ctx.emit({ path: filePath, content: ctx.templates.render('rtk-query/resource', view) });
87
+ }
88
+ },
89
+ };
90
+ function resourceNameOf(group) {
91
+ return (0, imports_1.toIdentifier)((0, casing_1.upperFirst)(group.resource));
92
+ }
93
+ function uniqueResourceName(group, claimed, warn) {
94
+ const base = resourceNameOf(group);
95
+ const keyOf = (name) => `${group.folder}/${(0, casing_1.lowerFirst)(name)}Api`;
96
+ let name = base;
97
+ for (let counter = 2; claimed.has(keyOf(name)); counter++)
98
+ name = `${base}${counter}`;
99
+ claimed.add(keyOf(name));
100
+ if (name !== base)
101
+ warn(`rtkQuery: resource "${group.key}" clashes with another after sanitizing; emitted as "${name}"`);
102
+ return name;
103
+ }
104
+ function buildRtkResourceViewModel(group, build) {
105
+ const { resourceName, apiConstName, imports, options } = build;
106
+ const depth = group.folder ? group.folder.split('/').filter(Boolean).length : 0;
107
+ const names = (0, naming_1.uniqueOperationNames)(group.operations, options.naming);
108
+ const endpointNames = group.operations.map((op) => { var _a; return (_a = names.get(op)) !== null && _a !== void 0 ? _a : op.id; });
109
+ imports.reserve(apiConstName, 'baseApi', 'FormData', ...endpointNames.flatMap((name) => {
110
+ const pascal = (0, casing_1.upperFirst)(name);
111
+ return [`${pascal}ApiResponse`, `${pascal}ApiArg`, `use${pascal}Query`, `use${pascal}Mutation`];
112
+ }));
113
+ const print = { imports, options: build.printOptions };
114
+ const endpoints = group.operations.map((operation, index) => buildRtkEndpointViewModel(operation, endpointNames[index], print, options));
115
+ return {
116
+ apiConstName,
117
+ tagType: resourceName,
118
+ baseApiImport: baseApiSpecifier(options.runtime, depth),
119
+ imports: (0, models_1.importViews)(sortDeclarations(imports.list())),
120
+ endpoints,
121
+ };
122
+ }
123
+ function buildRtkEndpointViewModel(operation, name, print, options) {
124
+ const isQuery = operation.method === 'get';
125
+ const transport = options.runtime === 'transport';
126
+ const toolkit = options.runtime === 'toolkit';
127
+ const pascal = (0, casing_1.upperFirst)(name);
128
+ const fullPath = (0, http_operations_1.endpointFullPath)(operation.path, options);
129
+ const declaredPath = operation.parameters.filter((param) => param.in === 'path');
130
+ const queryParams = operation.parameters.filter((param) => param.in === 'query');
131
+ const placeholders = pathPlaceholders(fullPath);
132
+ const body = requestBodyView(operation, print);
133
+ const claimed = new Set(body ? ['body'] : []);
134
+ const pathProps = new Map();
135
+ const argFields = [];
136
+ const claimPathParam = (wireName, type) => {
137
+ if (pathProps.has(wireName))
138
+ return;
139
+ const prop = claimArgName(wireName, 'path', claimed);
140
+ pathProps.set(wireName, prop);
141
+ argFields.push({ key: (0, naming_2.propertyKey)(prop), optional: false, type });
142
+ };
143
+ for (const param of declaredPath)
144
+ claimPathParam(param.name, (0, type_printer_1.printType)(param.type, print));
145
+ for (const placeholder of placeholders)
146
+ claimPathParam(placeholder, 'string');
147
+ const queryViews = queryParams.map((param) => {
148
+ const prop = claimArgName(param.name, 'query', claimed);
149
+ argFields.push({ key: (0, naming_2.propertyKey)(prop), optional: !param.required, type: (0, type_printer_1.printType)(param.type, print) });
150
+ return { key: (0, naming_2.propertyKey)(param.name), accessor: accessor(prop) };
151
+ });
152
+ const headerViews = operation.parameters
153
+ .filter((param) => param.in === 'header')
154
+ .map((param) => {
155
+ const prop = claimArgName(param.name, 'header', claimed);
156
+ argFields.push({ key: (0, naming_2.propertyKey)(prop), optional: !param.required, type: (0, type_printer_1.printType)(param.type, print) });
157
+ return { key: (0, naming_2.propertyKey)(param.name), accessor: accessor(prop), required: param.required };
158
+ });
159
+ if (body)
160
+ argFields.push({ key: 'body', optional: !body.required, type: body.type });
161
+ const kind = (0, http_operations_1.responseKind)(operation.responses);
162
+ const lastPlaceholder = placeholders[placeholders.length - 1];
163
+ const idProp = lastPlaceholder === undefined ? undefined : pathProps.get(lastPlaceholder);
164
+ return {
165
+ name,
166
+ builder: isQuery ? 'query' : 'mutation',
167
+ httpMethod: operation.method.toUpperCase(),
168
+ emitMethod: !isQuery,
169
+ responseAlias: `${pascal}ApiResponse`,
170
+ responseType: (transport || toolkit) && kind === 'blob' ? 'Blob' : responseTypeOf(operation, print),
171
+ argAlias: `${pascal}ApiArg`,
172
+ argFields,
173
+ path: fullPath,
174
+ hasPathParams: placeholders.length > 0,
175
+ urlParts: urlParts(fullPath, pathProps, transport || toolkit),
176
+ queryParams: queryViews,
177
+ headerParams: headerViews,
178
+ contentType: transport && body && !isDefaultMediaType(body.mediaType) ? body.mediaType : null,
179
+ readAs: transport && kind !== 'json' ? kind : null,
180
+ toolkitHandler: toolkit && kind !== 'json' ? kind : null,
181
+ body: body ? { accessor: 'queryArg.body' } : null,
182
+ idParam: idProp === undefined ? null : { accessor: accessor(idProp) },
183
+ hookName: `use${pascal}${isQuery ? 'Query' : 'Mutation'}`,
184
+ };
185
+ }
186
+ function responseTypeOf(operation, print) {
187
+ const success = operation.responses.find((response) => response.status.startsWith('2'));
188
+ const content = success ? pickContent(success.contents) : undefined;
189
+ return content ? (0, type_printer_1.printType)(content.type, print) : 'void';
190
+ }
191
+ function requestBodyView(operation, print) {
192
+ const body = operation.requestBody;
193
+ if (!body || body.contents.length === 0)
194
+ return undefined;
195
+ if (body.contents.some((content) => content.mediaType === 'multipart/form-data')) {
196
+ return { type: 'FormData', required: body.required, mediaType: 'multipart/form-data' };
197
+ }
198
+ const content = pickContent(body.contents);
199
+ return content ? { type: (0, type_printer_1.printType)(content.type, print), required: body.required, mediaType: content.mediaType } : undefined;
200
+ }
201
+ function isDefaultMediaType(mediaType) {
202
+ return mediaType === 'multipart/form-data' || (0, http_operations_1.pickJsonContent)([{ mediaType }]) !== undefined;
203
+ }
204
+ function pickContent(contents) {
205
+ var _a;
206
+ return (_a = contents.find((content) => content.mediaType === 'application/json')) !== null && _a !== void 0 ? _a : contents[0];
207
+ }
208
+ const PLACEHOLDER = /\{([^}]+)\}/g;
209
+ function pathPlaceholders(fullPath) {
210
+ return Array.from(fullPath.matchAll(PLACEHOLDER), (match) => match[1]);
211
+ }
212
+ function urlParts(fullPath, props, encode = false) {
213
+ var _a, _b;
214
+ if (pathPlaceholders(fullPath).length === 0)
215
+ return [];
216
+ const parts = [];
217
+ let last = 0;
218
+ for (const match of fullPath.matchAll(PLACEHOLDER)) {
219
+ const start = (_a = match.index) !== null && _a !== void 0 ? _a : 0;
220
+ if (start > last)
221
+ parts.push({ text: escapeTemplateText(fullPath.slice(last, start)), accessor: null });
222
+ const value = accessor((_b = props.get(match[1])) !== null && _b !== void 0 ? _b : match[1]);
223
+ parts.push({ text: '', accessor: encode ? `encodeURIComponent(String(${value}))` : value });
224
+ last = start + match[0].length;
225
+ }
226
+ if (last < fullPath.length)
227
+ parts.push({ text: escapeTemplateText(fullPath.slice(last)), accessor: null });
228
+ return parts;
229
+ }
230
+ function escapeTemplateText(text) {
231
+ return text.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
232
+ }
233
+ function claimArgName(wireName, prefix, claimed) {
234
+ let name = wireName;
235
+ if (claimed.has(name)) {
236
+ const base = `${prefix}${(0, casing_1.pascalCase)((0, imports_1.toIdentifier)(wireName))}`;
237
+ name = base;
238
+ for (let counter = 2; claimed.has(name); counter++)
239
+ name = `${base}${counter}`;
240
+ }
241
+ claimed.add(name);
242
+ return name;
243
+ }
244
+ function accessor(name) {
245
+ return (0, naming_2.isIdentifier)(name) ? `queryArg.${name}` : `queryArg[${JSON.stringify(name)}]`;
246
+ }
247
+ function baseApiSpecifier(runtime, depth) {
248
+ const relative = depth === 0 ? './' : '../'.repeat(depth);
249
+ if (runtime === 'transport' || runtime === 'toolkit')
250
+ return `${relative}api`;
251
+ const spec = runtime.imports.baseApi;
252
+ if (!spec.startsWith('.'))
253
+ return spec;
254
+ const joined = path.posix.normalize(`${'../'.repeat(depth)}${spec}`);
255
+ return joined.startsWith('.') ? joined : `./${joined}`;
256
+ }
257
+ function sortDeclarations(decls) {
258
+ const key = (decl) => { var _a, _b; var _c, _d; return (_d = (_c = (_a = decl.names[0]) === null || _a === void 0 ? void 0 : _a.alias) !== null && _c !== void 0 ? _c : (_b = decl.names[0]) === null || _b === void 0 ? void 0 : _b.name) !== null && _d !== void 0 ? _d : ''; };
259
+ return [...decls].sort((a, b) => key(a).localeCompare(key(b)));
260
+ }
261
+ function modelPeers(ctx) {
262
+ const models = ctx.peers.models;
263
+ if ((models === null || models === void 0 ? void 0 : models.enabled) || (models === null || models === void 0 ? void 0 : models.importPath))
264
+ return ctx.peers;
265
+ return Object.assign(Object.assign({}, ctx.peers), { models: Object.assign(Object.assign({}, models), { importPath: '@models/swagger' }) });
266
+ }
@@ -0,0 +1,7 @@
1
+ import type { Formatter } from '../../core/plugin';
2
+ export interface PrettierFormatterOptions {
3
+ resolveFrom?: string;
4
+ configFile?: string;
5
+ options?: Record<string, unknown>;
6
+ }
7
+ export declare function createPrettierFormatter(settings?: PrettierFormatterOptions): Formatter;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createPrettierFormatter = createPrettierFormatter;
13
+ function createPrettierFormatter(settings = {}) {
14
+ let prettier;
15
+ const configCache = new Map();
16
+ const resolveConfig = (filePath) => {
17
+ const key = settings.configFile ? `${settings.configFile}#${filePath}` : filePath;
18
+ let cached = configCache.get(key);
19
+ if (!cached) {
20
+ cached = prettier.resolveConfig(filePath, { config: settings.configFile, editorconfig: true });
21
+ configCache.set(key, cached);
22
+ }
23
+ return cached;
24
+ };
25
+ return {
26
+ name: 'prettier',
27
+ format(filePath, content) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ var _a, _b;
30
+ prettier !== null && prettier !== void 0 ? prettier : (prettier = loadPrettier((_a = settings.resolveFrom) !== null && _a !== void 0 ? _a : process.cwd()));
31
+ const resolved = (_b = (yield resolveConfig(filePath))) !== null && _b !== void 0 ? _b : {};
32
+ return prettier.format(content, Object.assign(Object.assign(Object.assign({}, resolved), settings.options), { filepath: filePath }));
33
+ });
34
+ },
35
+ };
36
+ }
37
+ function loadPrettier(fromDir) {
38
+ try {
39
+ return require(require.resolve('prettier', { paths: [fromDir] }));
40
+ }
41
+ catch (_a) {
42
+ return require('prettier');
43
+ }
44
+ }
@@ -0,0 +1,30 @@
1
+ {% comment -%}
2
+ SDK-specific entry point. Data: ClientApiView.
3
+ {% endcomment -%}
4
+ {{ banner }}
5
+ {% block imports -%}
6
+ import { createSend, withOperationHooks, type OperationsConfig, type {% if fetchTransport %}RuntimeConfig{% else %}TransportConfig{% endif %}, type Send } from "swagger-sdk-generator/runtime";
7
+ {% for resource in resources -%}
8
+ import { {{ resource.factoryName }} } from {{ resource.specifier | quote }};
9
+ {% endfor -%}
10
+ {% endblock %}
11
+
12
+ export type { RequestOptions } from "swagger-sdk-generator/runtime";
13
+ export const DEFAULT_BASE_URL = {{ defaultBaseUrl | quote }};
14
+ export type ApiConfig = {% if fetchTransport %}RuntimeConfig{% else %}TransportConfig{% endif %} & { operations?: OperationsConfig<Api> };
15
+
16
+ function buildApi(send: Send) {
17
+ {% block api -%}
18
+ return {
19
+ {% for member in members -%}
20
+ {% render 'client/partials/api-member', member: member %}
21
+ {% endfor -%}
22
+ };
23
+ {% endblock %}
24
+ }
25
+
26
+ export type Api = ReturnType<typeof buildApi>;
27
+
28
+ export function createApi({ operations, ...config }: ApiConfig{% if fetchTransport %} = {}{% endif %}): Api {
29
+ return withOperationHooks(buildApi(createSend(config, DEFAULT_BASE_URL)), operations);
30
+ }