@grandlinex/swagger-mate 0.30.8

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 (89) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +137 -0
  3. package/dist/cjs/PathHelp.d.ts +2 -0
  4. package/dist/cjs/PathHelp.js +47 -0
  5. package/dist/cjs/Swagger/Client/ClientUtil.d.ts +59 -0
  6. package/dist/cjs/Swagger/Client/ClientUtil.js +208 -0
  7. package/dist/cjs/Swagger/Client/FunctionProps.d.ts +4 -0
  8. package/dist/cjs/Swagger/Client/FunctionProps.js +60 -0
  9. package/dist/cjs/Swagger/Client/FunctionTemplate.d.ts +13 -0
  10. package/dist/cjs/Swagger/Client/FunctionTemplate.js +46 -0
  11. package/dist/cjs/Swagger/Client/InterfaceTemplate.d.ts +3 -0
  12. package/dist/cjs/Swagger/Client/InterfaceTemplate.js +14 -0
  13. package/dist/cjs/Swagger/Client/SwaggerClient.d.ts +4 -0
  14. package/dist/cjs/Swagger/Client/SwaggerClient.js +197 -0
  15. package/dist/cjs/Swagger/Meta/Swagger.d.ts +10 -0
  16. package/dist/cjs/Swagger/Meta/Swagger.js +40 -0
  17. package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +107 -0
  18. package/dist/cjs/Swagger/Meta/SwaggerTypes.js +9 -0
  19. package/dist/cjs/Swagger/Meta/SwaggerTypesStatic.d.ts +4 -0
  20. package/dist/cjs/Swagger/Meta/SwaggerTypesStatic.js +3 -0
  21. package/dist/cjs/Swagger/Path/SPathUtil.d.ts +28 -0
  22. package/dist/cjs/Swagger/Path/SPathUtil.js +228 -0
  23. package/dist/cjs/Swagger/Path/SUtilMap.d.ts +192 -0
  24. package/dist/cjs/Swagger/Path/SUtilMap.js +194 -0
  25. package/dist/cjs/Swagger/SwaggerUtil.d.ts +12 -0
  26. package/dist/cjs/Swagger/SwaggerUtil.js +195 -0
  27. package/dist/cjs/Swagger/debug/BaseCon.d.ts +68 -0
  28. package/dist/cjs/Swagger/debug/BaseCon.js +277 -0
  29. package/dist/cjs/Swagger/debug/FetchCon.d.ts +3 -0
  30. package/dist/cjs/Swagger/debug/FetchCon.js +79 -0
  31. package/dist/cjs/Swagger/debug/NodeCon.d.ts +3 -0
  32. package/dist/cjs/Swagger/debug/NodeCon.js +142 -0
  33. package/dist/cjs/Swagger/debug/index.d.ts +5 -0
  34. package/dist/cjs/Swagger/debug/index.js +27 -0
  35. package/dist/cjs/cli.d.ts +5 -0
  36. package/dist/cjs/cli.js +89 -0
  37. package/dist/cjs/index.d.ts +8 -0
  38. package/dist/cjs/index.js +30 -0
  39. package/dist/cjs/package.json +3 -0
  40. package/dist/mjs/PathHelp.d.ts +2 -0
  41. package/dist/mjs/PathHelp.js +16 -0
  42. package/dist/mjs/Swagger/Client/ClientUtil.d.ts +59 -0
  43. package/dist/mjs/Swagger/Client/ClientUtil.js +195 -0
  44. package/dist/mjs/Swagger/Client/FunctionProps.d.ts +4 -0
  45. package/dist/mjs/Swagger/Client/FunctionProps.js +58 -0
  46. package/dist/mjs/Swagger/Client/FunctionTemplate.d.ts +13 -0
  47. package/dist/mjs/Swagger/Client/FunctionTemplate.js +40 -0
  48. package/dist/mjs/Swagger/Client/InterfaceTemplate.d.ts +3 -0
  49. package/dist/mjs/Swagger/Client/InterfaceTemplate.js +13 -0
  50. package/dist/mjs/Swagger/Client/SwaggerClient.d.ts +4 -0
  51. package/dist/mjs/Swagger/Client/SwaggerClient.js +168 -0
  52. package/dist/mjs/Swagger/Meta/Swagger.d.ts +10 -0
  53. package/dist/mjs/Swagger/Meta/Swagger.js +32 -0
  54. package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +107 -0
  55. package/dist/mjs/Swagger/Meta/SwaggerTypes.js +5 -0
  56. package/dist/mjs/Swagger/Meta/SwaggerTypesStatic.d.ts +4 -0
  57. package/dist/mjs/Swagger/Meta/SwaggerTypesStatic.js +2 -0
  58. package/dist/mjs/Swagger/Path/SPathUtil.d.ts +28 -0
  59. package/dist/mjs/Swagger/Path/SPathUtil.js +222 -0
  60. package/dist/mjs/Swagger/Path/SUtilMap.d.ts +192 -0
  61. package/dist/mjs/Swagger/Path/SUtilMap.js +192 -0
  62. package/dist/mjs/Swagger/SwaggerUtil.d.ts +12 -0
  63. package/dist/mjs/Swagger/SwaggerUtil.js +166 -0
  64. package/dist/mjs/Swagger/debug/BaseCon.d.ts +68 -0
  65. package/dist/mjs/Swagger/debug/BaseCon.js +269 -0
  66. package/dist/mjs/Swagger/debug/FetchCon.d.ts +3 -0
  67. package/dist/mjs/Swagger/debug/FetchCon.js +77 -0
  68. package/dist/mjs/Swagger/debug/NodeCon.d.ts +3 -0
  69. package/dist/mjs/Swagger/debug/NodeCon.js +114 -0
  70. package/dist/mjs/Swagger/debug/index.d.ts +5 -0
  71. package/dist/mjs/Swagger/debug/index.js +5 -0
  72. package/dist/mjs/cli.d.ts +5 -0
  73. package/dist/mjs/cli.js +61 -0
  74. package/dist/mjs/index.d.ts +8 -0
  75. package/dist/mjs/index.js +8 -0
  76. package/dist/mjs/package.json +3 -0
  77. package/package.json +77 -0
  78. package/res/html/index.html +69 -0
  79. package/res/html/swagger-ui-bundle.js +3 -0
  80. package/res/html/swagger-ui-standalone-preset.js +3 -0
  81. package/res/html/swagger-ui.css +3 -0
  82. package/res/templates/class/ApiCon.ts +11 -0
  83. package/res/templates/class/AxiosCon.ts +49 -0
  84. package/res/templates/class/BaseCon.ts +377 -0
  85. package/res/templates/class/CApiCon.ts +11 -0
  86. package/res/templates/class/FetchCon.ts +93 -0
  87. package/res/templates/class/IApiCon.ts +10 -0
  88. package/res/templates/class/NodeCon.ts +164 -0
  89. package/res/templates/class/index.ts +18 -0
