@grandlinex/swagger-mate 1.2.2 → 1.3.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.
@@ -3,6 +3,7 @@ export type IfMappingKeyType = {
3
3
  key: string;
4
4
  type: string;
5
5
  required?: boolean;
6
+ nullable?: boolean;
6
7
  };
7
8
  export type IfMappingType = {
8
9
  name: string;
@@ -10,15 +11,28 @@ export type IfMappingType = {
10
11
  rawType?: string;
11
12
  };
12
13
  /**
13
- * Save string from unknown
14
- * @param e
14
+ * Returns a string representation of the given value. If the value is falsy,
15
+ * an empty string is returned.
16
+ *
17
+ * @param e - The value to convert to a string.
18
+ * @returns The string representation of `e`, or an empty string if `e` is falsy.
15
19
  */
16
20
  export declare function eS(e: any): string;
17
21
  /**
18
- * Optional field
19
- * @param required
22
+ * Returns a type annotation delimiter based on whether a value is required.
23
+ *
24
+ * @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
25
+ * @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
20
26
  */
21
27
  export declare function rq(required?: boolean): string;
28
+ /**
29
+ * Returns a type representation based on whether the value should be nullable.
30
+ *
31
+ * @param {string} type - The base type name to return when the value is not nullable.
32
+ * @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
33
+ * @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
34
+ */
35
+ export declare function rN(type: string, nullable?: boolean): string;
22
36
  export declare function sK(e: string): string;
23
37
  /**
24
38
  * Cast first letter to uppercase
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IFTag = void 0;
4
4
  exports.eS = eS;
5
5
  exports.rq = rq;
6
+ exports.rN = rN;
6
7
  exports.sK = sK;
7
8
  exports.fuc = fuc;
8
9
  exports.S = S;
@@ -13,15 +14,20 @@ exports.transformInterface = transformInterface;
13
14
  exports.transformFormInterface = transformFormInterface;
14
15
  const SwaggerTypes_js_1 = require("../Meta/SwaggerTypes.js");
15
16
  /**
16
- * Save string from unknown
17
- * @param e
17
+ * Returns a string representation of the given value. If the value is falsy,
18
+ * an empty string is returned.
19
+ *
20
+ * @param e - The value to convert to a string.
21
+ * @returns The string representation of `e`, or an empty string if `e` is falsy.
18
22
  */
19
23
  function eS(e) {
20
24
  return e || '';
21
25
  }
22
26
  /**
23
- * Optional field
24
- * @param required
27
+ * Returns a type annotation delimiter based on whether a value is required.
28
+ *
29
+ * @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
30
+ * @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
25
31
  */
26
32
  function rq(required) {
27
33
  if (!required) {
@@ -29,6 +35,19 @@ function rq(required) {
29
35
  }
30
36
  return ':';
31
37
  }
38
+ /**
39
+ * Returns a type representation based on whether the value should be nullable.
40
+ *
41
+ * @param {string} type - The base type name to return when the value is not nullable.
42
+ * @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
43
+ * @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
44
+ */
45
+ function rN(type, nullable) {
46
+ if (nullable) {
47
+ return `${type} | null`;
48
+ }
49
+ return type;
50
+ }
32
51
  function sK(e) {
33
52
  if (e.indexOf(':') >= 0) {
34
53
  return `'${e}'`;
@@ -98,20 +117,41 @@ function transformInterface(operation, tag, schema) {
98
117
  const prop = schema.properties[key];
99
118
  const isRequired = schema.required && schema.required.includes(key);
100
119
  if (!(0, SwaggerTypes_js_1.isSwaggerRef)(prop)) {
120
+ const nullable = prop.nullable ?? false;
101
121
  switch (prop.type) {
102
122
  case 'number':
103
123
  case 'integer':
104
- cur.keys.push({ key, type: 'number', required: isRequired });
124
+ cur.keys.push({
125
+ key,
126
+ type: 'number',
127
+ required: isRequired,
128
+ nullable,
129
+ });
105
130
  break;
106
131
  case 'string':
107
- cur.keys.push({ key, type: 'string', required: isRequired });
132
+ cur.keys.push({
133
+ key,
134
+ type: 'string',
135
+ required: isRequired,
136
+ nullable,
137
+ });
108
138
  break;
109
139
  case 'boolean':
110
- cur.keys.push({ key, type: 'boolean', required: isRequired });
140
+ cur.keys.push({
141
+ key,
142
+ type: 'boolean',
143
+ required: isRequired,
144
+ nullable,
145
+ });
111
146
  break;
112
147
  case 'object':
113
148
  if (!prop.properties) {
114
- cur.keys.push({ key, type: 'any', required: isRequired });
149
+ cur.keys.push({
150
+ key,
151
+ type: 'any',
152
+ required: isRequired,
153
+ nullable,
154
+ });
115
155
  }
116
156
  else {
117
157
  cur.keys.push({
@@ -128,6 +168,7 @@ function transformInterface(operation, tag, schema) {
128
168
  key,
129
169
  type: `${typeByRef(prop.items.$ref)}[]`,
130
170
  required: isRequired,
171
+ nullable,
131
172
  });
132
173
  }
133
174
  else {
@@ -135,6 +176,7 @@ function transformInterface(operation, tag, schema) {
135
176
  key,
136
177
  type: `${ifName(cur.name, `${key}Element`)}[]`,
137
178
  required: isRequired,
179
+ nullable,
138
180
  });
139
181
  out.push(...transformInterface(cur.name, key, prop));
140
182
  }
@@ -147,6 +189,7 @@ function transformInterface(operation, tag, schema) {
147
189
  key,
148
190
  type: typeByRef(prop.$ref),
149
191
  required: isRequired,
192
+ nullable: schema.nullable ?? false,
150
193
  });
151
194
  }
152
195
  }
@@ -8,6 +8,6 @@ function interfaceTemplate(IF_NAME, types, rawType) {
8
8
  return `export type ${IF_NAME} = ${rawType};`;
9
9
  }
10
10
  return `export interface ${IF_NAME} {
11
- ${types.map(({ key, type, required }) => `${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.sK)(key)}${(0, ClientUtil_js_1.rq)(required)} ${type};`).join('\n')}
11
+ ${types.map(({ key, type, required, nullable }) => `${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.sK)(key)}${(0, ClientUtil_js_1.rq)(required)} ${(0, ClientUtil_js_1.rN)(type, nullable)};`).join('\n')}
12
12
  }`;
13
13
  }
@@ -181,13 +181,13 @@ function createPackage(name, version, module) {
181
181
  types: 'dist/index.d.ts',
182
182
  module: module ? 'dist/index.js' : undefined,
183
183
  type: module ? 'module' : undefined,
184
- dependencies: {
185
- 'form-data': '4.0.4',
186
- axios: '1.11.0',
187
- },
188
184
  devDependencies: {
189
185
  '@types/node': '22.15.32',
190
- typescript: '5.8.3',
186
+ typescript: '5.9.2',
187
+ },
188
+ peerDependencies: {
189
+ axios: '>=1.13.2',
190
+ 'form-data': '>=4.0.5',
191
191
  },
192
192
  scripts: {
193
193
  build: 'tsc',
@@ -67,6 +67,7 @@ export type SSchemaEl = {
67
67
  items?: SSchemaEl;
68
68
  required?: string[];
69
69
  enum?: string[];
70
+ nullable?: boolean;
70
71
  } | SwaggerRRef;
71
72
  export type SwaggerContent = {
72
73
  [K in SMediaType]?: {
@@ -8,6 +8,7 @@ const SUtilMap_js_1 = __importDefault(require("./SUtilMap.js"));
8
8
  function resolveDBType(dType) {
9
9
  switch (dType) {
10
10
  case 'int':
11
+ case 'long':
11
12
  return 'integer';
12
13
  case 'double':
13
14
  case 'float':
@@ -174,11 +175,10 @@ class SPathUtil {
174
175
  keys.forEach((k) => {
175
176
  const cMeta = (0, core_1.getColumnMeta)(entity, k);
176
177
  if (cMeta && schema.properties) {
177
- if (!cMeta.canBeNull) {
178
- schema.required?.push(k);
179
- }
178
+ schema.required.push(k);
180
179
  schema.properties[k] = {
181
180
  type: resolveDBType(cMeta.dataType),
181
+ nullable: cMeta.canBeNull,
182
182
  };
183
183
  }
184
184
  });
@@ -3,6 +3,7 @@ export type IfMappingKeyType = {
3
3
  key: string;
4
4
  type: string;
5
5
  required?: boolean;
6
+ nullable?: boolean;
6
7
  };
7
8
  export type IfMappingType = {
8
9
  name: string;
@@ -10,15 +11,28 @@ export type IfMappingType = {
10
11
  rawType?: string;
11
12
  };
12
13
  /**
13
- * Save string from unknown
14
- * @param e
14
+ * Returns a string representation of the given value. If the value is falsy,
15
+ * an empty string is returned.
16
+ *
17
+ * @param e - The value to convert to a string.
18
+ * @returns The string representation of `e`, or an empty string if `e` is falsy.
15
19
  */
16
20
  export declare function eS(e: any): string;
17
21
  /**
18
- * Optional field
19
- * @param required
22
+ * Returns a type annotation delimiter based on whether a value is required.
23
+ *
24
+ * @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
25
+ * @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
20
26
  */
21
27
  export declare function rq(required?: boolean): string;
28
+ /**
29
+ * Returns a type representation based on whether the value should be nullable.
30
+ *
31
+ * @param {string} type - The base type name to return when the value is not nullable.
32
+ * @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
33
+ * @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
34
+ */
35
+ export declare function rN(type: string, nullable?: boolean): string;
22
36
  export declare function sK(e: string): string;
23
37
  /**
24
38
  * Cast first letter to uppercase
@@ -1,14 +1,19 @@
1
1
  import { isSwaggerRef } from '../Meta/SwaggerTypes.js';
2
2
  /**
3
- * Save string from unknown
4
- * @param e
3
+ * Returns a string representation of the given value. If the value is falsy,
4
+ * an empty string is returned.
5
+ *
6
+ * @param e - The value to convert to a string.
7
+ * @returns The string representation of `e`, or an empty string if `e` is falsy.
5
8
  */
6
9
  export function eS(e) {
7
10
  return e || '';
8
11
  }
9
12
  /**
10
- * Optional field
11
- * @param required
13
+ * Returns a type annotation delimiter based on whether a value is required.
14
+ *
15
+ * @param {boolean} [required] - Indicates if the value is required. If omitted or false, the value is considered optional.
16
+ * @returns {string} A colon (`:`) for required values or a question mark followed by a colon (`?:`) for optional values.
12
17
  */
13
18
  export function rq(required) {
14
19
  if (!required) {
@@ -16,6 +21,19 @@ export function rq(required) {
16
21
  }
17
22
  return ':';
18
23
  }
24
+ /**
25
+ * Returns a type representation based on whether the value should be nullable.
26
+ *
27
+ * @param {string} type - The base type name to return when the value is not nullable.
28
+ * @param {boolean} nullable - Indicates if the type should be considered nullable. If `true`, the function returns a colon (`:`); if `false`, it returns the original type string.
29
+ * @return {string} The original type string when `nullable` is `false`, otherwise a colon (`:`) to represent a nullable type in the consuming context.
30
+ */
31
+ export function rN(type, nullable) {
32
+ if (nullable) {
33
+ return `${type} | null`;
34
+ }
35
+ return type;
36
+ }
19
37
  export function sK(e) {
20
38
  if (e.indexOf(':') >= 0) {
21
39
  return `'${e}'`;
@@ -85,20 +103,41 @@ export function transformInterface(operation, tag, schema) {
85
103
  const prop = schema.properties[key];
86
104
  const isRequired = schema.required && schema.required.includes(key);
87
105
  if (!isSwaggerRef(prop)) {
106
+ const nullable = prop.nullable ?? false;
88
107
  switch (prop.type) {
89
108
  case 'number':
90
109
  case 'integer':
91
- cur.keys.push({ key, type: 'number', required: isRequired });
110
+ cur.keys.push({
111
+ key,
112
+ type: 'number',
113
+ required: isRequired,
114
+ nullable,
115
+ });
92
116
  break;
93
117
  case 'string':
94
- cur.keys.push({ key, type: 'string', required: isRequired });
118
+ cur.keys.push({
119
+ key,
120
+ type: 'string',
121
+ required: isRequired,
122
+ nullable,
123
+ });
95
124
  break;
96
125
  case 'boolean':
97
- cur.keys.push({ key, type: 'boolean', required: isRequired });
126
+ cur.keys.push({
127
+ key,
128
+ type: 'boolean',
129
+ required: isRequired,
130
+ nullable,
131
+ });
98
132
  break;
99
133
  case 'object':
100
134
  if (!prop.properties) {
101
- cur.keys.push({ key, type: 'any', required: isRequired });
135
+ cur.keys.push({
136
+ key,
137
+ type: 'any',
138
+ required: isRequired,
139
+ nullable,
140
+ });
102
141
  }
103
142
  else {
104
143
  cur.keys.push({
@@ -115,6 +154,7 @@ export function transformInterface(operation, tag, schema) {
115
154
  key,
116
155
  type: `${typeByRef(prop.items.$ref)}[]`,
117
156
  required: isRequired,
157
+ nullable,
118
158
  });
119
159
  }
120
160
  else {
@@ -122,6 +162,7 @@ export function transformInterface(operation, tag, schema) {
122
162
  key,
123
163
  type: `${ifName(cur.name, `${key}Element`)}[]`,
124
164
  required: isRequired,
165
+ nullable,
125
166
  });
126
167
  out.push(...transformInterface(cur.name, key, prop));
127
168
  }
@@ -134,6 +175,7 @@ export function transformInterface(operation, tag, schema) {
134
175
  key,
135
176
  type: typeByRef(prop.$ref),
136
177
  required: isRequired,
178
+ nullable: schema.nullable ?? false,
137
179
  });
138
180
  }
139
181
  }
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable prettier/prettier */
2
- import { rq, S, sK } from './ClientUtil.js';
2
+ import { rq, S, sK, rN } from './ClientUtil.js';
3
3
  function interfaceTemplate(IF_NAME, types, rawType) {
4
4
  if (rawType) {
5
5
  return `export type ${IF_NAME} = ${rawType};`;
6
6
  }
7
7
  return `export interface ${IF_NAME} {
8
- ${types.map(({ key, type, required }) => `${S(2)}${sK(key)}${rq(required)} ${type};`).join('\n')}
8
+ ${types.map(({ key, type, required, nullable }) => `${S(2)}${sK(key)}${rq(required)} ${rN(type, nullable)};`).join('\n')}
9
9
  }`;
10
10
  }
11
11
  export {
@@ -143,13 +143,13 @@ function createPackage(name, version, module) {
143
143
  types: 'dist/index.d.ts',
144
144
  module: module ? 'dist/index.js' : undefined,
145
145
  type: module ? 'module' : undefined,
146
- dependencies: {
147
- 'form-data': '4.0.4',
148
- axios: '1.11.0',
149
- },
150
146
  devDependencies: {
151
147
  '@types/node': '22.15.32',
152
- typescript: '5.8.3',
148
+ typescript: '5.9.2',
149
+ },
150
+ peerDependencies: {
151
+ axios: '>=1.13.2',
152
+ 'form-data': '>=4.0.5',
153
153
  },
154
154
  scripts: {
155
155
  build: 'tsc',
@@ -67,6 +67,7 @@ export type SSchemaEl = {
67
67
  items?: SSchemaEl;
68
68
  required?: string[];
69
69
  enum?: string[];
70
+ nullable?: boolean;
70
71
  } | SwaggerRRef;
71
72
  export type SwaggerContent = {
72
73
  [K in SMediaType]?: {
@@ -3,6 +3,7 @@ import map from './SUtilMap.js';
3
3
  function resolveDBType(dType) {
4
4
  switch (dType) {
5
5
  case 'int':
6
+ case 'long':
6
7
  return 'integer';
7
8
  case 'double':
8
9
  case 'float':
@@ -169,11 +170,10 @@ export default class SPathUtil {
169
170
  keys.forEach((k) => {
170
171
  const cMeta = getColumnMeta(entity, k);
171
172
  if (cMeta && schema.properties) {
172
- if (!cMeta.canBeNull) {
173
- schema.required?.push(k);
174
- }
173
+ schema.required.push(k);
175
174
  schema.properties[k] = {
176
175
  type: resolveDBType(cMeta.dataType),
176
+ nullable: cMeta.canBeNull,
177
177
  };
178
178
  }
179
179
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/swagger-mate",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -38,17 +38,19 @@
38
38
  "swagger-mate-esm": "./dist/mjs/cli.js"
39
39
  },
40
40
  "dependencies": {
41
- "@grandlinex/core": "1.2.0",
42
- "express": "5.1.0",
43
- "form-data": "4.0.4",
44
- "js-yaml": "4.1.0",
41
+ "@grandlinex/core": "1.3.1",
42
+ "js-yaml": "4.1.1",
45
43
  "reflect-metadata": "0.2.2"
46
44
  },
45
+ "peerDependencies": {
46
+ "express": ">=5.2.1",
47
+ "form-data": ">=4.0.5"
48
+ },
47
49
  "devDependencies": {
48
- "axios": "1.11.0",
50
+ "axios": "1.13.2",
49
51
  "node-fetch": "3.3.2",
50
52
  "cross-env": "10.0.0",
51
- "@types/express": "5.0.3",
53
+ "@types/express": "5.0.6",
52
54
  "@types/js-yaml": "4.0.9",
53
55
  "@types/jest": "29.5.14",
54
56
  "@types/node": "22.15.20",
@@ -68,7 +70,7 @@
68
70
  "ts-jest": "29.3.4",
69
71
  "ts-loader": "9.5.2",
70
72
  "ts-node": "10.9.2",
71
- "typedoc": "0.28.10",
73
+ "typedoc": "0.28.15",
72
74
  "typescript": "5.9.2"
73
75
  }
74
76
  }