ng-openapi-gen
Version:
An OpenAPI 3.0 and 3.1 codegen for Angular 16+
55 lines • 2.3 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) {
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 => {
// Import the variant fn
this.addImport(variant);
// Import the variant parameters
this.addImport(variant.paramsImport);
// Import the variant result type
this.collectImports(variant.successResponse?.spec?.schema);
// Add the request body additional dependencies
this.collectImports(variant.requestBody?.spec?.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 resp.content ?? []) {
this.collectImports(content.spec?.schema, true);
}
}
// Security schemes don't have schemas to import in newer OpenAPI versions
// 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