in packages/extensions/modelerfour/src/prenamer/prenamer.ts [78:258]
process() {
if (this.options["prenamer"] === false) {
return this.codeModel;
}
const deduplicateSchemaNames =
!!this.options["lenient-model-deduplication"] || !!this.options["resolve-schema-name-collisons"];
const scopeNamer = new ScopeNamer(this.session, {
deduplicateNames: deduplicateSchemaNames,
overrides: this.format.override,
});
// choice
this.processChoiceNames(this.codeModel.schemas.choices, scopeNamer);
// sealed choice
this.processChoiceNames(this.codeModel.schemas.sealedChoices, scopeNamer);
// constant
for (const schema of values(this.codeModel.schemas.constants)) {
this.namingService.setName(schema, this.format.constant, `Constant${this.enum++}`, this.format.override);
}
// strings
for (const schema of values(this.codeModel.schemas.strings)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
// number
for (const schema of values(this.codeModel.schemas.numbers)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.dates)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.dateTimes)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.durations)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.uuids)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.uris)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.unixtimes)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
if (isUnassigned(schema.language.default.description)) {
schema.language.default.description = "date in seconds since 1970-01-01T00:00:00Z.";
}
}
for (const schema of values(this.codeModel.schemas.byteArrays)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.chars)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.booleans)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
for (const schema of values(this.codeModel.schemas.flags)) {
this.namingService.setName(schema, this.format.type, schema.type, this.format.override);
}
// dictionary
for (const schema of values(this.codeModel.schemas.dictionaries)) {
this.namingService.setName(
schema,
this.format.type,
`DictionaryOf${schema.elementType.language.default.name}`,
this.format.override,
);
if (isUnassigned(schema.language.default.description)) {
schema.language.default.description = `Dictionary of ${schema.elementType.language.default.name}`;
}
}
for (const schema of values(this.codeModel.schemas.arrays)) {
this.namingService.setName(
schema,
this.format.type,
`ArrayOf${schema.elementType.language.default.name}`,
this.format.override,
);
if (isUnassigned(schema.language.default.description)) {
schema.language.default.description = `Array of ${schema.elementType.language.default.name}`;
}
}
for (const schema of values(this.codeModel.schemas.objects)) {
scopeNamer.add(schema, this.format.type, "");
const propertyScopeName = new ScopeNamer(this.session, {
deduplicateNames: false,
overrides: this.format.override,
});
for (const property of values(schema.properties)) {
propertyScopeName.add(property, this.format.property, "");
}
propertyScopeName.process();
}
for (const schema of values(this.codeModel.schemas.groups)) {
scopeNamer.add(schema, this.format.type, "");
for (const property of values(schema.properties)) {
this.namingService.setName(property, this.format.property, "", this.format.override);
}
}
for (const parameter of values(this.codeModel.globalParameters)) {
if (parameter.schema.type === SchemaType.Constant) {
this.namingService.setName(parameter, this.format.constantParameter, "", this.format.override);
} else {
this.namingService.setName(parameter, this.format.parameter, "", this.format.override);
}
}
for (const operationGroup of this.codeModel.operationGroups) {
this.namingService.setNameAllowEmpty(
operationGroup,
this.format.operationGroup,
operationGroup.$key,
this.format.override,
{
removeDuplicates: false,
},
);
const operationScopeNamer = new ScopeNamer(this.session, {
overrides: this.format.override,
});
for (const operation of operationGroup.operations) {
operationScopeNamer.add(operation, this.format.operation, "");
this.setParameterNames(operation);
for (const request of values(operation.requests)) {
this.setParameterNames(request);
}
for (const response of values(operation.responses)) {
this.setResponseHeaderNames(response);
}
for (const response of values(operation.exceptions)) {
this.setResponseHeaderNames(response);
}
const p = operation.language.default.paging;
if (p) {
p.group = p.group ? this.format.operationGroup(p.group, true, this.format.override) : undefined;
p.member = p.member ? this.format.operation(p.member, true, this.format.override) : undefined;
}
}
operationScopeNamer.process();
}
scopeNamer.process();
// set a styled client name
this.namingService.setName(this.codeModel, this.format.client, this.codeModel.info.title, this.format.override);
// fix collisions from flattening on ObjectSchemas
this.fixPropertyCollisions();
// fix collisions from flattening on VirtualParameters
this.fixParameterCollisions();
return this.codeModel;
}