@opra/cli 1.0.0-alpha.13 → 1.0.0-alpha.15
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.
|
@@ -90,19 +90,23 @@ async function generateHttpController(controller) {
|
|
|
90
90
|
queryParams.push(...Object.values(queryParamsMap));
|
|
91
91
|
headerParams.push(...Object.values(headerParamsMap));
|
|
92
92
|
}
|
|
93
|
+
/** Process path parameters and add as function arguments */
|
|
93
94
|
let argIndex = 0;
|
|
94
95
|
for (const prm of pathParams) {
|
|
95
|
-
let
|
|
96
|
+
let typeDef;
|
|
96
97
|
if (prm.type) {
|
|
97
98
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
98
|
-
|
|
99
|
+
typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
99
100
|
}
|
|
100
101
|
else
|
|
101
|
-
|
|
102
|
+
typeDef = `any`;
|
|
103
|
+
if (prm.isArray)
|
|
104
|
+
typeDef += '[]';
|
|
102
105
|
if (argIndex++ > 0)
|
|
103
106
|
operationBlock.head += ', ';
|
|
104
|
-
operationBlock.head += `${prm.name}: ${
|
|
107
|
+
operationBlock.head += `${prm.name}: ${typeDef}`;
|
|
105
108
|
}
|
|
109
|
+
/** Process requestBody and add as function argument ($body) */
|
|
106
110
|
let hasBody = false;
|
|
107
111
|
if (operation.requestBody?.content.length) {
|
|
108
112
|
if (argIndex++ > 0)
|
|
@@ -126,6 +130,8 @@ async function generateHttpController(controller) {
|
|
|
126
130
|
typeDef = `DTO<${typeDef}>`;
|
|
127
131
|
}
|
|
128
132
|
}
|
|
133
|
+
if (typeDef && content.isArray)
|
|
134
|
+
typeDef += '[]';
|
|
129
135
|
typeDef = typeDef || 'undefined';
|
|
130
136
|
if (!typeArr.includes(typeDef))
|
|
131
137
|
typeArr.push(typeDef);
|
|
@@ -149,7 +155,9 @@ async function generateHttpController(controller) {
|
|
|
149
155
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
|
150
156
|
if (prm.type) {
|
|
151
157
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
152
|
-
|
|
158
|
+
let typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
159
|
+
if (prm.isArray)
|
|
160
|
+
typeDef += '[]';
|
|
153
161
|
operationBlock.head += `${typeDef};\n`;
|
|
154
162
|
}
|
|
155
163
|
else
|
|
@@ -167,7 +175,9 @@ async function generateHttpController(controller) {
|
|
|
167
175
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
|
168
176
|
if (prm.type) {
|
|
169
177
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
170
|
-
|
|
178
|
+
let typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
179
|
+
if (prm.isArray)
|
|
180
|
+
typeDef += '[]';
|
|
171
181
|
operationBlock.head += `${typeDef};\n`;
|
|
172
182
|
}
|
|
173
183
|
else
|
|
@@ -176,7 +186,7 @@ async function generateHttpController(controller) {
|
|
|
176
186
|
operationBlock.head += '\b}\b';
|
|
177
187
|
}
|
|
178
188
|
/* Determine return type */
|
|
179
|
-
|
|
189
|
+
const returnTypes = [];
|
|
180
190
|
let typeDef = '';
|
|
181
191
|
for (const resp of operation.responses) {
|
|
182
192
|
if (!resp.statusCode.find(r => r.intersects(200, 299)))
|
|
@@ -186,14 +196,6 @@ async function generateHttpController(controller) {
|
|
|
186
196
|
const xt = await this.generateDataType(resp.type, 'typeDef', file);
|
|
187
197
|
typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
188
198
|
}
|
|
189
|
-
else if (resp.contentType && type_is_1.default.is(String(resp.contentType), [common_1.MimeTypes.opra_response_json])) {
|
|
190
|
-
file.addImport('@opra/common', ['OperationResult']);
|
|
191
|
-
typeDef = 'OperationResult';
|
|
192
|
-
}
|
|
193
|
-
if (typeDef === 'any') {
|
|
194
|
-
returnTypes = [];
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
199
|
if (typeDef) {
|
|
198
200
|
if (typeDef !== 'OperationResult') {
|
|
199
201
|
if (resp.partial) {
|
|
@@ -206,6 +208,12 @@ async function generateHttpController(controller) {
|
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
210
|
}
|
|
211
|
+
if (resp.contentType && type_is_1.default.is(String(resp.contentType), [common_1.MimeTypes.opra_response_json])) {
|
|
212
|
+
file.addImport('@opra/common', ['OperationResult']);
|
|
213
|
+
typeDef = typeDef ? `OperationResult<${typeDef}>` : 'OperationResult';
|
|
214
|
+
}
|
|
215
|
+
if (typeDef && resp.isArray)
|
|
216
|
+
typeDef += '[]';
|
|
209
217
|
typeDef = typeDef || 'undefined';
|
|
210
218
|
if (!returnTypes.includes(typeDef))
|
|
211
219
|
returnTypes.push(typeDef);
|
|
@@ -86,19 +86,23 @@ export async function generateHttpController(controller) {
|
|
|
86
86
|
queryParams.push(...Object.values(queryParamsMap));
|
|
87
87
|
headerParams.push(...Object.values(headerParamsMap));
|
|
88
88
|
}
|
|
89
|
+
/** Process path parameters and add as function arguments */
|
|
89
90
|
let argIndex = 0;
|
|
90
91
|
for (const prm of pathParams) {
|
|
91
|
-
let
|
|
92
|
+
let typeDef;
|
|
92
93
|
if (prm.type) {
|
|
93
94
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
94
|
-
|
|
95
|
+
typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
95
96
|
}
|
|
96
97
|
else
|
|
97
|
-
|
|
98
|
+
typeDef = `any`;
|
|
99
|
+
if (prm.isArray)
|
|
100
|
+
typeDef += '[]';
|
|
98
101
|
if (argIndex++ > 0)
|
|
99
102
|
operationBlock.head += ', ';
|
|
100
|
-
operationBlock.head += `${prm.name}: ${
|
|
103
|
+
operationBlock.head += `${prm.name}: ${typeDef}`;
|
|
101
104
|
}
|
|
105
|
+
/** Process requestBody and add as function argument ($body) */
|
|
102
106
|
let hasBody = false;
|
|
103
107
|
if (operation.requestBody?.content.length) {
|
|
104
108
|
if (argIndex++ > 0)
|
|
@@ -122,6 +126,8 @@ export async function generateHttpController(controller) {
|
|
|
122
126
|
typeDef = `DTO<${typeDef}>`;
|
|
123
127
|
}
|
|
124
128
|
}
|
|
129
|
+
if (typeDef && content.isArray)
|
|
130
|
+
typeDef += '[]';
|
|
125
131
|
typeDef = typeDef || 'undefined';
|
|
126
132
|
if (!typeArr.includes(typeDef))
|
|
127
133
|
typeArr.push(typeDef);
|
|
@@ -145,7 +151,9 @@ export async function generateHttpController(controller) {
|
|
|
145
151
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
|
146
152
|
if (prm.type) {
|
|
147
153
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
148
|
-
|
|
154
|
+
let typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
155
|
+
if (prm.isArray)
|
|
156
|
+
typeDef += '[]';
|
|
149
157
|
operationBlock.head += `${typeDef};\n`;
|
|
150
158
|
}
|
|
151
159
|
else
|
|
@@ -163,7 +171,9 @@ export async function generateHttpController(controller) {
|
|
|
163
171
|
operationBlock.head += `${prm.name}${prm.required ? '' : '?'}: `;
|
|
164
172
|
if (prm.type) {
|
|
165
173
|
const xt = await this.generateDataType(prm.type, 'typeDef', file);
|
|
166
|
-
|
|
174
|
+
let typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
175
|
+
if (prm.isArray)
|
|
176
|
+
typeDef += '[]';
|
|
167
177
|
operationBlock.head += `${typeDef};\n`;
|
|
168
178
|
}
|
|
169
179
|
else
|
|
@@ -172,7 +182,7 @@ export async function generateHttpController(controller) {
|
|
|
172
182
|
operationBlock.head += '\b}\b';
|
|
173
183
|
}
|
|
174
184
|
/* Determine return type */
|
|
175
|
-
|
|
185
|
+
const returnTypes = [];
|
|
176
186
|
let typeDef = '';
|
|
177
187
|
for (const resp of operation.responses) {
|
|
178
188
|
if (!resp.statusCode.find(r => r.intersects(200, 299)))
|
|
@@ -182,14 +192,6 @@ export async function generateHttpController(controller) {
|
|
|
182
192
|
const xt = await this.generateDataType(resp.type, 'typeDef', file);
|
|
183
193
|
typeDef = xt.kind === 'embedded' ? xt.code : xt.typeName;
|
|
184
194
|
}
|
|
185
|
-
else if (resp.contentType && typeIs.is(String(resp.contentType), [MimeTypes.opra_response_json])) {
|
|
186
|
-
file.addImport('@opra/common', ['OperationResult']);
|
|
187
|
-
typeDef = 'OperationResult';
|
|
188
|
-
}
|
|
189
|
-
if (typeDef === 'any') {
|
|
190
|
-
returnTypes = [];
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
195
|
if (typeDef) {
|
|
194
196
|
if (typeDef !== 'OperationResult') {
|
|
195
197
|
if (resp.partial) {
|
|
@@ -202,6 +204,12 @@ export async function generateHttpController(controller) {
|
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
}
|
|
207
|
+
if (resp.contentType && typeIs.is(String(resp.contentType), [MimeTypes.opra_response_json])) {
|
|
208
|
+
file.addImport('@opra/common', ['OperationResult']);
|
|
209
|
+
typeDef = typeDef ? `OperationResult<${typeDef}>` : 'OperationResult';
|
|
210
|
+
}
|
|
211
|
+
if (typeDef && resp.isArray)
|
|
212
|
+
typeDef += '[]';
|
|
205
213
|
typeDef = typeDef || 'undefined';
|
|
206
214
|
if (!returnTypes.includes(typeDef))
|
|
207
215
|
returnTypes.push(typeDef);
|
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.15",
|
|
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.15",
|
|
36
|
+
"@opra/common": "^1.0.0-alpha.15",
|
|
37
37
|
"chalk": "^5.3.0",
|
|
38
38
|
"commander": "^12.0.0",
|
|
39
39
|
"js-string-escape": "^1.0.1",
|