Projections and snippets
ContentSettings
Configuration settings for content generators in the SKMTC DSL system.
ContentSettings encapsulates the configuration needed by generators to produce content, including where to export the generated files, how to identify the content, and any custom enrichment data for extending the generation process.
This class is used by ModelProjectionBase and OasOperationProjectionBase to configure their generation behavior, providing a consistent interface for generator settings across the system.
Key Features
- Export Path Management: Specifies where generated content should be written
- Identifier Integration: Links content to specific identifiers for naming
- Enrichment Support: Allows custom data to extend generation capabilities
- Type Safety: Generic enrichment typing for compile-time validation
Signature
import { ContentSettings } from '@skmtc/core'
class ContentSettings<EnrichmentType = undefined>The type of enrichment data (default: undefined)
Examples
import { ContentSettings, normalizeWorkspacePath } from '@skmtc/core';
import { createType } from '@skmtc/lang-typescript';
const settings = ContentSettings.empty({
exportPath: normalizeWorkspacePath('./src/generated/models.ts'),
identifier: createType('UserModels')
});
console.log(settings.exportPath); // '@/src/generated/models.ts'
console.log(settings.enrichments); // undefinedtype ValidationEnrichment = {
validateRequired: boolean;
generateComments: boolean;
customValidators: string[];
};
const enrichedSettings = new ContentSettings({
identifier: createType('ValidatedModels'),
exportPath: normalizeWorkspacePath('./src/models/validated.ts'),
enrichments: {
validateRequired: true,
generateComments: true,
customValidators: ['email', 'phone']
}
});
// Access enrichment data in generators
if (enrichedSettings.enrichments?.validateRequired) {
// Generate validation logic
}class ValidatedModelGenerator extends ModelProjectionBase<ValidationEnrichment> {
constructor(args) {
super({
...args,
settings: new ContentSettings({
identifier: createType(args.refName),
exportPath: normalizeWorkspacePath('./src/validated-models.ts'),
enrichments: {
validateRequired: true,
generateComments: false,
customValidators: []
}
})
});
}
toDefinition(): Definition {
const validation = this.settings.enrichments?.validateRequired
? this.generateValidation()
: '';
return new Definition({
context: this.context,
identifier: this.settings.identifier,
value: {
generatorKey: this.generatorKey,
content: `${this.generateInterface()}${validation}`
}
});
}
}Constructor
constructor
constructor(args: CreateArgs<EnrichmentType>)Creates a new ContentSettings instance with enrichments.
Settings configuration
The identifier for the content being generated
The path where generated content will be exported
Custom enrichment data for extending generation
Operation variant name ('main' for variants-unaware Projections)
Properties
The identifier for the content being generated
The path where generated content will be exported, normalized (normalizeWorkspacePath): it finds its file without being normalized again.
Custom enrichment data for extending generation
Operation variant this content belongs to. Carries the variant name threaded from the engine's per-operation dispatch through the Driver into this Projection. 'main' for variants-unaware operation generators and for model Projections.
The identifiers that lead from the file's Index to the Index this content's definition sits in. Absent or empty at the file level. Optional so settings written as plain objects stay valid.
Methods
ContentSettings.empty
ContentSettings.empty(args: EmptyArgs): ContentSettings<undefined>Factory method to create ContentSettings without enrichments.
This is a convenience method for creating ContentSettings when no custom enrichment data is needed. It explicitly sets enrichments to undefined and returns a properly typed instance.
Basic settings arguments
The identifier for the content being generated
The path where generated content will be exported
ContentSettings instance with undefined enrichments