@grandlinex/swagger-mate 1.3.1 → 1.3.3

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/Meta/SwaggerTypes.d.ts +3 -2
  2. package/dist/cjs/Swagger/Path/ESchemaEditor.d.ts +51 -0
  3. package/dist/cjs/Swagger/Path/ESchemaEditor.js +151 -0
  4. package/dist/cjs/Swagger/Path/SPathUtil.d.ts +107 -5
  5. package/dist/cjs/Swagger/Path/SPathUtil.js +136 -52
  6. package/dist/cjs/Swagger/SwaggerUtil.d.ts +18 -2
  7. package/dist/cjs/Swagger/SwaggerUtil.js +32 -5
  8. package/dist/cjs/Swagger/annotation/index.d.ts +8 -3
  9. package/dist/cjs/Swagger/debug/BaseCon.d.ts +115 -11
  10. package/dist/cjs/Swagger/debug/BaseCon.js +142 -38
  11. package/dist/cjs/cli.js +5 -1
  12. package/dist/cjs/index.d.ts +1 -0
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +3 -2
  15. package/dist/mjs/Swagger/Path/ESchemaEditor.d.ts +51 -0
  16. package/dist/mjs/Swagger/Path/ESchemaEditor.js +147 -0
  17. package/dist/mjs/Swagger/Path/SPathUtil.d.ts +107 -5
  18. package/dist/mjs/Swagger/Path/SPathUtil.js +137 -53
  19. package/dist/mjs/Swagger/SwaggerUtil.d.ts +18 -2
  20. package/dist/mjs/Swagger/SwaggerUtil.js +33 -6
  21. package/dist/mjs/Swagger/annotation/index.d.ts +8 -3
  22. package/dist/mjs/Swagger/debug/BaseCon.d.ts +115 -11
  23. package/dist/mjs/Swagger/debug/BaseCon.js +142 -38
  24. package/dist/mjs/cli.js +5 -1
  25. package/dist/mjs/index.d.ts +1 -0
  26. package/dist/mjs/index.js +1 -0
  27. package/package.json +2 -2
  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
@@ -56,7 +56,7 @@ export interface SwaggerRInfo {
56
56
  version: string;
57
57
  license?: SwaggerRInfoLicence;
58
58
  }