@@ -0,0 +1,107 @@
1
+ import { HttpStatusTypes, SDataFormat, SDataType, SMediaType } from './SwaggerTypesStatic.js';
2
+ export type SwaggerPathInput = {
3
+ path: SwaggerRPath;
4
+ prefix?: string;
5
+ };
6
+ export type SwaggerRRef = {
7
+ $ref: string;
8
+ };
9
+ export declare function isSwaggerRef(o: unknown): o is SwaggerRRef;
10
+ export type SwaggerRPathConfResponseDef = SwaggerCompResponse | SwaggerRRef;
11
+ export type SwaggerRPath = SKey<SwaggerRPathTypes>;
12
+ export type SwaggerRPathConfResponse = {
13
+ [K in HttpStatusTypes]?: SwaggerRPathConfResponseDef;
14
+ };
15
+ export interface SwaggerRPathReqBody {
16
+ content?: SwaggerContent;
17
+ description?: string;
18
+ }
19
+ export interface SwaggerRPathParameter {
20
+ content?: SwaggerContent;
21
+ description?: string;
22
+ name: string;
23
+ required: boolean;
24
+ schema?: SSchemaEl;
25
+ in?: 'query' | 'header' | 'path';
26
+ }
27
+ export interface SwaggerRPathConf {
28
+ responses?: SwaggerRPathConfResponse;
29
+ description?: string;
30
+ summary?: string;
31
+ tags?: string[];
32
+ operationId?: string;
33
+ requestBody?: SwaggerRPathReqBody;
34
+ parameters?: SwaggerRPathParameter[];
35
+ }
36
+ export interface SwaggerRPathTypes {
37
+ get?: SwaggerRPathConf;
38
+ post?: SwaggerRPathConf;
39
+ patch?: SwaggerRPathConf;
40
+ delete?: SwaggerRPathConf;
41
+ update?: SwaggerRPathConf;
42
+ }
43
+ export interface SwaggerRInfoLicence {
44
+ name: string;
45
+ url?: string;
46
+ }
47
+ export interface SwaggerRServer {
48
+ url: string;
49
+ description?: string;
50
+ variables?: string | string[];
51
+ }
52
+ export interface SwaggerRInfo {
53
+ title: string;
54
+ description?: string;
55
+ termsOfService?: string;
56
+ version: string;
57
+ license?: SwaggerRInfoLicence;
58
+ }
59
+ export type SSchemaEl = {
60
+ type: SDataType;
61
+ example?: string;
62
+ format?: SDataFormat;
63
+ description?: string;
64
+ properties?: {
65
+ [key: string]: SSchemaEl;
66
+ };
67
+ items?: SSchemaEl;
68
+ required?: string[];
69
+ enum?: string[];
70
+ } | SwaggerRRef;
71
+ export type SwaggerContent = {
72
+ [K in SMediaType]?: {
73
+ schema: SSchemaEl;
74
+ };
75
+ };
76
+ export type SwaggerCompResponse = {
77
+ description?: string;
78
+ content?: SwaggerContent;
79
+ };
80
+ export type SwaggerComSecuritySchemes = {
81
+ in?: 'query' | 'header' | 'cookie';
82
+ scheme: string;
83
+ type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
84
+ bearerFormat?: string | 'JWT';
85
+ description?: string;
86
+ };
87
+ export interface SKey<T> {
88
+ [key: string]: T;
89
+ }
90
+ export interface SwaggerConfigComponents {
91
+ securitySchemes?: SKey<SwaggerComSecuritySchemes>;
92
+ responses?: SKey<SwaggerCompResponse>;
93
+ schemas?: SKey<SSchemaEl>;
94
+ }
95
+ export interface SwaggerConfig {
96
+ openapi: string;
97
+ info: SwaggerRInfo;
98
+ servers?: SwaggerRServer[];
99
+ paths: SwaggerRPath;
100
+ security?: [SKey<any[]>];
101
+ tags?: string[];
102
+ components?: SwaggerConfigComponents;
103
+ }
104
+ export interface MergeInputType {
105
+ path: SwaggerPathInput | undefined;
106
+ comp: SwaggerConfigComponents | undefined;
107
+ }
@@ -0,0 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ export function isSwaggerRef(o) {
3
+ const a = o;
4
+ return typeof a === 'object' && !!a?.$ref;
5
+ }
@@ -0,0 +1,4 @@
1
+ export type SMediaType = 'text/plain; charset=utf-8' | 'application/json' | 'multipart/form-data';
2
+ export type SDataFormat = 'binary' | 'base64' | 'uuid';
3
+ export type SDataType = 'integer' | 'number' | 'string' | 'boolean' | 'array' | 'object';
4
+ export type HttpStatusTypes = '100' | '101' | '102' | '103' | '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226' | '300' | '301' | '302' | '303' | '304' | '305' | '306' | '307' | '308' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '421' | '422' | '423' | '424' | '425' | '426' | '428' | '429' | '431' | '451' | '500' | '501' | '502' | '503' | '504' | '505' | '506' | '507' | '508' | '510' | '511';
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ export {};
@@ -0,0 +1,28 @@
1
+ import { CoreEntity } from '@grandlinex/core';
2
+ import { HttpStatusTypes } from '../Meta/SwaggerTypesStatic.js';
3
+ import { SKey, SSchemaEl, SwaggerContent, SwaggerRPathConfResponse, SwaggerRPathReqBody } from '../Meta/SwaggerTypes.js';
4
+ export default class SPathUtil {
5
+ static defaultResponse(...types: HttpStatusTypes[]): SwaggerRPathConfResponse;
6
+ static jsonBody(schema: SSchemaEl): SwaggerRPathReqBody;
7
+ static formBody(schema?: SSchemaEl): SwaggerRPathReqBody;
8
+ static entityContent<T extends CoreEntity>(entity: T, list?: boolean): SwaggerContent | undefined;
9
+ static entityResponse<T extends CoreEntity>(entity: T, list?: boolean, create?: boolean): SwaggerRPathConfResponse;
10
+ static schemaPath(inp: string): string;
11
+ static refResponse(code: HttpStatusTypes, $ref: string | CoreEntity, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
12
+ static jsonResponse(code: HttpStatusTypes, schema: SSchemaEl, list: boolean, ...addCodes: HttpStatusTypes[]): SwaggerRPathConfResponse;
13
+ static schemaFromEntity<T extends CoreEntity>(entity: T): SSchemaEl | undefined;
14
+ static contentSchemaFromEntity<T extends CoreEntity>(entity: T): {
15
+ description: string;
16
+ content: {
17
+ 'application/json': {
18
+ schema: SSchemaEl;
19
+ };
20
+ };
21
+ } | undefined;
22
+ /**
23
+ * generate global schema
24
+ * @param e
25
+ */
26
+ static schemaEntryGen(...e: CoreEntity[]): SKey<SSchemaEl>;
27
+ static schemaFromEntityView<A extends CoreEntity, B extends CoreEntity>(entity: A, entityMap: B): SSchemaEl;
28
+ }
@@ -0,0 +1,222 @@
1
+ import { getEntityMeta, XUtil, getColumnMeta, } from '@grandlinex/core';
2
+ import map from './SUtilMap.js';
3
+ function resolveDBType(dType) {
4
+ switch (dType) {
5
+ case 'int':
6
+ return 'integer';
7
+ case 'double':
8
+ case 'float':
9
+ return 'number';
10
+ case 'blob':
11
+ return 'string';
12
+ case 'string':
13
+ case 'text':
14
+ case 'uuid':
15
+ return 'string';
16
+ case 'boolean':
17
+ return 'boolean';
18
+ case 'date':
19
+ return 'string';
20
+ case 'json':
21
+ return 'object';
22
+ default:
23
+ throw Error('TypeNotSupported');
24
+ }
25
+ }
26
+ export default class SPathUtil {
27
+ static defaultResponse(...types) {
28
+ const res = {};
29
+ types.forEach((el) => {
30
+ res[el] = map[el];
31
+ });
32
+ return res;
33
+ }
34
+ static jsonBody(schema) {
35
+ return {
36
+ content: {
37
+ 'application/json': {
38
+ schema,
39
+ },
40
+ },
41
+ };
42
+ }
43
+ static formBody(schema) {
44
+ return {
45
+ content: {
46
+ 'multipart/form-data': {
47
+ schema: schema || {
48
+ type: 'object',
49
+ properties: {
50
+ file: {
51
+ type: 'string',
52
+ format: 'binary',
53
+ description: 'File to upload',
54
+ },
55
+ },
56
+ },
57
+ },
58
+ },
59
+ };
60
+ }
61
+ static entityContent(entity, list) {
62
+ const schema = this.schemaFromEntity(entity);
63
+ if (!schema) {
64
+ return undefined;
65
+ }
66
+ if (list) {
67
+ return {
68
+ 'application/json': {
69
+ schema: {
70
+ type: 'array',
71
+ items: schema,
72
+ },
73
+ },
74
+ };
75
+ }
76
+ return {
77
+ 'application/json': {
78
+ schema,
79
+ },
80
+ };
81
+ }
82
+ static entityResponse(entity, list, create) {
83
+ const code = create ? '201' : '200';
84
+ const an = {};
85
+ an[code] = {
86
+ description: map[code].description,
87
+ content: this.entityContent(entity, list),
88
+ };
89
+ return an;
90
+ }
91
+ static schemaPath(inp) {
92
+ return `#/components/schemas/${inp}`;
93
+ }
94
+ static refResponse(code, $ref, list, ...addCodes) {
95
+ const an = {
96
+ ...this.defaultResponse(...addCodes),
97
+ };
98
+ const t = typeof $ref === 'string'
99
+ ? { $ref }
100
+ : {
101
+ $ref: this.schemaPath(XUtil.getEntityNames($ref).className),
102
+ };
103
+ if (list) {
104
+ an[code] = {
105
+ description: map[code].description,
106
+ content: {
107
+ 'application/json': {
108
+ schema: {
109
+ type: 'array',
110
+ items: t,
111
+ },
112
+ },
113
+ },
114
+ };
115
+ }
116
+ else {
117
+ an[code] = {
118
+ description: map[code].description,
119
+ content: {
120
+ 'application/json': {
121
+ schema: t,
122
+ },
123
+ },
124
+ };
125
+ }
126
+ return an;
127
+ }
128
+ static jsonResponse(code, schema, list, ...addCodes) {
129
+ const an = {
130
+ ...this.defaultResponse(...addCodes),
131
+ };
132
+ if (list) {
133
+ an[code] = {
134
+ description: map[code].description,
135
+ content: {
136
+ 'application/json': {
137
+ schema: {
138
+ type: 'array',
139
+ items: schema,
140
+ },
141
+ },
142
+ },
143
+ };
144
+ }
145
+ else {
146
+ an[code] = {
147
+ description: map[code].description,
148
+ content: {
149
+ 'application/json': {
150
+ schema,
151
+ },
152
+ },
153
+ };
154
+ }
155
+ return an;
156
+ }
157
+ static schemaFromEntity(entity) {
158
+ const schema = {
159
+ type: 'object',
160
+ properties: {},
161
+ };
162
+ const meta = getEntityMeta(entity);
163
+ if (!meta) {
164
+ return undefined;
165
+ }
166
+ schema.description = `Entity: ${meta.name}`;
167
+ schema.required = [];
168
+ const keys = Object.keys(entity);
169
+ keys.forEach((k) => {
170
+ const cMeta = getColumnMeta(entity, k);
171
+ if (cMeta && schema.properties) {
172
+ if (!cMeta.canBeNull) {
173
+ schema.required?.push(k);
174
+ }
175
+ schema.properties[k] = {
176
+ type: resolveDBType(cMeta.dataType),
177
+ };
178
+ }
179
+ });
180
+ return schema;
181
+ }
182
+ static contentSchemaFromEntity(entity) {
183
+ const meta = getEntityMeta(entity);
184
+ if (!meta) {
185
+ return undefined;
186
+ }
187
+ return {
188
+ description: `Entity: ${meta.name}`,
189
+ content: {
190
+ 'application/json': {
191
+ schema: this.schemaFromEntity(entity),
192
+ },
193
+ },
194
+ };
195
+ }
196
+ /**
197
+ * generate global schema
198
+ * @param e
199
+ */
200
+ static schemaEntryGen(...e) {
201
+ const out = {};
202
+ e.forEach((el) => {
203
+ const meta = getEntityMeta(el);
204
+ if (meta) {
205
+ out[meta.name] = SPathUtil.schemaFromEntity(el);
206
+ }
207
+ });
208
+ return out;
209
+ }
210
+ static schemaFromEntityView(entity, entityMap) {
211
+ return {
212
+ type: 'object',
213
+ properties: {
214
+ i: {
215
+ type: 'integer',
216
+ },
217
+ dat: this.schemaFromEntity(entity),
218
+ join_map: this.schemaFromEntity(entityMap),
219
+ },
220
+ };
221
+ }
222
+ }
@@ -0,0 +1,192 @@
1
+ declare const DefaultMap: {
2
+ '100': {
3
+ description: string;
4
+ };
5
+ '101': {
6
+ description: string;
7
+ };
8
+ '102': {
9
+ description: string;
10
+ };
11
+ '103': {
12
+ description: string;
13
+ };
14
+ '200': {
15
+ description: string;
16
+ };
17
+ '201': {
18
+ description: string;
19
+ };
20
+ '202': {
21
+ description: string;
22
+ };
23
+ '203': {
24
+ description: string;
25
+ };
26
+ '204': {
27
+ description: string;
28
+ };
29
+ '205': {
30
+ description: string;
31
+ };
32
+ '206': {
33
+ description: string;
34
+ };
35
+ '207': {
36
+ description: string;
37
+ };
38
+ '208': {
39
+ description: string;
40
+ };
41
+ '226': {
42
+ description: string;
43
+ };
44
+ '300': {
45
+ description: string;
46
+ };
47
+ '301': {
48
+ description: string;
49
+ };
50
+ '302': {
51
+ description: string;
52
+ };
53
+ '303': {
54
+ description: string;
55
+ };
56
+ '304': {
57
+ description: string;
58
+ };
59
+ '305': {
60
+ description: string;
61
+ };
62
+ '306': {
63
+ description: string;
64
+ };
65
+ '307': {
66
+ description: string;
67
+ };
68
+ '308': {
69
+ description: string;
70
+ };
71
+ '400': {
72
+ description: string;
73
+ };
74
+ '401': {
75
+ description: string;
76
+ };
77
+ '402': {
78
+ description: string;
79
+ };
80
+ '403': {
81
+ description: string;
82
+ };
83
+ '404': {
84
+ description: string;
85
+ };
86
+ '405': {
87
+ description: string;
88
+ };
89
+ '406': {
90
+ description: string;
91
+ };
92
+ '407': {
93
+ description: string;
94
+ };
95
+ '408': {
96
+ description: string;
97
+ };
98
+ '409': {
99
+ description: string;
100
+ };
101
+ '410': {
102
+ description: string;
103
+ };
104
+ '411': {
105
+ description: string;
106
+ };
107
+ '412': {
108
+ description: string;
109
+ };
110
+ '413': {
111
+ description: string;
112
+ };
113
+ '414': {
114
+ description: string;
115
+ };
116
+ '415': {
117
+ description: string;
118
+ };
119
+ '416': {
120
+ description: string;
121
+ };
122
+ '417': {
123
+ description: string;
124
+ };
125
+ '418': {
126
+ description: string;
127
+ };
128
+ '421': {
129
+ description: string;
130
+ };
131
+ '422': {
132
+ description: string;
133
+ };
134
+ '423': {
135
+ description: string;
136
+ };
137
+ '424': {
138
+ description: string;
139
+ };
140
+ '425': {
141
+ description: string;
142
+ };
143
+ '426': {
144
+ description: string;
145
+ };
146
+ '428': {
147
+ description: string;
148
+ };
149
+ '429': {
150
+ description: string;
151
+ };
152
+ '431': {
153
+ description: string;
154
+ };
155
+ '451': {
156
+ description: string;
157
+ };
158
+ '500': {
159
+ description: string;
160
+ };
161
+ '501': {
162
+ description: string;
163
+ };
164
+ '502': {
165
+ description: string;
166
+ };
167
+ '503': {
168
+ description: string;
169
+ };
170
+ '504': {
171
+ description: string;
172
+ };
173
+ '505': {
174
+ description: string;
175
+ };
176
+ '506': {
177
+ description: string;
178
+ };
179
+ '507': {
180
+ description: string;
181
+ };
182
+ '508': {
183
+ description: string;
184
+ };
185
+ '510': {
186
+ description: string;
187
+ };
188
+ '511': {
189
+ description: string;
190
+ };
191
+ };
192
+ export default DefaultMap;