ng-openapi-gen
Version:
An OpenAPI 3 codegen for Angular 12+
57 lines • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Service = void 0;
const gen_type_1 = require("./gen-type");
const gen_utils_1 = require("./gen-utils");
/**
* Context to generate a service
*/
class Service extends gen_type_1.GenType {
constructor(tag, operations, options) {
var _a, _b;
super(tag.name, gen_utils_1.serviceClass, options);
this.operations = operations;
// Angular standards demand that services have a period separating them
if (this.fileName.endsWith('-service')) {
this.fileName = this.fileName.substring(0, this.fileName.length - '-service'.length) + '.service';
}
this.tsComments = (0, gen_utils_1.tsComments)(tag.description || '', 0);
// Collect the imports
for (const operation of operations) {
operation.variants.forEach(variant => {
var _a, _b, _c, _d;
// Import the variant fn
this.addImport(variant);
// Import the variant parameters
this.addImport(variant.paramsImport);
// Import the variant result type
this.collectImports((_b = (_a = variant.successResponse) === null || _a === void 0 ? void 0 : _a.spec) === null || _b === void 0 ? void 0 : _b.schema);
// Add the request body additional dependencies
this.collectImports((_d = (_c = variant.requestBody) === null || _c === void 0 ? void 0 : _c.spec) === null || _d === void 0 ? void 0 : _d.schema, true);
});
// Add the parameters as additional dependencies
for (const parameter of operation.parameters) {
this.collectImports(parameter.spec.schema, true);
}
// Add the responses imports as additional dependencies
for (const resp of operation.allResponses) {
for (const content of (_a = resp.content) !== null && _a !== void 0 ? _a : []) {
this.collectImports((_b = content.spec) === null || _b === void 0 ? void 0 : _b.schema, true);
}
}
// Add the security group imports
for (const securityGroup of operation.security) {
securityGroup.forEach(security => this.collectImports(security.spec.schema));
}
}
this.updateImports();
}
skipImport() {
return false;
}
initPathToRoot() {
return '../';
}
}
exports.Service = Service;
//# sourceMappingURL=service.js.map