swaggie 1.1.2 → 1.1.3-test.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,12 +25,11 @@ var _createBarrel = require('./createBarrel');
25
25
  const operations = _swagger.getOperations.call(void 0, spec);
26
26
  const groups = _utils.groupOperationsByGroupName.call(void 0, operations);
27
27
  const servicePrefix = _nullishCoalesce(options.servicePrefix, () => ( ''));
28
- let result =
29
- _utils.renderFile.call(void 0, 'baseClient.ejs', {
30
- servicePrefix,
31
- baseUrl: options.baseUrl,
32
- ...options.queryParamsSerialization,
33
- }) || '';
28
+ let result = _utils.renderFile.call(void 0, 'baseClient.ejs', {
29
+ servicePrefix,
30
+ baseUrl: options.baseUrl,
31
+ ...options.queryParamsSerialization,
32
+ });
34
33
 
35
34
  for (const name in groups) {
36
35
  const group = groups[name];
@@ -41,7 +40,7 @@ var _createBarrel = require('./createBarrel');
41
40
  servicePrefix,
42
41
  });
43
42
 
44
- result += renderedFile || '';
43
+ result += renderedFile;
45
44
  }
46
45
 
47
46
  result += _createBarrel.generateBarrelFile.call(void 0, groups, options);
@@ -64,6 +63,18 @@ function prepareClient(
64
63
  };
65
64
  }
66
65
 
66
+ /**
67
+ * Prepares operations for client generation. A lot of things will be done here:
68
+ * - Fix duplicate operation names
69
+ * - Determine the best response object and content type
70
+ * - Get the parameter type for the response object
71
+ * - Get the request body, query parameters, and other parameters
72
+ * - Sort parameters by their 'x-position' if defined
73
+ *
74
+ * @param operations Flat list of operations from the spec
75
+ * @param options
76
+ * @returns List of operations prepared for client generation
77
+ */
67
78
  function prepareOperations(
68
79
  operations,
69
80
  options
@@ -87,6 +98,8 @@ function prepareClient(
87
98
  params.sort((a, b) => a.original['x-position'] - b.original['x-position']);
88
99
  }
89
100
 
101
+ markParametersAsSkippable(params);
102
+
90
103
  const headers = getParams(op.parameters , options, ['header']);
91
104
  // Some libraries need to know the content type of the request body in case of urlencoded body
92
105
  if (_optionalChain([body, 'optionalAccess', _2 => _2.contentType]) === 'urlencoded') {
@@ -110,6 +123,17 @@ function prepareClient(
110
123
  });
111
124
  } exports.prepareOperations = prepareOperations;
112
125
 
126
+ function markParametersAsSkippable(params) {
127
+ const lastRequiredParamIndex = params.map((p) => !p.optional).lastIndexOf(true);
128
+ if (lastRequiredParamIndex === params.length - 1) {
129
+ return;
130
+ }
131
+
132
+ for (let i = lastRequiredParamIndex + 1; i < params.length; i++) {
133
+ params[i].skippable = true;
134
+ }
135
+ }
136
+
113
137
  /**
114
138
  * This function will replace path template expressions with ${encodeURIComponent('paramName')} placeholders
115
139
  * The end result will be a string that is effectively a template (i.e. you should wrap end result with backticks)
@@ -166,7 +190,7 @@ function prepareUrl(path) {
166
190
  return _case.camel.call(void 0, opId.replace(`${group}_`, ''));
167
191
  } exports.getOperationName = getOperationName;
168
192
 
169
- function getParams(
193
+ function getParams(
170
194
  params,
171
195
  options,
172
196
  where
@@ -175,7 +199,7 @@ function getParams(
175
199
  return [];
176
200
  }
177
201
 
178
- return params
202
+ const result = params
179
203
  .filter((p) => !where || where.includes(p.in))
180
204
  .map((p) => ({
181
205
  originalName: p.name,
@@ -184,7 +208,29 @@ function getParams(
184
208
  optional: p.required === undefined || p.required === null ? true : !p.required,
185
209
  original: p,
186
210
  }));
187
- }
211
+
212
+ if (_optionalChain([options, 'access', _3 => _3.modifiers, 'optionalAccess', _4 => _4.parameters])) {
213
+ for (const [name, modifier] of Object.entries(options.modifiers.parameters)) {
214
+ const paramIndex = result.findIndex(
215
+ (p) => p.original.in !== 'path' && (p.originalName === name || p.name === name)
216
+ );
217
+ if (paramIndex === -1) {
218
+ continue;
219
+ }
220
+ const param = result[paramIndex];
221
+
222
+ if (modifier === 'optional') {
223
+ param.optional = true;
224
+ } else if (modifier === 'required') {
225
+ param.optional = false;
226
+ } else if (modifier === 'ignore') {
227
+ result.splice(paramIndex, 1);
228
+ }
229
+ }
230
+ }
231
+
232
+ return result;
233
+ } exports.getParams = getParams;
188
234
 
189
235
  /**
190
236
  * Escapes param names to more safe form
@@ -244,6 +290,9 @@ function getRequestBody(reqBody) {
244
290
 
245
291
 
246
292
 
293
+
294
+
295
+
247
296
 
248
297
 
249
298
 
package/dist/types.d.ts CHANGED
@@ -20,6 +20,13 @@ export interface ClientOptions {
20
20
  dateFormat?: DateSupport;
21
21
  /** Options for query parameters serialization */