59
- export type SSchemaEl = {
59
+ export type SSchemaElObj = {
60
60
  type: SDataType;
61
61
  example?: string;
62
62
  format?: SDataFormat;
@@ -68,7 +68,8 @@ export type SSchemaEl = {
68
68
  required?: string[];
69
69
  enum?: string[];
70
70
  nullable?: boolean;
71
- } | SwaggerRRef;
71
+ };
72
+ export type SSchemaEl = SSchemaElObj | SwaggerRRef;
72
73
  export type SwaggerContent = {
73
74
  [K in SMediaType]?: {
74
75
  schema: SSchemaEl;
@@ -0,0 +1,51 @@
1
+ import { CoreEntity } from '@grandlinex/core';
2
+ import { SKey, SSchemaEl, SSchemaElObj } from '../Meta/SwaggerTypes.js';
3
+ export type ESchemaAddOption = {
4
+ key: string;
5
+ list?: boolean;
6
+ entity?: CoreEntity;
7
+ schema?: SSchemaEl;
8
+ required?: boolean;
9
+ nullable?: boolean;
10
+ };
11
+ export declare class ESchemaEditor<T extends CoreEntity> {
12
+ private data;
13
+ private name;
14
+ private constructor();
15
+ /**
16
+ * Removes the specified keys from the schema's properties and updates the required list.
17
+ *
18
+ * @param {...(keyof T)} keys - The keys of the properties to remove.
19
+ * @returns {ESchemaEditor<T>} The editor instance for method chaining.
20
+ */
21
+ remove(...keys: (keyof T)[]): ESchemaEditor<T>;
22
+ /**
23
+ * Adds properties to the schema based on the provided options.
24
+ *
25
+ * @param {...ESchemaAddOption} options The options describing the properties to add. Each option may specify a
26
+ * `key`, a `schema` or an `entity`, and optionally whether the property is a `list`, `nullable`, or `required`.
27
+ * @returns {ESchemaEditor<T>} The editor instance for chaining.
28
+ */
29
+ add(...options: ESchemaAddOption[]): ESchemaEditor<T>;
30
+ getSchema(): SSchemaElObj;
31
+ getSKeySchema(): SKey<SSchemaElObj>;
32
+ static fromEntity<J extends CoreEntity>(e: J): ESchemaEditor<J>;
33
+ /**
34
+ * Generates a JSON schema representation from a CoreEntity instance.
35
+ *
36
+ * This method inspects the entity's metadata to construct a schema object
37
+ * describing the entity's shape. The resulting schema contains:
38
+ * - `type`: always `"object"`.
39
+ * - `description`: a string indicating the entity name.
40
+ * - `required`: an array of property names that are defined on the entity.
41
+ * - `properties`: an object mapping each property name to an object that
42
+ * includes the resolved database type and its nullability.
43
+ *
44
+ * If no metadata is found for the provided entity, the method returns `undefined`.
45
+ *
46
+ * @param {T} entity - The entity instance for which to create a schema.
47
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
48
+ * if the entity's metadata could not be retrieved.
49
+ */
50
+ static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaElObj | undefined;
51
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ESchemaEditor = void 0;
4
+ const core_1 = require("@grandlinex/core");
5
+ function resolveDBType(dType) {
6
+ switch (dType) {
7
+ case 'int':
8
+ case 'long':
9
+ return 'integer';
10
+ case 'double':
11
+ case 'float':
12
+ return 'number';
13
+ case 'blob':
14
+ return 'string';
15
+ case 'string':
16
+ case 'text':
17
+ case 'uuid':
18
+ return 'string';
19
+ case 'boolean':
20
+ return 'boolean';
21
+ case 'date':
22
+ return 'string';
23
+ case 'json':
24
+ return 'object';
25
+ default:
26
+ throw Error('TypeNotSupported');
27
+ }
28
+ }
29
+ class ESchemaEditor {
30
+ constructor(entity, name) {
31
+ this.data = ESchemaEditor.schemaFromEntity(entity);
32
+ this.name = name;
33
+ }
34
+ /**
35
+ * Removes the specified keys from the schema's properties and updates the required list.
36
+ *
37
+ * @param {...(keyof T)} keys - The keys of the properties to remove.
38
+ * @returns {ESchemaEditor<T>} The editor instance for method chaining.
39
+ */
40
+ remove(...keys) {
41
+ if (this.data.properties) {
42
+ for (const key of keys) {
43
+ this.data.properties = Object.fromEntries(Object.entries(this.data.properties).filter(([e]) => key !== e));
44
+ this.data.required = (this.data.required || []).filter((e) => key !== e);
45
+ }
46
+ }
47
+ return this;
48
+ }
49
+ /**
50
+ * Adds properties to the schema based on the provided options.
51
+ *
52
+ * @param {...ESchemaAddOption} options The options describing the properties to add. Each option may specify a
53
+ * `key`, a `schema` or an `entity`, and optionally whether the property is a `list`, `nullable`, or `required`.
54
+ * @returns {ESchemaEditor<T>} The editor instance for chaining.
55
+ */
56
+ add(...options) {
57
+ if (!this.data.properties) {
58
+ return this;
59
+ }
60
+ for (const option of options) {
61
+ if (option.schema) {
62
+ if (option.list) {
63
+ this.data.properties[option.key] = {
64
+ type: 'array',
65
+ items: option.schema,
66
+ nullable: option.nullable,
67
+ };
68
+ }
69
+ else {
70
+ this.data.properties[option.key] = option.schema;
71
+ }
72
+ }
73
+ else if (option.entity) {
74
+ const scheme = ESchemaEditor.fromEntity(option.entity).getSchema();
75
+ if (option.nullable) {
76
+ scheme.nullable = true;
77
+ }
78
+ if (option.list) {
79
+ this.data.properties[option.key] = {
80
+ type: 'array',
81
+ items: scheme,
82
+ };
83
+ }
84
+ else {
85
+ this.data.properties[option.key] = scheme;
86
+ }
87
+ }
88
+ if (option.required) {
89
+ this.data.required = [...(this.data.required || []), option.key];
90
+ }
91
+ }
92
+ return this;
93
+ }
94
+ getSchema() {
95
+ return this.data;
96
+ }
97
+ getSKeySchema() {
98
+ return {
99
+ [this.name]: this.data,
100
+ };
101
+ }
102
+ static fromEntity(e) {
103
+ const meta = (0, core_1.getEntityMeta)(e);
104
+ if (meta) {
105
+ return new ESchemaEditor(e, meta.name);
106
+ }
107
+ throw new Error('Entity metadata not found');
108
+ }
109
+ /**
110
+ * Generates a JSON schema representation from a CoreEntity instance.
111
+ *
112
+ * This method inspects the entity's metadata to construct a schema object
113
+ * describing the entity's shape. The resulting schema contains:
114
+ * - `type`: always `"object"`.
115
+ * - `description`: a string indicating the entity name.
116
+ * - `required`: an array of property names that are defined on the entity.
117
+ * - `properties`: an object mapping each property name to an object that
118
+ * includes the resolved database type and its nullability.
119
+ *
120
+ * If no metadata is found for the provided entity, the method returns `undefined`.
121
+ *
122
+ * @param {T} entity - The entity instance for which to create a schema.
123
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
124
+ * if the entity's metadata could not be retrieved.
125
+ */
126
+ static schemaFromEntity(entity) {
127
+ const schema = {
128
+ type: 'object',
129
+ properties: {},
130
+ };
131
+ const meta = (0, core_1.getEntityMeta)(entity);
132
+ if (!meta) {
133
+ return undefined;
134
+ }
135
+ schema.description = `Entity: ${meta.name}`;
136
+ schema.required = [];
137
+ const keys = Object.keys(entity);
138
+ keys.forEach((k) => {
139
+ const cMeta = (0, core_1.getColumnMeta)(entity, k);
140
+ if (cMeta && schema.properties) {
141
+ schema.required.push(k);
142
+ schema.properties[k] = {
143
+ type: resolveDBType(cMeta.dataType),
144
+ nullable: cMeta.canBeNull,
145
+ };
146
+ }
147
+ });
148
+ return schema;
149
+ }
150
+ }
151
+ exports.ESchemaEditor = ESchemaEditor;
@@ -1,16 +1,107 @@
1
1
  import { CoreEntity } from '@grandlinex/core';
2
2
  import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
3
- import { SKey, SSchemaEl, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
3
+ import { SKey, SSchemaEl, SSchemaElObj, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
4
+ import { ESchemaEditor } from './ESchemaEditor.js';
4
5
  export default class SPathUtil {
6
+ /**
7
+ * Generates a default response mapping for the specified HTTP status types.
8
+ *
9
+ * @param {HttpStatusTypes[]} types - The HTTP status types for which default responses should be created.
10
+ * @return {SwaggerRPathConfResponse} An object mapping each provided status type to its default response definition. */
5
11
  static defaultResponse(...types: HttpStatusTypes[]): SwaggerRPathConfResponse;
12
+ /**
13
+ * Creates a request body definition for JSON content type using the provided schema.
14
+ *
15
+ * @param {SSchemaEl} schema - The JSON schema used for validating the request body.
16
+ * @return {SwaggerRPathReqBody} A Swagger path request body object specifying application/json content type with the provided schema.
17
+ */
6
18
  static jsonBody(schema: SSchemaEl): SwaggerRPathReqBody;
19
+ /**
20
+ * Builds a Swagger request body for `multipart/form-data` requests.
21
+ *
22
+ * @param {SSchemaEl} [schema] Optional schema describing the form data.
23
+ * If omitted, a default schema with a single binary `file` field is provided.
24
+ * @return {SwaggerRPathReqBody} Swagger request body definition with
25
+ * `multipart/form-data` content and the supplied or default schema. */
7
26
  static formBody(schema?: SSchemaEl): SwaggerRPathReqBody;
27
+ /**
28
+ * Generates a Swagger content definition for the provided entity.
29
+ *
30
+ * @param {T} entity - The entity instance to derive the Swagger schema from.
31
+ * @param {boolean} [list] - When true, the schema will be wrapped in an array type, representing a list of entities.
32
+ *
33
+ * @returns {SwaggerContent|undefined} The Swagger content object for the entity, or `undefined` if the entity does not have a schema.
34
+ */
8
35
  static entityContent<T extends CoreEntity>(entity: T, list?: boolean): SwaggerContent | undefined;
36
+ /**
37
+ * @template T extends CoreEntity
38
+ * @param {T} entity - The entity instance for which to build the response configuration.
39
+ * @param {boolean} [list] - Indicates whether the response should represent a list of entities.
40
+ * @param {boolean} [create] - Indicates whether the response corresponds to a creation operation (status code 201); otherwise 200.
41
+ * @returns {SwaggerRPathConfResponse} The Swagger response configuration object containing the appropriate status code and content.
42
+ */
9
43
  static entityResponse<T extends CoreEntity>(entity: T, list?: boolean, create?: boolean): SwaggerRPathConfResponse;
44
+ /**
45
+ * Builds a JSON schema reference path for the given component name.
46
+ *
47
+ * @param {string} inp - The name of the schema component.
48
+ * @return {string} The JSON reference path formatted as `#/components/schemas/<inp>`.
49
+ */
10
50
  static schemaPath(inp: string): string;
51
+ /**
52
+ * Creates a Swagger request body definition that references a schema.
53
+ *
54
+ * @param {string | CoreEntity} $ref
55
+ * Either the string reference to a schema or a `CoreEntity` instance whose
56
+ * class name will be used to build the reference path.
57
+ * @param {boolean} list
58
+ * If true, the referenced schema is wrapped in an array; otherwise the
59
+ * schema is used directly.
60
+ * @returns {SwaggerRPathReqBody}
61
+ * The request body object containing the appropriate content and schema
62
+ * configuration.
63
+ */
64
+ static refRequest($ref: string | CoreEntity, list: boolean): SwaggerRPathReqBody;
65
+ /**
66
+ * Creates a Swagger response configuration for a given HTTP status code.
67
+ *
68
+ * @param {HttpStatusTypes} code - The primary HTTP status code for */
11
69
  static refResponse(code: HttpStatusTypes, $ref: string | CoreEntity, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
70
+ /**
71
+ * Builds a Swagger response configuration object for a given HTTP status code and schema.
72
+ *
73
+ * @param {HttpStatusTypes} code - The primary HTTP status code for the response.
74
+ * @param {SSchemaEl} schema - The JSON schema definition for the response body.
75
+ * @param {boolean} list - If true, the schema is wrapped in an array for list responses.
76
+ * @param {...HttpStatusTypes} addCodes - Additional HTTP status codes for default responses.
77
+ * @return {SwaggerRPathConfResponse} The constructed response configuration object.
78
+ */
12
79
  static jsonResponse(code: HttpStatusTypes, schema: SSchemaEl, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
13
- static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaEl | undefined;
80
+ /**
81
+ * Generates a JSON schema representation from a CoreEntity instance.
82
+ *
83
+ * This method inspects the entity's metadata to construct a schema object
84
+ * describing the entity's shape. The resulting schema contains:
85
+ * - `type`: always `"object"`.
86
+ * - `description`: a string indicating the entity name.
87
+ * - `required`: an array of property names that are defined on the entity.
88
+ * - `properties`: an object mapping each property name to an object that
89
+ * includes the resolved database type and its nullability.
90
+ *
91
+ * If no metadata is found for the provided entity, the method returns `undefined`.
92
+ *
93
+ * @param {T} entity - The entity instance for which to create a schema.
94
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
95
+ * if the entity's metadata could not be retrieved.
96
+ * @deprecated Use {@link ESchemaEditor.schemaFromEntity} instead.
97
+ */
98
+ static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaElObj | undefined;
99
+ /**
100
+ * 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.
101
+ *
102
+ * @param {T} entity - The entity instance for which to generate the content schema. The generic type `T` must extend {@link CoreEntity}.
103
+ * @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.
104
+ */
14
105
  static contentSchemaFromEntity<T extends CoreEntity>(entity: T): {
15
106
  description: string;
16
107
  content: {
@@ -20,9 +111,20 @@ export default class SPathUtil {
20
111
  };
21
112
  } | undefined;
22
113
  /**
23
- * generate global schema
24
- * @param e
114
+ * Generates a mapping from entity names to their corresponding schema objects.
115
+ *
116
+ * @param {CoreEntity[]} e The entities for which schema entries should be generated.
117
+ * @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
118
+ */
119
+ static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaElObj>;
120
+ /**
121
+ * Builds a JSON schema representation for an entity view that includes both the
122
+ * entity data and its related entity map.
123
+ *
124
+ * @param entity The primary entity used to construct the `dat` portion of the schema.
125
+ * @param entityMap The related entity map used to construct the `join_map` portion of the schema.
126
+ * @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
25
127
  */
26
- static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaEl>;
27
128
  static schemaFromEntityView<A extends CoreEntity, B extends CoreEntity>(entity: A, entityMap: B): SSchemaEl;
129
+ static editor<J extends CoreEntity>(e: J): ESchemaEditor<J>;
28
130
  }
@@ -5,31 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_1 = require("@grandlinex/core");
7
7
  const SUtilMap_js_1 = __importDefault(require("./SUtilMap.js"));
8
- function resolveDBType(dType) {
9
- switch (dType) {
10
- case 'int':
11
- case 'long':
12
- return 'integer';
13
- case 'double':
14
- case 'float':
15
- return 'number';
16
- case 'blob':
17
- return 'string';
18
- case 'string':
19
- case 'text':
20
- case 'uuid':
21
- return 'string';
22
- case 'boolean':
23
- return 'boolean';
24
- case 'date':
25
- return 'string';
26
- case 'json':
27
- return 'object';
28
- default:
29
- throw Error('TypeNotSupported');
30
- }
31
- }
8
+ const ESchemaEditor_js_1 = require("./ESchemaEditor.js");
32
9
  class SPathUtil {
10
+ /**
11
+ * Generates a default response mapping for the specified HTTP status types.
12
+ *
13
+ * @param {HttpStatusTypes[]} types - The HTTP status types for which default responses should be created.
14
+ * @return {SwaggerRPathConfResponse} An object mapping each provided status type to its default response definition. */
33
15
  static defaultResponse(...types) {
34
16
  const res = {};
35
17
  types.forEach((el) => {
@@ -37,6 +19,12 @@ class SPathUtil {
37
19
  });
38
20
  return res;
39
21
  }
22
+ /**
23
+ * Creates a request body definition for JSON content type using the provided schema.
24
+ *
25
+ * @param {SSchemaEl} schema - The JSON schema used for validating the request body.
26
+ * @return {SwaggerRPathReqBody} A Swagger path request body object specifying application/json content type with the provided schema.
27
+ */
40
28
  static jsonBody(schema) {
41
29
  return {
42
30
  content: {
@@ -46,6 +34,13 @@ class SPathUtil {
46
34
  },
47
35
  };
48
36
  }
37
+ /**
38
+ * Builds a Swagger request body for `multipart/form-data` requests.
39
+ *
40
+ * @param {SSchemaEl} [schema] Optional schema describing the form data.
41
+ * If omitted, a default schema with a single binary `file` field is provided.
42
+ * @return {SwaggerRPathReqBody} Swagger request body definition with
43
+ * `multipart/form-data` content and the supplied or default schema. */
49
44
  static formBody(schema) {
50
45
  return {
51
46
  content: {
@@ -64,6 +59,14 @@ class SPathUtil {
64
59
  },
65
60
  };
66
61
  }
62
+ /**
63
+ * Generates a Swagger content definition for the provided entity.
64
+ *
65
+ * @param {T} entity - The entity instance to derive the Swagger schema from.
66
+ * @param {boolean} [list] - When true, the schema will be wrapped in an array type, representing a list of entities.
67
+ *
68
+ * @returns {SwaggerContent|undefined} The Swagger content object for the entity, or `undefined` if the entity does not have a schema.
69
+ */
67
70
  static entityContent(entity, list) {
68
71
  const schema = this.schemaFromEntity(entity);
69
72
  if (!schema) {
@@ -85,6 +88,13 @@ class SPathUtil {
85
88
  },
86
89
  };
87
90
  }
91
+ /**
92
+ * @template T extends CoreEntity
93
+ * @param {T} entity - The entity instance for which to build the response configuration.
94
+ * @param {boolean} [list] - Indicates whether the response should represent a list of entities.
95
+ * @param {boolean} [create] - Indicates whether the response corresponds to a creation operation (status code 201); otherwise 200.
96
+ * @returns {SwaggerRPathConfResponse} The Swagger response configuration object containing the appropriate status code and content.
97
+ */
88
98
  static entityResponse(entity, list, create) {
89
99
  const code = create ? '201' : '200';
90
100
  const an = {};
@@ -94,9 +104,58 @@ class SPathUtil {
94
104
  };
95
105
  return an;
96
106
  }
107
+ /**
108
+ * Builds a JSON schema reference path for the given component name.
109
+ *
110
+ * @param {string} inp - The name of the schema component.
111
+ * @return {string} The JSON reference path formatted as `#/components/schemas/<inp>`.
112
+ */
97
113
  static schemaPath(inp) {
98
114
  return `#/components/schemas/${inp}`;
99
115
  }
116
+ /**
117
+ * Creates a Swagger request body definition that references a schema.
118
+ *
119
+ * @param {string | CoreEntity} $ref
120
+ * Either the string reference to a schema or a `CoreEntity` instance whose
121
+ * class name will be used to build the reference path.
122
+ * @param {boolean} list
123
+ * If true, the referenced schema is wrapped in an array; otherwise the
124
+ * schema is used directly.
125
+ * @returns {SwaggerRPathReqBody}
126
+ * The request body object containing the appropriate content and schema
127
+ * configuration.
128
+ */
129
+ static refRequest($ref, list) {
130
+ const t = typeof $ref === 'string'
131
+ ? { $ref }
132
+ : {
133
+ $ref: this.schemaPath(core_1.XUtil.getEntityNames($ref).className),
134
+ };
135
+ if (list) {
136
+ return {
137
+ content: {
138
+ 'application/json': {
139
+ schema: {
140
+ type: 'array',
141
+ items: t,
142
+ },
143
+ },
144
+ },
145
+ };
146
+ }
147
+ return {
148
+ content: {
149
+ 'application/json': {
150
+ schema: t,
151
+ },
152
+ },
153
+ };
154
+ }
155
+ /**
156
+ * Creates a Swagger response configuration for a given HTTP status code.
157
+ *
158
+ * @param {HttpStatusTypes} code - The primary HTTP status code for */
100
159
  static refResponse(code, $ref, list, ...addCodes) {
101
160
  const an = {
102
161
  ...this.defaultResponse(...addCodes),
@@ -131,6 +190,15 @@ class SPathUtil {
131
190
  }
132
191
  return an;
133
192
  }
193
+ /**
194
+ * Builds a Swagger response configuration object for a given HTTP status code and schema.
195
+ *
196
+ * @param {HttpStatusTypes} code - The primary HTTP status code for the response.
197
+ * @param {SSchemaEl} schema - The JSON schema definition for the response body.
198
+ * @param {boolean} list - If true, the schema is wrapped in an array for list responses.
199
+ * @param {...HttpStatusTypes} addCodes - Additional HTTP status codes for default responses.
200
+ * @return {SwaggerRPathConfResponse} The constructed response configuration object.
201
+ */
134
202
  static jsonResponse(code, schema, list, ...addCodes) {
135
203
  const an = {
136
204
  ...this.defaultResponse(...addCodes),
@@ -160,30 +228,33 @@ class SPathUtil {
160
228
  }
161
229
  return an;
162
230
  }
231
+ /**
232
+ * Generates a JSON schema representation from a CoreEntity instance.
233
+ *
234
+ * This method inspects the entity's metadata to construct a schema object
235
+ * describing the entity's shape. The resulting schema contains:
236
+ * - `type`: always `"object"`.
237
+ * - `description`: a string indicating the entity name.
238
+ * - `required`: an array of property names that are defined on the entity.
239
+ * - `properties`: an object mapping each property name to an object that
240
+ * includes the resolved database type and its nullability.
241
+ *
242
+ * If no metadata is found for the provided entity, the method returns `undefined`.
243
+ *
244
+ * @param {T} entity - The entity instance for which to create a schema.
245
+ * @returns {SSchemaElObj | undefined} The generated schema object, or `undefined`
246
+ * if the entity's metadata could not be retrieved.
247
+ * @deprecated Use {@link ESchemaEditor.schemaFromEntity} instead.
248
+ */
163
249
  static schemaFromEntity(entity) {
164
- const schema = {
165
- type: 'object',
166
- properties: {},
167
- };
168
- const meta = (0, core_1.getEntityMeta)(entity);
169
- if (!meta) {
170
- return undefined;
171
- }
172
- schema.description = `Entity: ${meta.name}`;
173
- schema.required = [];
174
- const keys = Object.keys(entity);
175
- keys.forEach((k) => {
176
- const cMeta = (0, core_1.getColumnMeta)(entity, k);
177
- if (cMeta && schema.properties) {
178
- schema.required.push(k);
179
- schema.properties[k] = {
180
- type: resolveDBType(cMeta.dataType),
181
- nullable: cMeta.canBeNull,
182
- };
183
- }
184
- });
185
- return schema;
250
+ return ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity);
186
251
  }
252
+ /**
253
+ * 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.
254
+ *
255
+ * @param {T} entity - The entity instance for which to generate the content schema. The generic type `T` must extend {@link CoreEntity}.
256
+ * @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.
257
+ */
187
258
  static contentSchemaFromEntity(entity) {
188
259
  const meta = (0, core_1.getEntityMeta)(entity);
189
260
  if (!meta) {
@@ -193,25 +264,35 @@ class SPathUtil {
193
264
  description: `Entity: ${meta.name}`,
194
265
  content: {
195
266
  'application/json': {
196
- schema: this.schemaFromEntity(entity),
267
+ schema: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity),
197
268
  },
198
269
  },
199
270
  };
200
271
  }
201
272
  /**
202
- * generate global schema
203
- * @param e
273
+ * Generates a mapping from entity names to their corresponding schema objects.
274
+ *
275
+ * @param {CoreEntity[]} e The entities for which schema entries should be generated.
276
+ * @return {SKey<SSchemaEl>} An object whose keys are entity names and values are the schemas derived from those entities.
204
277
  */
205
278
  static schemaEntryGen(...e) {
206
279
  const out = {};
207
280
  e.forEach((el) => {
208
281
  const meta = (0, core_1.getEntityMeta)(el);
209
282
  if (meta) {
210
- out[meta.name] = SPathUtil.schemaFromEntity(el);
283
+ out[meta.name] = ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(el);
211
284
  }
212
285
  });
213
286
  return out;
214
287
  }
288
+ /**
289
+ * Builds a JSON schema representation for an entity view that includes both the
290
+ * entity data and its related entity map.
291
+ *
292
+ * @param entity The primary entity used to construct the `dat` portion of the schema.
293
+ * @param entityMap The related entity map used to construct the `join_map` portion of the schema.
294
+ * @returns A {@link SSchemaEl} object schema with properties `i`, `dat`, and `join_map`.
295
+ */
215
296
  static schemaFromEntityView(entity, entityMap) {
216
297
  return {
217
298
  type: 'object',
@@ -219,10 +300,13 @@ class SPathUtil {
219
300
  i: {
220
301
  type: 'integer',
221
302
  },
222
- dat: this.schemaFromEntity(entity),
223
- join_map: this.schemaFromEntity(entityMap),
303
+ dat: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entity),
304
+ join_map: ESchemaEditor_js_1.ESchemaEditor.schemaFromEntity(entityMap),
224
305
  },
225
306
  };
226
307
  }
308
+ static editor(e) {
309
+ return ESchemaEditor_js_1.ESchemaEditor.fromEntity(e);
310
+ }
227
311
  }
228
312
  exports.default = SPathUtil;
@@ -1,11 +1,27 @@
1
- import { ObjectLike } from '@grandlinex/core';
1
+ import { CoreLogChannel, ObjectLike } from '@grandlinex/core';
2
2
  import { Server } from 'net';
3
3
  import { MergeInputType, SwaggerConfig, SwaggerRPath } from './Meta/SwaggerTypes.js';
4
4
  import { RouteData } from './annotation/index.js';
5
5
  export default class SwaggerUtil {
6
+ static logger: CoreLogChannel | null;
7
+ static getLogger(): CoreLogChannel;
6
8
  static writeMeta(conf: SwaggerConfig, kind: 'JSON' | 'YAML', path?: string): void;
7
9
  static readMeta(path: string): any;
8
- static serveMeta(conf: SwaggerConfig, port?: number, auth?: string): Promise<Server | null>;
10
+ /**
11
+ * Serves a meta page for Swagger UI or rapi-doc.
12
+ *
13
+ * @param {SwaggerConfig} conf The swagger configuration to expose via `/spec`.
14
+ * @param {Object} [option] Options for serving the meta page.
15
+ * @param {'swagger-ui'|'rapi-doc'} [option.type='swagger-ui'] The type of UI to serve.
16
+ * @param {number} [option.port] The port to listen on. Defaults to 9000.
17
+ * @param {string} [option.auth] Optional authentication key appended to the URL.
18
+ * @returns {Promise<Server|null>} A promise that resolves with the created server instance or null.
19
+ */
20
+ static serveMeta(conf: SwaggerConfig, option?: {
21
+ type?: 'swagger-ui' | 'rapi-doc';
22
+ port?: number;
23
+ auth?: string;
24
+ }): Promise<Server | null>;
9
25
  static metaExtractor(root: ObjectLike, npmPackageVersion: boolean, ...path: ObjectLike[]): SwaggerConfig | undefined;
10
26
  static routeToSwaggerPath(route: RouteData): SwaggerRPath;
11
27
  static merge(root: SwaggerConfig, data: MergeInputType[]): SwaggerConfig;