@grandlinex/swagger-mate 1.2.2 → 1.3.2

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 (37) hide show
  1. package/dist/cjs/Swagger/Client/ClientUtil.d.ts +18 -4
  2. package/dist/cjs/Swagger/Client/ClientUtil.js +51 -8
  3. package/dist/cjs/Swagger/Client/InterfaceTemplate.js +1 -1
  4. package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -5
  5. package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
  6. package/dist/cjs/Swagger/Path/SPathUtil.d.ts +173 -2
  7. package/dist/cjs/Swagger/Path/SPathUtil.js +261 -5
  8. package/dist/cjs/Swagger/SwaggerUtil.d.ts +18 -2
  9. package/dist/cjs/Swagger/SwaggerUtil.js +32 -5
  10. package/dist/cjs/Swagger/annotation/index.d.ts +8 -3
  11. package/dist/cjs/Swagger/debug/BaseCon.d.ts +115 -11
  12. package/dist/cjs/Swagger/debug/BaseCon.js +142 -38
  13. package/dist/cjs/cli.js +5 -1
  14. package/dist/mjs/Swagger/Client/ClientUtil.d.ts +18 -4
  15. package/dist/mjs/Swagger/Client/ClientUtil.js +50 -8
  16. package/dist/mjs/Swagger/Client/InterfaceTemplate.js +2 -2
  17. package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -5
  18. package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +1 -0
  19. package/dist/mjs/Swagger/Path/SPathUtil.d.ts +173 -2
  20. package/dist/mjs/Swagger/Path/SPathUtil.js +261 -5
  21. package/dist/mjs/Swagger/SwaggerUtil.d.ts +18 -2
  22. package/dist/mjs/Swagger/SwaggerUtil.js +33 -6
  23. package/dist/mjs/Swagger/annotation/index.d.ts +8 -3
  24. package/dist/mjs/Swagger/debug/BaseCon.d.ts +115 -11
  25. package/dist/mjs/Swagger/debug/BaseCon.js +142 -38
  26. package/dist/mjs/cli.js +5 -1
  27. package/package.json +10 -8
  28. package/res/html/rapi-doc/index.html +28 -0
  29. package/res/html/rapi-doc/rapidoc-min.js +3915 -0
  30. package/res/html/{index.html → swagger-ui/index.html} +11 -3
  31. package/res/html/swagger-ui/swagger-ui-bundle.js +2 -0
  32. package/res/html/swagger-ui/swagger-ui-standalone-preset.js +2 -0
  33. package/res/html/swagger-ui/swagger-ui.css +3 -0
  34. package/res/templates/class/BaseCon.ts +160 -61
  35. package/res/html/swagger-ui-bundle.js +0 -2
  36. package/res/html/swagger-ui-standalone-preset.js +0 -2
  37. package/res/html/swagger-ui.css +0 -3
