@innet/server 2.0.0-alpha.3 → 2.0.0-alpha.5
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.
- package/README.md +34 -8
- package/example/requests/index.d.ts +1 -1
- package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
- package/example/requests/todo/AddTodo/index.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
- package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
- package/example/requests/todo/EditTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
- package/example/requests/todo/GetTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
- package/example/requests/todo/GetTodos/index.d.ts +1 -0
- package/example/requests/todo/index.d.ts +5 -0
- package/example/requests/todo/todos.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
- package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
- package/example/schemas/app/index.d.ts +1 -0
- package/example/schemas/index.d.ts +1 -3
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
- package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
- package/example/schemas/todo/index.d.ts +1 -0
- package/example/tags/Todo/Todo.d.ts +1 -0
- package/example/tags/Todo/index.d.ts +1 -0
- package/example/tags/index.d.ts +1 -1
- package/hooks/useComponentName/useComponentName.d.ts +1 -1
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -2
- package/plugins/main/response/response.d.ts +1 -1
- package/plugins/main/response/response.es6.js +1 -1
- package/plugins/main/response/response.js +1 -1
- package/plugins/utils/dts/dts.d.ts +1 -2
- package/plugins/utils/dts/dts.es6.js +6 -25
- package/plugins/utils/dts/dts.js +5 -29
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +102 -0
- package/utils/generateTypes/generateTypes.js +107 -0
- package/utils/generateTypes/generateTypes.test.d.ts +1 -0
- package/utils/generateTypes/index.d.ts +1 -0
- package/utils/generateTypes/index.es6.js +1 -0
- package/utils/generateTypes/index.js +10 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
- package/example/requests/partners/EditPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
- package/example/requests/partners/GetPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
- package/example/requests/partners/GetPartners/index.d.ts +0 -1
- package/example/requests/partners/index.d.ts +0 -3
- package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
- package/example/schemas/address/AddressSchema/index.d.ts +0 -1
- package/example/schemas/address/index.d.ts +0 -1
- package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
- package/example/schemas/location/LocationSchema/index.d.ts +0 -1
- package/example/schemas/location/index.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/index.d.ts +0 -2
- package/example/tags/Partner/Partner.d.ts +0 -1
- package/example/tags/Partner/index.d.ts +0 -1
package/README.md
CHANGED
|
@@ -396,22 +396,29 @@ export default (
|
|
|
396
396
|
)
|
|
397
397
|
```
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
|
|
399
|
+
You do not need to import types, use `Api` namespace everywhere.
|
|
401
400
|
Here is an example of generated types usage.
|
|
402
401
|
|
|
403
|
-
*src/GetPartner.tsx*
|
|
404
402
|
```typescript jsx
|
|
405
403
|
import { useParams } from '@innet/server'
|
|
406
404
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
405
|
+
import { todos } from '../todos'
|
|
406
|
+
|
|
407
|
+
export function DeleteTodo () {
|
|
408
|
+
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
409
|
+
|
|
410
|
+
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
411
|
+
|
|
412
|
+
if (todoIndex === -1) {
|
|
413
|
+
return <error code='todoNotFound' status={404} />
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
todos.splice(todoIndex, 1)
|
|
417
|
+
|
|
418
|
+
return <success />
|
|
410
419
|
}
|
|
411
420
|
```
|
|
412
421
|
|
|
413
|
-
You do not need to import types, they generate as namespaces.
|
|
414
|
-
|
|
415
422
|
## API Info
|
|
416
423
|
|
|
417
424
|
The API information elements are here.
|
|
@@ -3319,6 +3326,7 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3319
3326
|
[useParams](#useparams)
|
|
3320
3327
|
[useSearch](#usesearch)
|
|
3321
3328
|
[useBody](#usebody)
|
|
3329
|
+
[useComponentName](#usecomponentname)
|
|
3322
3330
|
|
|
3323
3331
|
---
|
|
3324
3332
|
|
|
@@ -3496,6 +3504,24 @@ export function Component () {
|
|
|
3496
3504
|
}
|
|
3497
3505
|
```
|
|
3498
3506
|
|
|
3507
|
+
### useComponentName
|
|
3508
|
+
|
|
3509
|
+
[← back](#hooks)
|
|
3510
|
+
|
|
3511
|
+
This hook returns name of current component.
|
|
3512
|
+
|
|
3513
|
+
*src/Component.tsx*
|
|
3514
|
+
```typescript jsx
|
|
3515
|
+
import { useComponentName } from '@innet/sever'
|
|
3516
|
+
|
|
3517
|
+
export function Component () {
|
|
3518
|
+
// returns this ^-------^
|
|
3519
|
+
const name = useComponentName()
|
|
3520
|
+
|
|
3521
|
+
return <success>{{ name }}</success>
|
|
3522
|
+
}
|
|
3523
|
+
```
|
|
3524
|
+
|
|
3499
3525
|
## Issues
|
|
3500
3526
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|
|
3501
3527
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './todo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AddTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DeleteTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DeleteTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function EditTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function GetTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GetTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function GetTodos(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GetTodos';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const todos: Api.Schemas.TodoSchema[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ListQueryParams(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ListQueryParams';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TodoSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TodoSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Todo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Todo';
|
package/example/tags/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './Todo';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useComponentName():
|
|
1
|
+
export declare function useComponentName(): string;
|
package/index.es6.js
CHANGED
|
@@ -81,6 +81,7 @@ export { maxBin } from './utils/rules/maxBin/maxBin.es6.js';
|
|
|
81
81
|
export { binaryAccept } from './utils/rules/binaryAccept/binaryAccept.es6.js';
|
|
82
82
|
export { JSONString } from './utils/JSONString/JSONString.es6.js';
|
|
83
83
|
export { Bin } from './utils/FileData/Bin.es6.js';
|
|
84
|
+
export { generateSchemaTypes, generateTypes } from './utils/generateTypes/generateTypes.es6.js';
|
|
84
85
|
export { serverContext, useServer } from './hooks/useServer/useServer.es6.js';
|
|
85
86
|
export { apiContext, useApi } from './hooks/useApi/useApi.es6.js';
|
|
86
87
|
export { hostContext, useHost } from './hooks/useHost/useHost.es6.js';
|
package/index.js
CHANGED
|
@@ -85,6 +85,7 @@ var maxBin = require('./utils/rules/maxBin/maxBin.js');
|
|
|
85
85
|
var binaryAccept = require('./utils/rules/binaryAccept/binaryAccept.js');
|
|
86
86
|
var JSONString = require('./utils/JSONString/JSONString.js');
|
|
87
87
|
var Bin = require('./utils/FileData/Bin.js');
|
|
88
|
+
var generateTypes = require('./utils/generateTypes/generateTypes.js');
|
|
88
89
|
var useServer = require('./hooks/useServer/useServer.js');
|
|
89
90
|
var useApi = require('./hooks/useApi/useApi.js');
|
|
90
91
|
var useHost = require('./hooks/useHost/useHost.js');
|
|
@@ -203,6 +204,8 @@ exports.maxBin = maxBin.maxBin;
|
|
|
203
204
|
exports.binaryAccept = binaryAccept.binaryAccept;
|
|
204
205
|
exports.JSONString = JSONString.JSONString;
|
|
205
206
|
exports.Bin = Bin.Bin;
|
|
207
|
+
exports.generateSchemaTypes = generateTypes.generateSchemaTypes;
|
|
208
|
+
exports.generateTypes = generateTypes.generateTypes;
|
|
206
209
|
exports.serverContext = useServer.serverContext;
|
|
207
210
|
exports.useServer = useServer.useServer;
|
|
208
211
|
exports.apiContext = useApi.apiContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innet/server",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.5",
|
|
4
4
|
"description": "Create server-side application with innet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.es6.js",
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"@types/multiparty": "^0.0.33",
|
|
43
43
|
"@types/qs": "^6.9.7",
|
|
44
44
|
"cookie": "^0.5.0",
|
|
45
|
-
"dtsgenerator": "^3.18.0",
|
|
46
45
|
"http-proxy": "^1.18.1",
|
|
47
46
|
"innet": "^2.0.0-alpha.3",
|
|
48
47
|
"is-invalid-path": "^1.0.2",
|
|
@@ -4,7 +4,7 @@ export interface ResponseProps {
|
|
|
4
4
|
* A description of the response.
|
|
5
5
|
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
6
6
|
* */
|
|
7
|
-
description
|
|
7
|
+
description?: string;
|
|
8
8
|
/**
|
|
9
9
|
* Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as the property.
|
|
10
10
|
* To define a range of response codes, this field MAY contain the uppercase wildcard character X.
|
|
@@ -9,7 +9,7 @@ import { getOrAdd } from '../../../utils/getOrAdd/getOrAdd.es6.js';
|
|
|
9
9
|
import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
10
10
|
|
|
11
11
|
const response = () => {
|
|
12
|
-
const { description, status = 'default' } = useProps();
|
|
12
|
+
const { description = '', status = 'default' } = useProps() || {};
|
|
13
13
|
const { operation, props: { path } } = useEndpoint();
|
|
14
14
|
const children = useChildren();
|
|
15
15
|
const handler = useNewHandler();
|
|
@@ -17,7 +17,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
17
17
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
18
18
|
|
|
19
19
|
const response = () => {
|
|
20
|
-
const { description, status = 'default' } = jsx.useProps();
|
|
20
|
+
const { description = '', status = 'default' } = jsx.useProps() || {};
|
|
21
21
|
const { operation, props: { path } } = useEndpoint.useEndpoint();
|
|
22
22
|
const children = jsx.useChildren();
|
|
23
23
|
const handler = innet.useNewHandler();
|
|
@@ -1,34 +1,15 @@
|
|
|
1
|
-
import { __rest, __awaiter } from 'tslib';
|
|
2
1
|
import { useProps } from '@innet/jsx';
|
|
3
|
-
import
|
|
4
|
-
import fs from 'node:fs';
|
|
2
|
+
import { promises } from 'node:fs';
|
|
5
3
|
import '../../../hooks/index.es6.js';
|
|
4
|
+
import '../../../utils/index.es6.js';
|
|
6
5
|
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
6
|
+
import { generateTypes } from '../../../utils/generateTypes/generateTypes.es6.js';
|
|
7
7
|
|
|
8
8
|
const dts = () => {
|
|
9
|
-
const
|
|
9
|
+
const { path } = useProps();
|
|
10
10
|
const { docs } = useApi();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
config,
|
|
14
|
-
}).then((content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
yield fs.promises.writeFile(path, `interface Bin {
|
|
16
|
-
filename: string
|
|
17
|
-
fieldName: string
|
|
18
|
-
originalFilename: string
|
|
19
|
-
path: string
|
|
20
|
-
type: string
|
|
21
|
-
disposition: string
|
|
22
|
-
size: number
|
|
23
|
-
extension?: string
|
|
24
|
-
}
|
|
25
|
-
${content
|
|
26
|
-
.replaceAll(';', '')
|
|
27
|
-
.replaceAll('number // int64', 'bigint')
|
|
28
|
-
.replaceAll('string // binary', 'Bin')
|
|
29
|
-
.replaceAll('string // date-time', 'Date')}`);
|
|
30
|
-
})).catch(error => {
|
|
31
|
-
console.warn(error);
|
|
11
|
+
promises.writeFile(path, generateTypes(docs)).catch(e => {
|
|
12
|
+
console.error(e);
|
|
32
13
|
});
|
|
33
14
|
};
|
|
34
15
|
|
package/plugins/utils/dts/dts.js
CHANGED
|
@@ -2,42 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jsx = require('@innet/jsx');
|
|
7
|
-
var dtsGenerator = require('dtsgenerator');
|
|
8
6
|
var fs = require('node:fs');
|
|
9
7
|
require('../../../hooks/index.js');
|
|
8
|
+
require('../../../utils/index.js');
|
|
10
9
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var dtsGenerator__default = /*#__PURE__*/_interopDefaultLegacy(dtsGenerator);
|
|
15
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
|
+
var generateTypes = require('../../../utils/generateTypes/generateTypes.js');
|
|
16
11
|
|
|
17
12
|
const dts = () => {
|
|
18
|
-
const
|
|
13
|
+
const { path } = jsx.useProps();
|
|
19
14
|
const { docs } = useApi.useApi();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
config,
|
|
23
|
-
}).then((content) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
yield fs__default["default"].promises.writeFile(path, `interface Bin {
|
|
25
|
-
filename: string
|
|
26
|
-
fieldName: string
|
|
27
|
-
originalFilename: string
|
|
28
|
-
path: string
|
|
29
|
-
type: string
|
|
30
|
-
disposition: string
|
|
31
|
-
size: number
|
|
32
|
-
extension?: string
|
|
33
|
-
}
|
|
34
|
-
${content
|
|
35
|
-
.replaceAll(';', '')
|
|
36
|
-
.replaceAll('number // int64', 'bigint')
|
|
37
|
-
.replaceAll('string // binary', 'Bin')
|
|
38
|
-
.replaceAll('string // date-time', 'Date')}`);
|
|
39
|
-
})).catch(error => {
|
|
40
|
-
console.warn(error);
|
|
15
|
+
fs.promises.writeFile(path, generateTypes.generateTypes(docs)).catch(e => {
|
|
16
|
+
console.error(e);
|
|
41
17
|
});
|
|
42
18
|
};
|
|
43
19
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function hasDefault(target) {
|
|
2
|
+
return Boolean(target && ('default' in target || 'x-default' in target));
|
|
3
|
+
}
|
|
4
|
+
function generateSchemaTypes(schema, spaces = 2) {
|
|
5
|
+
const space = [...new Array(spaces)].map(() => ' ').join('');
|
|
6
|
+
if ('$ref' in schema) {
|
|
7
|
+
return `Schemas.${schema.$ref.slice(21)}\n`;
|
|
8
|
+
}
|
|
9
|
+
if (schema.type === 'integer') {
|
|
10
|
+
return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
|
|
11
|
+
}
|
|
12
|
+
if (schema.type === 'string') {
|
|
13
|
+
if (schema.format === 'date-time') {
|
|
14
|
+
return 'Date\n';
|
|
15
|
+
}
|
|
16
|
+
if (schema.format === 'binary') {
|
|
17
|
+
return 'Bin\n';
|
|
18
|
+
}
|
|
19
|
+
return 'string\n';
|
|
20
|
+
}
|
|
21
|
+
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
22
|
+
return `${schema.type}\n`;
|
|
23
|
+
}
|
|
24
|
+
if (schema.type === 'array') {
|
|
25
|
+
if (!schema.items)
|
|
26
|
+
return 'any[]\n';
|
|
27
|
+
return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
|
|
28
|
+
}
|
|
29
|
+
if (schema.type !== 'object') {
|
|
30
|
+
console.error('unknown type', schema);
|
|
31
|
+
return 'any\n';
|
|
32
|
+
}
|
|
33
|
+
let result = '{\n';
|
|
34
|
+
const required = schema.required || [];
|
|
35
|
+
for (const key in schema.properties) {
|
|
36
|
+
const prop = schema.properties[key];
|
|
37
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
38
|
+
? ':'
|
|
39
|
+
: '?:';
|
|
40
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
41
|
+
}
|
|
42
|
+
return `${result}${space.slice(0, -2)}}\n`;
|
|
43
|
+
}
|
|
44
|
+
function generateTypes(docs) {
|
|
45
|
+
var _a;
|
|
46
|
+
let result = 'declare namespace Api {\n export interface Bin {\n filename: string\n fieldName: string\n originalFilename: string\n path: string\n type: string\n disposition: string\n size: number\n extension?: string\n }\n';
|
|
47
|
+
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
48
|
+
const paths = docs.paths;
|
|
49
|
+
if (schemas) {
|
|
50
|
+
result += ' namespace Schemas {\n';
|
|
51
|
+
for (const name in schemas) {
|
|
52
|
+
result += ` export type ${name} = ${generateSchemaTypes(schemas[name], 6)}`;
|
|
53
|
+
}
|
|
54
|
+
result += ' }\n';
|
|
55
|
+
}
|
|
56
|
+
result += ' export interface Endpoints {\n';
|
|
57
|
+
for (const path in paths) {
|
|
58
|
+
const pathObject = paths[path];
|
|
59
|
+
for (const method in pathObject) {
|
|
60
|
+
// @ts-expect-error: FIXME
|
|
61
|
+
const endpoint = pathObject[method];
|
|
62
|
+
const parameters = endpoint.parameters;
|
|
63
|
+
const requestBody = endpoint.requestBody;
|
|
64
|
+
const responses = endpoint.responses;
|
|
65
|
+
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
66
|
+
if (parameters) {
|
|
67
|
+
const params = {
|
|
68
|
+
query: '',
|
|
69
|
+
header: '',
|
|
70
|
+
path: '',
|
|
71
|
+
cookie: '',
|
|
72
|
+
};
|
|
73
|
+
for (const param of parameters) {
|
|
74
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
75
|
+
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
76
|
+
}
|
|
77
|
+
if (params.path) {
|
|
78
|
+
result += ` Params: {\n${params.path} }\n`;
|
|
79
|
+
}
|
|
80
|
+
if (params.query) {
|
|
81
|
+
result += ` Search: {\n${params.query} }\n`;
|
|
82
|
+
}
|
|
83
|
+
if (params.header) {
|
|
84
|
+
result += ` Headers: {\n${params.header} }\n`;
|
|
85
|
+
}
|
|
86
|
+
if (params.cookie) {
|
|
87
|
+
result += ` Cookies: {\n${params.cookie} }\n`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (requestBody) {
|
|
91
|
+
result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
|
|
92
|
+
}
|
|
93
|
+
if (responses === null || responses === void 0 ? void 0 : responses.default) {
|
|
94
|
+
result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
|
|
95
|
+
}
|
|
96
|
+
result += ' }\n';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result + ' }\n}';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { generateSchemaTypes, generateTypes };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function hasDefault(target) {
|
|
6
|
+
return Boolean(target && ('default' in target || 'x-default' in target));
|
|
7
|
+
}
|
|
8
|
+
function generateSchemaTypes(schema, spaces = 2) {
|
|
9
|
+
const space = [...new Array(spaces)].map(() => ' ').join('');
|
|
10
|
+
if ('$ref' in schema) {
|
|
11
|
+
return `Schemas.${schema.$ref.slice(21)}\n`;
|
|
12
|
+
}
|
|
13
|
+
if (schema.type === 'integer') {
|
|
14
|
+
return `${schema.format === 'int64' ? 'bigint' : 'number'}\n`;
|
|
15
|
+
}
|
|
16
|
+
if (schema.type === 'string') {
|
|
17
|
+
if (schema.format === 'date-time') {
|
|
18
|
+
return 'Date\n';
|
|
19
|
+
}
|
|
20
|
+
if (schema.format === 'binary') {
|
|
21
|
+
return 'Bin\n';
|
|
22
|
+
}
|
|
23
|
+
return 'string\n';
|
|
24
|
+
}
|
|
25
|
+
if (['boolean', 'number', 'null'].includes(schema.type)) {
|
|
26
|
+
return `${schema.type}\n`;
|
|
27
|
+
}
|
|
28
|
+
if (schema.type === 'array') {
|
|
29
|
+
if (!schema.items)
|
|
30
|
+
return 'any[]\n';
|
|
31
|
+
return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
|
|
32
|
+
}
|
|
33
|
+
if (schema.type !== 'object') {
|
|
34
|
+
console.error('unknown type', schema);
|
|
35
|
+
return 'any\n';
|
|
36
|
+
}
|
|
37
|
+
let result = '{\n';
|
|
38
|
+
const required = schema.required || [];
|
|
39
|
+
for (const key in schema.properties) {
|
|
40
|
+
const prop = schema.properties[key];
|
|
41
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
42
|
+
? ':'
|
|
43
|
+
: '?:';
|
|
44
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
45
|
+
}
|
|
46
|
+
return `${result}${space.slice(0, -2)}}\n`;
|
|
47
|
+
}
|
|
48
|
+
function generateTypes(docs) {
|
|
49
|
+
var _a;
|
|
50
|
+
let result = 'declare namespace Api {\n export interface Bin {\n filename: string\n fieldName: string\n originalFilename: string\n path: string\n type: string\n disposition: string\n size: number\n extension?: string\n }\n';
|
|
51
|
+
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
52
|
+
const paths = docs.paths;
|
|
53
|
+
if (schemas) {
|
|
54
|
+
result += ' namespace Schemas {\n';
|
|
55
|
+
for (const name in schemas) {
|
|
56
|
+
result += ` export type ${name} = ${generateSchemaTypes(schemas[name], 6)}`;
|
|
57
|
+
}
|
|
58
|
+
result += ' }\n';
|
|
59
|
+
}
|
|
60
|
+
result += ' export interface Endpoints {\n';
|
|
61
|
+
for (const path in paths) {
|
|
62
|
+
const pathObject = paths[path];
|
|
63
|
+
for (const method in pathObject) {
|
|
64
|
+
// @ts-expect-error: FIXME
|
|
65
|
+
const endpoint = pathObject[method];
|
|
66
|
+
const parameters = endpoint.parameters;
|
|
67
|
+
const requestBody = endpoint.requestBody;
|
|
68
|
+
const responses = endpoint.responses;
|
|
69
|
+
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
70
|
+
if (parameters) {
|
|
71
|
+
const params = {
|
|
72
|
+
query: '',
|
|
73
|
+
header: '',
|
|
74
|
+
path: '',
|
|
75
|
+
cookie: '',
|
|
76
|
+
};
|
|
77
|
+
for (const param of parameters) {
|
|
78
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
79
|
+
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
80
|
+
}
|
|
81
|
+
if (params.path) {
|
|
82
|
+
result += ` Params: {\n${params.path} }\n`;
|
|
83
|
+
}
|
|
84
|
+
if (params.query) {
|
|
85
|
+
result += ` Search: {\n${params.query} }\n`;
|
|
86
|
+
}
|
|
87
|
+
if (params.header) {
|
|
88
|
+
result += ` Headers: {\n${params.header} }\n`;
|
|
89
|
+
}
|
|
90
|
+
if (params.cookie) {
|
|
91
|
+
result += ` Cookies: {\n${params.cookie} }\n`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (requestBody) {
|
|
95
|
+
result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
|
|
96
|
+
}
|
|
97
|
+
if (responses === null || responses === void 0 ? void 0 : responses.default) {
|
|
98
|
+
result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
|
|
99
|
+
}
|
|
100
|
+
result += ' }\n';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result + ' }\n}';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.generateSchemaTypes = generateSchemaTypes;
|
|
107
|
+
exports.generateTypes = generateTypes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generateTypes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateSchemaTypes, generateTypes } from './generateTypes.es6.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var generateTypes = require('./generateTypes.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.generateSchemaTypes = generateTypes.generateSchemaTypes;
|
|
10
|
+
exports.generateTypes = generateTypes.generateTypes;
|
package/utils/index.d.ts
CHANGED
package/utils/index.es6.js
CHANGED
package/utils/index.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function EditPartner(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './EditPartner';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function GetPartner(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GetPartner';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function GetPartners(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './GetPartners';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function AddressSchema(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AddressSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AddressSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function LocationSchema(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './LocationSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './LocationSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function EditPartnerSchema(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './EditPartnerSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function PartnerSchema(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PartnerSchema';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function Partner(): any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Partner';
|