@opra/cli 1.0.0-alpha.19 → 1.0.0-alpha.20
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.
|
@@ -42,12 +42,21 @@ async function generateHttpController(controller) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/** Process operations */
|
|
45
|
+
const mergedControllerParams = [...controller.parameters];
|
|
46
|
+
let _base = controller;
|
|
47
|
+
while (_base.owner instanceof common_1.HttpController) {
|
|
48
|
+
_base = _base.owner;
|
|
49
|
+
mergedControllerParams.unshift(..._base?.parameters);
|
|
50
|
+
}
|
|
45
51
|
for (const operation of controller.operations.values()) {
|
|
52
|
+
const mergedParams = [...mergedControllerParams, ...operation.parameters];
|
|
46
53
|
const operationBlock = (classBlock['operation_' + operation.name] = new code_block_js_1.CodeBlock());
|
|
47
|
-
operationBlock.doc =
|
|
54
|
+
operationBlock.doc = new code_block_js_1.CodeBlock();
|
|
55
|
+
operationBlock.doc.header = `
|
|
48
56
|
/**
|
|
49
57
|
* ${(0, string_utils_js_1.wrapJSDocString)(operation.description || operation.name + ' operation')}`;
|
|
50
|
-
|
|
58
|
+
operationBlock.doc.parameters = new code_block_js_1.CodeBlock();
|
|
59
|
+
if (mergedParams.length) {
|
|
51
60
|
const block = new code_block_js_1.CodeBlock();
|
|
52
61
|
block.doc = '\n *\n * RegExp parameters:';
|
|
53
62
|
let i = 0;
|
|
@@ -63,12 +72,11 @@ async function generateHttpController(controller) {
|
|
|
63
72
|
(prm.deprecated ? `\n * deprecated: ${prm.deprecated}` : '');
|
|
64
73
|
}
|
|
65
74
|
if (i)
|
|
66
|
-
operationBlock.doc
|
|
75
|
+
operationBlock.doc.regExParameters = block;
|
|
67
76
|
}
|
|
68
|
-
operationBlock.doc
|
|
77
|
+
operationBlock.doc.tail = `\n */\n`;
|
|
69
78
|
operationBlock.head = `${operation.name}(`;
|
|
70
79
|
/** Process operation parameters */
|
|
71
|
-
const mergedParams = [...controller.parameters, ...operation.parameters];
|
|
72
80
|
const pathParams = [];
|
|
73
81
|
const queryParams = [];
|
|
74
82
|
const headerParams = [];
|
|
@@ -105,6 +113,10 @@ async function generateHttpController(controller) {
|
|
|
105
113
|
if (argIndex++ > 0)
|
|
106
114
|
operationBlock.head += ', ';
|
|
107
115
|
operationBlock.head += `${prm.name}: ${typeDef}`;
|
|
116
|
+
operationBlock.doc.parameters +=
|
|
117
|
+
`\n * @param {${typeDef}} ` +
|
|
118
|
+
(prm.required ? prm.name : `[${prm.name}]`) +
|
|
119
|
+
(prm.description ? ' - ' + (0, string_utils_js_1.wrapJSDocString)(prm.description || '') : '');
|
|
108
120
|
}
|
|
109
121
|
/** Process requestBody and add as function argument ($body) */
|
|
110
122
|
let hasBody = false;
|
|
@@ -137,10 +149,18 @@ async function generateHttpController(controller) {
|
|
|
137
149
|
typeArr.push(typeDef);
|
|
138
150
|
continue;
|
|
139
151
|
}
|
|
152
|
+
else if (content.contentType && type_is_1.default.is(String(content.contentType), ['multipart/*'])) {
|
|
153
|
+
const typeDef = 'FormData';
|
|
154
|
+
if (!typeArr.includes(typeDef))
|
|
155
|
+
typeArr.push(typeDef);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
140
158
|
typeArr = [];
|
|
141
159
|
break;
|
|
142
160
|
}
|
|
143
|
-
|
|
161
|
+
const typeDef = typeArr.join(' | ') || 'any';
|
|
162
|
+
operationBlock.head += `$body: ${typeDef}`;
|
|
163
|
+
operationBlock.doc.parameters += `\n * @param {${typeDef}} $body - Http body`;
|
|
144
164
|
hasBody = true;
|
|
145
165
|
}
|
|
146
166
|
/** process query params */
|
|
@@ -150,6 +170,7 @@ async function generateHttpController(controller) {
|
|
|
150
170
|
if (argIndex++ > 0)
|
|
151
171
|
operationBlock.head += ', ';
|
|
152
172
|
operationBlock.head += '\n\t$params' + (isHeadersRequired || isQueryRequired ? '' : '?') + ': {\n\t';
|
|
173
|
+
operationBlock.doc.parameters += '\n * @param {object} $params - Available parameters for the operation';
|
|
153
174
|
for (const prm of queryParams) {
|
|
154
175
|
operationBlock.head += `/**\n * ${prm.description || ''}\n */\n`;
|
|
155
176
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import typeIs from '@browsery/type-is';
|
|
3
|
-
import { MimeTypes } from '@opra/common';
|
|
3
|
+
import { HttpController, MimeTypes } from '@opra/common';
|
|
4
4
|
import { camelCase, pascalCase } from 'putil-varhelpers';
|
|
5
5
|
import { CodeBlock } from '../../code-block.js';
|
|
6
6
|
import { locateNamedType } from '../utils/locate-named-type.js';
|
|
@@ -38,12 +38,21 @@ export async function generateHttpController(controller) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/** Process operations */
|
|
41
|
+
const mergedControllerParams = [...controller.parameters];
|
|
42
|
+
let _base = controller;
|
|
43
|
+
while (_base.owner instanceof HttpController) {
|
|
44
|
+
_base = _base.owner;
|
|
45
|
+
mergedControllerParams.unshift(..._base?.parameters);
|
|
46
|
+
}
|
|
41
47
|
for (const operation of controller.operations.values()) {
|
|
48
|
+
const mergedParams = [...mergedControllerParams, ...operation.parameters];
|
|
42
49
|
const operationBlock = (classBlock['operation_' + operation.name] = new CodeBlock());
|
|
43
|
-
operationBlock.doc =
|
|
50
|
+
operationBlock.doc = new CodeBlock();
|
|
51
|
+
operationBlock.doc.header = `
|
|
44
52
|
/**
|
|
45
53
|
* ${wrapJSDocString(operation.description || operation.name + ' operation')}`;
|
|
46
|
-
|
|
54
|
+
operationBlock.doc.parameters = new CodeBlock();
|
|
55
|
+
if (mergedParams.length) {
|
|
47
56
|
const block = new CodeBlock();
|
|
48
57
|
block.doc = '\n *\n * RegExp parameters:';
|
|
49
58
|
let i = 0;
|
|
@@ -59,12 +68,11 @@ export async function generateHttpController(controller) {
|
|
|
59
68
|
(prm.deprecated ? `\n * deprecated: ${prm.deprecated}` : '');
|
|
60
69
|
}
|
|
61
70
|
if (i)
|
|
62
|
-
operationBlock.doc
|
|
71
|
+
operationBlock.doc.regExParameters = block;
|
|
63
72
|
}
|
|
64
|
-
operationBlock.doc
|
|
73
|
+
operationBlock.doc.tail = `\n */\n`;
|
|
65
74
|
operationBlock.head = `${operation.name}(`;
|
|
66
75
|
/** Process operation parameters */
|
|
67
|
-
const mergedParams = [...controller.parameters, ...operation.parameters];
|
|
68
76
|
const pathParams = [];
|
|
69
77
|
const queryParams = [];
|
|
70
78
|
const headerParams = [];
|
|
@@ -101,6 +109,10 @@ export async function generateHttpController(controller) {
|
|
|
101
109
|
if (argIndex++ > 0)
|
|
102
110
|
operationBlock.head += ', ';
|
|
103
111
|
operationBlock.head += `${prm.name}: ${typeDef}`;
|
|
112
|
+
operationBlock.doc.parameters +=
|
|
113
|
+
`\n * @param {${typeDef}} ` +
|
|
114
|
+
(prm.required ? prm.name : `[${prm.name}]`) +
|
|
115
|
+
(prm.description ? ' - ' + wrapJSDocString(prm.description || '') : '');
|
|
104
116
|
}
|
|
105
117
|
/** Process requestBody and add as function argument ($body) */
|
|
106
118
|
let hasBody = false;
|
|
@@ -133,10 +145,18 @@ export async function generateHttpController(controller) {
|
|
|
133
145
|
typeArr.push(typeDef);
|
|
134
146
|
continue;
|
|
135
147
|
}
|
|
148
|
+
else if (content.contentType && typeIs.is(String(content.contentType), ['multipart/*'])) {
|
|
149
|
+
const typeDef = 'FormData';
|
|
150
|
+
if (!typeArr.includes(typeDef))
|
|
151
|
+
typeArr.push(typeDef);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
136
154
|
typeArr = [];
|
|
137
155
|
break;
|
|
138
156
|
}
|
|
139
|
-
|
|
157
|
+
const typeDef = typeArr.join(' | ') || 'any';
|
|
158
|
+
operationBlock.head += `$body: ${typeDef}`;
|
|
159
|
+
operationBlock.doc.parameters += `\n * @param {${typeDef}} $body - Http body`;
|
|
140
160
|
hasBody = true;
|
|
141
161
|
}
|
|
142
162
|
/** process query params */
|
|
@@ -146,6 +166,7 @@ export async function generateHttpController(controller) {
|
|
|
146
166
|
if (argIndex++ > 0)
|
|
147
167
|
operationBlock.head += ', ';
|
|
148
168
|
operationBlock.head += '\n\t$params' + (isHeadersRequired || isQueryRequired ? '' : '?') + ': {\n\t';
|
|
169
|
+
operationBlock.doc.parameters += '\n * @param {object} $params - Available parameters for the operation';
|
|
149
170
|
for (const prm of queryParams) {
|
|
150
171
|
operationBlock.head += `/**\n * ${prm.description || ''}\n */\n`;
|
|
151
172
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@browsery/type-is": "^1.6.18-r3",
|
|
35
|
-
"@opra/client": "^1.0.0-alpha.
|
|
36
|
-
"@opra/common": "^1.0.0-alpha.
|
|
35
|
+
"@opra/client": "^1.0.0-alpha.20",
|
|
36
|
+
"@opra/common": "^1.0.0-alpha.20",
|
|
37
37
|
"chalk": "^5.3.0",
|
|
38
38
|
"commander": "^12.0.0",
|
|
39
39
|
"js-string-escape": "^1.0.1",
|