@goast/typescript 0.3.8 → 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/cjs/lib/generators/services/angular-services/angular-service-generator.js +11 -2
- package/cjs/lib/generators/services/angular-services/models.js +1 -0
- package/esm/lib/generators/services/angular-services/angular-service-generator.js +11 -2
- package/esm/lib/generators/services/angular-services/models.js +1 -0
- package/package.json +1 -1
- 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
|
@@ -184,12 +184,12 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
|
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
getEndpointMethod(ctx, endpoint) {
|
|
187
|
-
var _a
|
|
187
|
+
var _a;
|
|
188
188
|
const hasParams = this.hasEndpointParams(ctx, endpoint);
|
|
189
189
|
const paramsOptional = !endpoint.parameters.some((p) => p.required) && !((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.required);
|
|
190
190
|
const responseModelType = ast_1.ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx), { importType: 'type-import' });
|
|
191
191
|
const returnType = ctx.refs.abortablePromise([responseModelType]);
|
|
192
|
-
const accept =
|
|
192
|
+
const accept = this.getEndpointSuccessResponseType(ctx, endpoint);
|
|
193
193
|
const responseType = this.contentTypeToResponseType(accept);
|
|
194
194
|
return ast_1.ts.method(this.getEndpointMethodName(ctx, endpoint), {
|
|
195
195
|
accessModifier: 'public',
|
|
@@ -252,6 +252,15 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
|
|
|
252
252
|
], '\n'),
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
+
getEndpointSuccessResponseType(ctx, endpoint) {
|
|
256
|
+
var _a, _b, _c, _d, _e, _f;
|
|
257
|
+
const response = this.getEndpointSuccessResponse(ctx, endpoint);
|
|
258
|
+
if (!response)
|
|
259
|
+
return '*/*';
|
|
260
|
+
if (!ctx.config.defaultSuccessResponseType)
|
|
261
|
+
return (_b = (_a = response.contentOptions[0]) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : '*/*';
|
|
262
|
+
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 : '*/*');
|
|
263
|
+
}
|
|
255
264
|
getEndpointSuccessResponse(ctx, endpoint) {
|
|
256
265
|
var _a;
|
|
257
266
|
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));
|
|
@@ -12,6 +12,7 @@ exports.defaultTypeScriptAngularServicesGeneratorConfig = {
|
|
|
12
12
|
403: null,
|
|
13
13
|
500: null,
|
|
14
14
|
},
|
|
15
|
+
defaultSuccessResponseType: undefined,
|
|
15
16
|
possibleStatusCodes: [
|
|
16
17
|
100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308,
|
|
17
18
|
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 425,
|
|
@@ -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',
|
|
@@ -249,6 +249,15 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
|
|
|
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,
|
package/package.json
CHANGED
|
@@ -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`.
|