@goast/typescript 0.3.8-beta1 → 0.3.9
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 +43 -43
- package/assets/client/angular/angular-service.utils.ts +82 -82
- package/assets/client/angular/request-builder.ts +374 -374
- package/assets/client/fetch/fetch-client.utils.ts +52 -52
- package/assets/client/k6/request-builder.js +411 -411
- package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +260 -260
- package/cjs/lib/generators/services/angular-services/angular-service-generator.js +20 -11
- package/cjs/lib/generators/services/angular-services/models.js +1 -0
- package/cjs/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/cjs/lib/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/cjs/lib/generators/services/k6-clients/k6-client-generator.js +6 -6
- package/esm/lib/generators/services/angular-services/angular-service-generator.js +20 -11
- package/esm/lib/generators/services/angular-services/models.js +1 -0
- package/esm/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/esm/lib/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/esm/lib/generators/services/k6-clients/k6-client-generator.js +6 -6
- package/package.json +3 -2
- package/types/lib/generators/services/angular-services/angular-service-generator.d.ts +1 -0
- package/types/lib/generators/services/angular-services/models.d.ts +5 -0
|
@@ -181,12 +181,12 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
|
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
getEndpointMethod(ctx, endpoint) {
|
|
184
|
-
var _a
|
|
184
|
+
var _a;
|
|
185
185
|
const hasParams = this.hasEndpointParams(ctx, endpoint);
|
|
186
186
|
const paramsOptional = !endpoint.parameters.some((p) => p.required) && !((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.required);
|
|
187
187
|
const responseModelType = ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx), { importType: 'type-import' });
|
|
188
188
|
const returnType = ctx.refs.abortablePromise([responseModelType]);
|
|
189
|
-
const accept =
|
|
189
|
+
const accept = this.getEndpointSuccessResponseType(ctx, endpoint);
|
|
190
190
|
const responseType = this.contentTypeToResponseType(accept);
|
|
191
191
|
return ts.method(this.getEndpointMethodName(ctx, endpoint), {
|
|
192
192
|
accessModifier: 'public',
|
|
@@ -228,13 +228,13 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
|
|
|
228
228
|
}
|
|
229
229
|
: null,
|
|
230
230
|
'',
|
|
231
|
-
s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
|
|
232
|
-
this.http.request(rb.build({${s.indent `
|
|
233
|
-
responseType: ${ts.string(responseType)},
|
|
234
|
-
accept: ${ts.string(accept)},
|
|
235
|
-
context,`}
|
|
236
|
-
})),
|
|
237
|
-
{${s.indent `
|
|
231
|
+
s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
|
|
232
|
+
this.http.request(rb.build({${s.indent `
|
|
233
|
+
responseType: ${ts.string(responseType)},
|
|
234
|
+
accept: ${ts.string(accept)},
|
|
235
|
+
context,`}
|
|
236
|
+
})),
|
|
237
|
+
{${s.indent `
|
|
238
238
|
errorResponseTypes: ${ts.object({
|
|
239
239
|
members: [
|
|
240
240
|
...Object.entries(this.getEndpointStatusCodes(ctx, endpoint))
|
|
@@ -243,12 +243,21 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
|
|
|
243
243
|
return ts.property(key, { value: ts.string(value.parser) });
|
|
244
244
|
}),
|
|
245
245
|
],
|
|
246
|
-
})}`}
|
|
247
|
-
}`}
|
|
246
|
+
})}`}
|
|
247
|
+
}`}
|
|
248
248
|
)`,
|
|
249
249
|
], '\n'),
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
+
getEndpointSuccessResponseType(ctx, endpoint) {
|
|
253
|
+
var _a, _b, _c, _d, _e, _f;
|
|
254
|
+
const response = this.getEndpointSuccessResponse(ctx, endpoint);
|
|
255
|
+
if (!response)
|
|
256
|
+
return '*/*';
|
|
257
|
+
if (!ctx.config.defaultSuccessResponseType)
|
|
258
|
+
return (_b = (_a = response.contentOptions[0]) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : '*/*';
|
|
259
|
+
return ((_f = (_d = (_c = response.contentOptions.find((x) => x.type === ctx.config.defaultSuccessResponseType)) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : (_e = response.contentOptions[0]) === null || _e === void 0 ? void 0 : _e.type) !== null && _f !== void 0 ? _f : '*/*');
|
|
260
|
+
}
|
|
252
261
|
getEndpointSuccessResponse(ctx, endpoint) {
|
|
253
262
|
var _a;
|
|
254
263
|
return ((_a = endpoint.responses.find((x) => x.statusCode && x.statusCode >= 200 && x.statusCode < 300)) !== null && _a !== void 0 ? _a : endpoint.responses.find((x) => x.statusCode === undefined));
|
|
@@ -9,6 +9,7 @@ export const defaultTypeScriptAngularServicesGeneratorConfig = {
|
|
|
9
9
|
403: null,
|
|
10
10
|
500: null,
|
|
11
11
|
},
|
|
12
|
+
defaultSuccessResponseType: undefined,
|
|
12
13
|
possibleStatusCodes: [
|
|
13
14
|
100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308,
|
|
14
15
|
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 425,
|
|
@@ -94,15 +94,15 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
94
94
|
],
|
|
95
95
|
returnType: 'this',
|
|
96
96
|
body: appendValueGroup([
|
|
97
|
-
s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
|
|
98
|
-
${ts.string(endpoint.method.toUpperCase())},
|
|
99
|
-
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
100
|
-
async (request) => {${s.indent `
|
|
101
|
-
if (this.stubWrapper.options.rememberRequests) {${s.indent `
|
|
102
|
-
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
103
|
-
}
|
|
104
|
-
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
105
|
-
}`}
|
|
97
|
+
s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
|
|
98
|
+
${ts.string(endpoint.method.toUpperCase())},
|
|
99
|
+
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
100
|
+
async (request) => {${s.indent `
|
|
101
|
+
if (this.stubWrapper.options.rememberRequests) {${s.indent `
|
|
102
|
+
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
103
|
+
}
|
|
104
|
+
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
105
|
+
}`}
|
|
106
106
|
);`,
|
|
107
107
|
'return this;',
|
|
108
108
|
], '\n'),
|
|
@@ -133,7 +133,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
|
|
|
133
133
|
const method = this.getInterfaceEndpointMethod(ctx, endpoint);
|
|
134
134
|
method.accessModifier = 'public';
|
|
135
135
|
method.body = appendValueGroup([
|
|
136
|
-
s `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${s.indent `
|
|
136
|
+
s `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${s.indent `
|
|
137
137
|
.withPath(${ts.string(endpoint.path)})${(b) => b.forEach(endpoint.parameters, (b, p) => {
|
|
138
138
|
switch (p.target) {
|
|
139
139
|
case 'path':
|
|
@@ -143,7 +143,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
|
|
|
143
143
|
b.append(s `\n.withQueryParam(${ts.string(p.name)}, params.${toCasing(p.name, ctx.config.paramNameCasing)})`);
|
|
144
144
|
break;
|
|
145
145
|
}
|
|
146
|
-
})}
|
|
146
|
+
})}
|
|
147
147
|
.build();`}`,
|
|
148
148
|
s `const response = (this.options.fetch ?? fetch)(url, ${ts.object({
|
|
149
149
|
members: [
|
|
@@ -186,7 +186,7 @@ export class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator
|
|
|
186
186
|
],
|
|
187
187
|
}),
|
|
188
188
|
parameters: [ts.constructorParameter('rootUrl'), ts.constructorParameter('defaultK6ParamsFactory')],
|
|
189
|
-
body: s `this.rootUrl = rootUrl;
|
|
189
|
+
body: s `this.rootUrl = rootUrl;
|
|
190
190
|
this._defaultK6ParamsFactory = defaultK6ParamsFactory;`,
|
|
191
191
|
}),
|
|
192
192
|
...ctx.service.endpoints.map((e) => this.getEndpointMethod(ctx, e)),
|
|
@@ -245,11 +245,11 @@ export class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator
|
|
|
245
245
|
}
|
|
246
246
|
: null,
|
|
247
247
|
'',
|
|
248
|
-
s `return /** @type {${returnType}} */ (${s.indent `
|
|
249
|
-
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
250
|
-
accept: ${ts.string(accept)},
|
|
251
|
-
params: this.getK6Params(k6Params),`}
|
|
252
|
-
})`}
|
|
248
|
+
s `return /** @type {${returnType}} */ (${s.indent `
|
|
249
|
+
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
250
|
+
accept: ${ts.string(accept)},
|
|
251
|
+
params: this.getK6Params(k6Params),`}
|
|
252
|
+
})`}
|
|
253
253
|
);`,
|
|
254
254
|
], '\n'),
|
|
255
255
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/typescript",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"repository": "https://github.com/MaSch0212/goast.git",
|
|
5
5
|
"description": "Provides gOAst generators for generating TypeScript code from OpenAPI specifications.",
|
|
6
6
|
"keywords": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@goast/core": "0.3.5",
|
|
31
31
|
"tslib": "2.6.3"
|
|
32
32
|
},
|
|
33
|
+
"packageManager": "pnpm@9.5.0",
|
|
33
34
|
"module": "./esm/index.js",
|
|
34
35
|
"main": "./cjs/index.js",
|
|
35
36
|
"types": "./types/index.d.ts",
|
|
@@ -41,4 +42,4 @@
|
|
|
41
42
|
},
|
|
42
43
|
"./package.json": "./package.json"
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
+
}
|
|
@@ -22,6 +22,7 @@ export declare class DefaultTypeScriptAngularServiceGenerator extends TypeScript
|
|
|
22
22
|
protected getEndpointParamsType(ctx: Context, endpoint: ApiEndpoint): ts.TypeAlias<Builder>;
|
|
23
23
|
protected getClass(ctx: Context): ts.Class<Builder>;
|
|
24
24
|
protected getEndpointMethod(ctx: Context, endpoint: ApiEndpoint): ts.Method<Builder>;
|
|
25
|
+
protected getEndpointSuccessResponseType(ctx: Context, endpoint: ApiEndpoint): string;
|
|
25
26
|
protected getEndpointSuccessResponse(ctx: Context, endpoint: ApiEndpoint): import("@goast/core").ApiResponse | undefined;
|
|
26
27
|
protected getServiceClassName(ctx: Context): string;
|
|
27
28
|
protected getResponseModelName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
@@ -51,6 +51,11 @@ export type TypeScriptAngularServicesGeneratorConfig = TypeScriptGeneratorConfig
|
|
|
51
51
|
parser: 'text' | 'json';
|
|
52
52
|
type: Exclude<ts.Type<TypeScriptFileBuilder>, Function> | ((schemas: readonly ApiSchema[]) => ApiSchema);
|
|
53
53
|
} | null>;
|
|
54
|
+
/**
|
|
55
|
+
* The default content type which is used for the success response. If not defined the first one defined in the OpenApi specification is used.
|
|
56
|
+
* @default undefined
|
|
57
|
+
*/
|
|
58
|
+
defaultSuccessResponseType: Nullable<string>;
|
|
54
59
|
/**
|
|
55
60
|
* The possible status codes that any API endpoint can return.
|
|
56
61
|
* This is only used when `strictResponseTypes` is set to `false`.
|