22
22
  queryParamsSerialization: QueryParamsSerializationOptions;
23
+ /** Offers ability to adjust the OpenAPI spec before it is processed */
24
+ modifiers?: {
25
+ /** Global-level modifiers for parameter with a given name */
26
+ parameters?: {
27
+ [key: string]: 'optional' | 'required' | 'ignore';
28
+ };
29
+ };
23
30
  }
24
31
  export interface CliOptions extends FullAppOptions {
25
32
  allowDots?: boolean;
@@ -37,5 +37,5 @@ function readLocalFile(filePath) {
37
37
  }
38
38
 
39
39
  function parseFileContents(contents, path) {
40
- return /.ya?ml$/i.test(path) ? _jsyaml2.default.load(contents) : JSON.parse(contents);
40
+ return /.ya?ml$/i.test(path) ? (_jsyaml2.default.load(contents) ) : JSON.parse(contents);
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-test.1",
4
4
  "description": "Generate TypeScript REST client code from an OpenAPI spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -61,11 +61,11 @@
61
61
  "@types/chai": "5.2.2",
62
62
  "@types/js-yaml": "4.0.9",
63
63
  "@types/mocha": "10.0.10",
64
- "@types/node": "24.0.14",
64
+ "@types/node": "24.2.0",
65
65
  "chai": "5.2.1",
66
66
  "mocha": "11.7.1",
67
67
  "openapi-types": "^12.1.3",
68
68
  "sucrase": "3.35.0",
69
- "typescript": "5.8.3"
69
+ "typescript": "5.9.2"
70
70
  }
71
71
  }
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? '| null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: AxiosRequestConfig
11
11
  ): AxiosPromise<<%~ it.returnType %>> {
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? '| null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: RequestInit
11
11
  ): Promise<<%~ it.returnType %>> {
@@ -6,7 +6,7 @@
6
6
  * @return Success
7
7
  */
8
8
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
9
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? ' | null | undefined' : '' %>,
9
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
10
10
  <% }); %>
11
11
  config?: IRequestShortcutConfig
12
12
  ): IPromise<<%~ it.returnType %>> {
@@ -7,7 +7,7 @@
7
7
  */
8
8
  <%= it.name %>(
9
9
  <% it.parameters.forEach((parameter) => { %>
10
- <%= parameter.name %>: <%~ parameter.type %><%= parameter.optional ? ' | null | undefined' : '' %>,
10
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
11
11
  <% }); %>
12
12
  config?: any
13
13
  ): Observable<<%~ it.returnType %>> {
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? ' | null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: AxiosRequestConfig
11
11
  ): AxiosPromise<<%~ it.returnType %>> {
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  export function <%= it.swrOpName %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? ' | null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: SwrConfig
11
11
  ) {
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? '| null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: XiorRequestConfig
11
11
  ): Promise<XiorResponse<<%~ it.returnType %>>> {
@@ -7,7 +7,7 @@
7
7
  * @param $httpConfig (optional) Additional configuration for xior request (actually executes the request)
8
8
  */
9
9
  export function <%= it.rqOpName %><TData = <%~ it.returnType %>, TError = Error>(<% it.parameters.forEach((parameter) => { %>
10
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? ' | null | undefined' : '' %>,
10
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
11
11
  <% }); %>
12
12
  $config?: Omit<
13
13
  UseQueryOptions<<%~ it.returnType %>, TError, TData>,
@@ -5,7 +5,7 @@
5
5
  <% }); -%>
6
6
  */
7
7
  <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
- <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? '| null | undefined' : '' %>,
8
+ <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
9
9
  <% }); %>
10
10
  $config?: XiorRequestConfig
11
11
  ): Promise<XiorResponse<<%~ it.returnType %>>> {