@innet/server 2.0.0-alpha.2 → 2.0.0-alpha.4
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 +19 -0
- 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 +93 -0
- package/utils/generateTypes/generateTypes.js +98 -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
|
@@ -3319,6 +3319,7 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3319
3319
|
[useParams](#useparams)
|
|
3320
3320
|
[useSearch](#usesearch)
|
|
3321
3321
|
[useBody](#usebody)
|
|
3322
|
+
[useComponentName](#usecomponentname)
|
|
3322
3323
|
|
|
3323
3324
|
---
|
|
3324
3325
|
|
|
@@ -3496,6 +3497,24 @@ export function Component () {
|
|
|
3496
3497
|
}
|
|
3497
3498
|
```
|
|
3498
3499
|
|
|
3500
|
+
### useComponentName
|
|
3501
|
+
|
|
3502
|
+
[← back](#hooks)
|
|
3503
|
+
|
|
3504
|
+
This hook returns name of current component.
|
|
3505
|
+
|
|
3506
|
+
*src/Component.tsx*
|
|
3507
|
+
```typescript jsx
|
|
3508
|
+
import { useComponentName } from '@innet/sever'
|
|
3509
|
+
|
|
3510
|
+
export function Component () {
|
|
3511
|
+
// returns this ^-------^
|
|
3512
|
+
const name = useComponentName()
|
|
3513
|
+
|
|
3514
|
+
return <success>{{ name }}</success>
|
|
3515
|
+
}
|
|
3516
|
+
```
|
|
3517
|
+
|
|
3499
3518
|
## Issues
|
|
3500
3519
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|
|
3501
3520
|
|
|
@@ -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.4",
|
|
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,93 @@
|
|
|
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 (['string', 'boolean', 'number', 'null'].includes(schema.type)) {
|
|
13
|
+
return `${schema.type}\n`;
|
|
14
|
+
}
|
|
15
|
+
if (schema.type === 'array') {
|
|
16
|
+
if (!schema.items)
|
|
17
|
+
return 'any[]\n';
|
|
18
|
+
return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
|
|
19
|
+
}
|
|
20
|
+
if (schema.type !== 'object') {
|
|
21
|
+
console.error('unknown type', schema);
|
|
22
|
+
return 'any\n';
|
|
23
|
+
}
|
|
24
|
+
let result = '{\n';
|
|
25
|
+
const required = schema.required || [];
|
|
26
|
+
for (const key in schema.properties) {
|
|
27
|
+
const prop = schema.properties[key];
|
|
28
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
29
|
+
? ':'
|
|
30
|
+
: '?:';
|
|
31
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
32
|
+
}
|
|
33
|
+
return `${result}${space.slice(0, -2)}}\n`;
|
|
34
|
+
}
|
|
35
|
+
function generateTypes(docs) {
|
|
36
|
+
var _a;
|
|
37
|
+
let result = 'declare namespace Api {\n';
|
|
38
|
+
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
39
|
+
const paths = docs.paths;
|
|
40
|
+
if (schemas) {
|
|
41
|
+
result += ' namespace Schemas {\n';
|
|
42
|
+
for (const name in schemas) {
|
|
43
|
+
result += ` export type ${name} = ${generateSchemaTypes(schemas[name], 6)}`;
|
|
44
|
+
}
|
|
45
|
+
result += ' }\n';
|
|
46
|
+
}
|
|
47
|
+
result += ' export interface Endpoints {\n';
|
|
48
|
+
for (const path in paths) {
|
|
49
|
+
const pathObject = paths[path];
|
|
50
|
+
for (const method in pathObject) {
|
|
51
|
+
// @ts-expect-error: FIXME
|
|
52
|
+
const endpoint = pathObject[method];
|
|
53
|
+
const parameters = endpoint.parameters;
|
|
54
|
+
const requestBody = endpoint.requestBody;
|
|
55
|
+
const responses = endpoint.responses;
|
|
56
|
+
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
57
|
+
if (parameters) {
|
|
58
|
+
const params = {
|
|
59
|
+
query: '',
|
|
60
|
+
header: '',
|
|
61
|
+
path: '',
|
|
62
|
+
cookie: '',
|
|
63
|
+
};
|
|
64
|
+
for (const param of parameters) {
|
|
65
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
66
|
+
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
67
|
+
}
|
|
68
|
+
if (params.path) {
|
|
69
|
+
result += ` Params: {\n${params.path} }\n`;
|
|
70
|
+
}
|
|
71
|
+
if (params.query) {
|
|
72
|
+
result += ` Search: {\n${params.query} }\n`;
|
|
73
|
+
}
|
|
74
|
+
if (params.header) {
|
|
75
|
+
result += ` Headers: {\n${params.header} }\n`;
|
|
76
|
+
}
|
|
77
|
+
if (params.cookie) {
|
|
78
|
+
result += ` Cookies: {\n${params.cookie} }\n`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (requestBody) {
|
|
82
|
+
result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
|
|
83
|
+
}
|
|
84
|
+
if (responses === null || responses === void 0 ? void 0 : responses.default) {
|
|
85
|
+
result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
|
|
86
|
+
}
|
|
87
|
+
result += ' }\n';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result + ' }\n}';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { generateSchemaTypes, generateTypes };
|
|
@@ -0,0 +1,98 @@
|
|
|
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 (['string', 'boolean', 'number', 'null'].includes(schema.type)) {
|
|
17
|
+
return `${schema.type}\n`;
|
|
18
|
+
}
|
|
19
|
+
if (schema.type === 'array') {
|
|
20
|
+
if (!schema.items)
|
|
21
|
+
return 'any[]\n';
|
|
22
|
+
return `(${generateSchemaTypes(schema.items, spaces + 2).slice(0, -1)})[]\n`;
|
|
23
|
+
}
|
|
24
|
+
if (schema.type !== 'object') {
|
|
25
|
+
console.error('unknown type', schema);
|
|
26
|
+
return 'any\n';
|
|
27
|
+
}
|
|
28
|
+
let result = '{\n';
|
|
29
|
+
const required = schema.required || [];
|
|
30
|
+
for (const key in schema.properties) {
|
|
31
|
+
const prop = schema.properties[key];
|
|
32
|
+
const splitter = required.includes(key) || hasDefault(prop)
|
|
33
|
+
? ':'
|
|
34
|
+
: '?:';
|
|
35
|
+
result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
|
|
36
|
+
}
|
|
37
|
+
return `${result}${space.slice(0, -2)}}\n`;
|
|
38
|
+
}
|
|
39
|
+
function generateTypes(docs) {
|
|
40
|
+
var _a;
|
|
41
|
+
let result = 'declare namespace Api {\n';
|
|
42
|
+
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
43
|
+
const paths = docs.paths;
|
|
44
|
+
if (schemas) {
|
|
45
|
+
result += ' namespace Schemas {\n';
|
|
46
|
+
for (const name in schemas) {
|
|
47
|
+
result += ` export type ${name} = ${generateSchemaTypes(schemas[name], 6)}`;
|
|
48
|
+
}
|
|
49
|
+
result += ' }\n';
|
|
50
|
+
}
|
|
51
|
+
result += ' export interface Endpoints {\n';
|
|
52
|
+
for (const path in paths) {
|
|
53
|
+
const pathObject = paths[path];
|
|
54
|
+
for (const method in pathObject) {
|
|
55
|
+
// @ts-expect-error: FIXME
|
|
56
|
+
const endpoint = pathObject[method];
|
|
57
|
+
const parameters = endpoint.parameters;
|
|
58
|
+
const requestBody = endpoint.requestBody;
|
|
59
|
+
const responses = endpoint.responses;
|
|
60
|
+
result += ` ['${method.toUpperCase()}:${path}']: {\n`;
|
|
61
|
+
if (parameters) {
|
|
62
|
+
const params = {
|
|
63
|
+
query: '',
|
|
64
|
+
header: '',
|
|
65
|
+
path: '',
|
|
66
|
+
cookie: '',
|
|
67
|
+
};
|
|
68
|
+
for (const param of parameters) {
|
|
69
|
+
const splitter = param.in === 'path' || hasDefault(param.schema) ? ':' : '?:';
|
|
70
|
+
params[param.in] += ` ${param.name}${splitter} ${generateSchemaTypes(param.schema)}`;
|
|
71
|
+
}
|
|
72
|
+
if (params.path) {
|
|
73
|
+
result += ` Params: {\n${params.path} }\n`;
|
|
74
|
+
}
|
|
75
|
+
if (params.query) {
|
|
76
|
+
result += ` Search: {\n${params.query} }\n`;
|
|
77
|
+
}
|
|
78
|
+
if (params.header) {
|
|
79
|
+
result += ` Headers: {\n${params.header} }\n`;
|
|
80
|
+
}
|
|
81
|
+
if (params.cookie) {
|
|
82
|
+
result += ` Cookies: {\n${params.cookie} }\n`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (requestBody) {
|
|
86
|
+
result += ` Body: ${generateSchemaTypes(requestBody.content['multipart/form-data'].schema, 8)}`;
|
|
87
|
+
}
|
|
88
|
+
if (responses === null || responses === void 0 ? void 0 : responses.default) {
|
|
89
|
+
result += ` Response: ${generateSchemaTypes(responses.default.content['application/json'].schema, 8)}`;
|
|
90
|
+
}
|
|
91
|
+
result += ' }\n';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result + ' }\n}';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.generateSchemaTypes = generateSchemaTypes;
|
|
98
|
+
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';
|