@@ -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]?: {
@@ -2,15 +2,104 @@ import { CoreEntity } from '@grandlinex/core';
2
2
  import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
3
3
  import { SKey, SSchemaEl, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
4
4
  export default class SPathUtil {
5
+ /**
6
+ * Generates a default response mapping for the specified HTTP status types.
7
+ *
8
+ * @param {HttpStatusTypes[]} types - The HTTP status types for which default responses should be created.
9
+ * @return {SwaggerRPathConfResponse} An object mapping each provided status type to its default response definition. */
5
10
  static defaultResponse(...types: HttpStatusTypes[]): SwaggerRPathConfResponse;
11
+ /**
12
+ * Creates a request body definition for JSON content type using the provided schema.
13
+ *
14
+ * @param {SSchemaEl} schema - The JSON schema used for validating the request body.
15
+ * @return {SwaggerRPathReqBody} A Swagger path request body object specifying application/json content type with the provided schema.
16
+ */
6
17
  static jsonBody(schema: SSchemaEl): SwaggerRPathReqBody;
18
+ /**
19
+ * Builds a Swagger request body for `multipart/form-data` requests.
20
+ *
21
+ * @param {SSchemaEl} [schema] Optional schema describing the form data.
22
+ * If omitted, a default schema with a single binary `file` field is provided.
23
+ * @return {SwaggerRPathReqBody} Swagger request body definition with
24
+ * `multipart/form-data` content and the supplied or default schema. */
7
25
  static formBody(schema?: SSchemaEl): SwaggerRPathReqBody;
26
+ /**
27
+ * Generates a Swagger content definition for the provided entity.
28
+ *
29
+ * @param {T} entity - The entity instance to derive the Swagger schema from.
30
+ * @param {boolean} [list] - When true, the schema will be wrapped in an array type, representing a list of entities.
31
+ *
32
+ * @returns {SwaggerContent|undefined} The Swagger content object for the entity, or `undefined` if the entity does not have a schema.
33
+ */
8
34
  static entityContent<T extends CoreEntity>(entity: T, list?: boolean): SwaggerContent | undefined;
35
+ /**
36
+ * @template T extends CoreEntity
37
+ * @param {T} entity - The entity instance for which to build the response configuration.
38
+ * @param {boolean} [list] - Indicates whether the response should represent a list of entities.
39
+ * @param {boolean} [create] - Indicates whether the response corresponds to a creation operation (status code 201); otherwise 200.
40
+ * @returns {SwaggerRPathConfResponse} The Swagger response configuration object containing the appropriate status code and content.
41
+ */
9
42
  static entityResponse<T extends CoreEntity>(entity: T, list?: boolean, create?: boolean): SwaggerRPathConfResponse;
43
+ /**
44
+ * Builds a JSON schema reference path for the given component name.
45
+ *
46
+ * @param {string} inp - The name of the schema component.
47
+ * @return {string} The JSON reference path formatted as `#/components/schemas/<inp>`.
48
+ */
10
49
  static schemaPath(inp: string): string;
50
+ /**
51
+ * Creates a Swagger request body definition that references a schema.
52
+ *
53
+ * @param {string | CoreEntity} $ref
54
+ * Either the string reference to a schema or a `CoreEntity` instance whose
55
+ * class name will be used to build the reference path.
56
+ * @param {boolean} list
57
+ * If true, the referenced schema is wrapped in an array; otherwise the
58
+ * schema is used directly.
59
+ * @returns {SwaggerRPathReqBody}
60
+ * The request body object containing the appropriate content and schema
61
+ * configuration.
62
+ */
63
+ static refRequest($ref: string | CoreEntity, list: boolean): SwaggerRPathReqBody;
64
+ /**
65
+ * Creates a Swagger response configuration for a given HTTP status code.
66
+ *
67
+ * @param {HttpStatusTypes} code - The primary HTTP status code for */
11
68
  static refResponse(code: HttpStatusTypes, $ref: string | CoreEntity, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
69
+ /**
70
+ * Builds a Swagger response configuration object for a given HTTP status code and schema.
71
+ *
72
+ * @param {HttpStatusTypes} code - The primary HTTP status code for the response.
73
+ * @param {SSchemaEl} schema - The JSON schema definition for the response body.
74
+ * @param {boolean} list - If true, the schema is wrapped in an array for list responses.
75
+ * @param {...HttpStatusTypes} addCodes - Additional HTTP status codes for default responses.
76
+ * @return {SwaggerRPathConfResponse} The constructed response configuration object.
77
+ */
12
78
  static jsonResponse(code: HttpStatusTypes, schema: SSchemaEl, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
79
+ /**
80
+ * Generates a JSON schema representation from a CoreEntity instance.
81
+ *
82
+ * This method inspects the entity's metadata to construct a schema object
83
+ * describing the entity's shape. The resulting schema contains:
84
+ * - `type`: always `"object"`.
85
+ * - `description`: a string indicating the entity name.
86
+ * - `required`: an array of property names that are defined on the entity.
87
+ * - `properties`: an object mapping each property name to an object that
88
+ * includes the resolved database type and its nullability.
89
+ *
90
+ * If no metadata is found for the provided entity, the method returns `undefined`.
91
+ *
92
+ * @param {T} entity - The entity instance for which to create a schema.
93
+ * @returns {SSchemaEl | undefined} The generated schema object, or `undefined`
94
+ * if the entity's metadata could not be retrieved.
95
+ */
13
96
  static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaEl | undefined;
97
+ /**
98
+ * Generates a content schema object for the given entity. The schema contains a description derived from the entity metadata and a JSON content schema based on the entity's structure.
99
+ *
100
+ * @param {T} entity - The entity instance for which to generate the content schema. The generic type `T` must extend {@link CoreEntity}.
101
+ * @returns {{ description: string; content: { 'application/json': { schema: SSchemaEl } }; } | undefined} An object containing the content schema, or `undefined` if no metadata is available for the entity.
102
+ */
14
103
  static contentSchemaFromEntity<T extends CoreEntity>(entity: T): {
15
104
  description: string;
16
105
  content: {
@@ -20,9 +109,91 @@ export default class SPathUtil {
20
109
  };
21
110
  } | undefined;
22
111
  /**
23
- * generate global schema
24
- * @param e
112
+ * Generates a mapping from entity names to their corresponding schema objects.
113
+ *
114
+ * @param {CoreEntity[]} e The entities for which schema entries should be generated.
115
+ * @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
25
116
  */
26
117
  static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaEl>;
118
+ /**
119
+ * Builds a JSON schema representation for an entity view that includes both the
120
+ * entity data and its related entity map.
121
+ *
122
+ * @param entity The primary entity used to construct the `dat` portion of the schema.
123
+ * @param entityMap The related entity map used to construct the `join_map` portion of the schema.
124
+ * @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
125
+ */
27
126
  static schemaFromEntityView<A extends CoreEntity, B extends CoreEntity>(entity: A, entityMap: B): SSchemaEl;
127
+ /**
128
+ * Extends an entity schema object by merging additional schema options.
129
+ *
130
+ * @param {CoreEntity} entity
131
+ * The entity for which the schema should be extended.
132
+ *
133
+ * @param {...Object} options
134
+ * One or more objects defining schema extensions. Each object may contain:
135
+ * - `key` (string): The property key to add or extend.
136
+ * - `list` (boolean, optional): Indicates whether the property is a list.
137
+ * - `entity` (CoreEntity, optional): The entity type for the property.
138
+ * - `schema` (SSchemaEl, optional): A custom schema definition for the property.
139
+ * - `required` (boolean, optional): Whether the property is required.
140
+ *
141
+ * @return {SSchemaEl}
142
+ * The resulting schema element. If a single property is returned by
143
+ * `extendEntitySchema`, its schema is returned directly; otherwise an
144
+ * object schema with a type of `'object'` is returned.
145
+ */
146
+ static extendEntitySchemaObject(entity: CoreEntity, ...options: {
147
+ key: string;
148
+ list?: boolean;
149
+ entity?: CoreEntity;
150
+ schema?: SSchemaEl;
151
+ required?: boolean;
152
+ }[]): SSchemaEl;
153
+ /**
154
+ * Extends the schema of a given {@link CoreEntity} with additional properties.
155
+ *
156
+ * @param {CoreEntity} entity
157
+ * The entity whose schema will be extended.
158
+ *
159
+ * @param {...{
160
+ * key: string,
161
+ * list?: boolean,
162
+ * entity?: CoreEntity,
163
+ * schema?: SSchemaEl,
164
+ * required?: boolean
165
+ * }} options
166
+ * One or more option objects specifying the extensions to apply. Each option
167
+ * may provide either a direct schema (`schema`) or an entity reference
168
+ * (`entity`). The `list` flag indicates whether the property should be
169
+ * represented as an array of the provided schema. The `required` flag
170
+ * adds the property to the schema’s required list.
171
+ *
172
+ * @returns {SKey<SSchemaEl>}
173
+ * An object containing the updated schema for the entity, keyed by the
174
+ * entity’s name. If the entity metadata cannot be found, an empty
175
+ * object is returned.
176
+ */
177
+ static extendEntitySchema(entity: CoreEntity, ...options: {
178
+ key: string;
179
+ list?: boolean;
180
+ entity?: CoreEntity;
181
+ schema?: SSchemaEl;
182
+ required?: boolean;
183
+ }[]): SKey<SSchemaEl>;
184
+ /**
185
+ * Reduces the entity schema to a single schema element or a generic object.
186
+ *
187
+ * @param entity The entity whose schema should be reduced.
188
+ * @param keys Optional list of keys to include in the reduced schema. If omitted, all keys are considered.
189
+ * @return Returns the schema element of the sole key if only one key is present; otherwise, returns a generic object schema with type `'object'`. */
190
+ static reduceEntitySchemaObject<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SSchemaEl;
191
+ /**
192
+ * Creates a reduced version of an entity's schema by excluding specified properties.
193
+ *
194
+ * @param {CoreEntity} entity - The entity whose schema is to be processed.
195
+ * @param {...string} keys - Property names to remove from the schema's `properties` and `required` lists.
196
+ *
197
+ * @returns */
198
+ static reduceEntitySchema<T extends CoreEntity>(entity: T, ...keys: (keyof T)[]): SKey<SSchemaEl>;
28
199
  }