Skip to content

[Backport 8.18] Enforce globally unique type names #4379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions compiler/src/steps/validate-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
return ep.request != null && ep.response != null
}

// Check that all type names are unique
validateUniqueTypeNames(apiModel, modelError)

// Validate all endpoints. We start by those that are ready for validation so that transitive validation of common
// data types is associated with these endpoints and their errors are not filtered out in the error report.
apiModel.endpoints.filter(ep => readyForValidation(ep)).forEach(validateEndpoint)
Expand All @@ -204,6 +207,63 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma

// -----------------------------------------------------------------------------------------------

/**
* Validates that all type names in the model are unique
*/
function validateUniqueTypeNames (apiModel: model.Model, modelError: (msg: string) => void): void {
const existingDuplicates: Record<string, string[]> = {
Action: ['indices.modify_data_stream', 'indices.update_aliases', 'watcher._types'],
Actions: ['ilm._types', 'security.put_privileges', 'watcher._types'],
ComponentTemplate: ['cat.component_templates', 'cluster._types'],
Context: ['_global.get_script_context', '_global.search._types', 'nodes._types'],
DatabaseConfigurationMetadata: ['ingest.get_geoip_database', 'ingest.get_ip_location_database'],
Datafeed: ['ml._types', 'xpack.usage'],
Destination: ['_global.reindex', 'transform._types'],
Feature: ['features._types', 'indices.get', 'xpack.info'],
Features: ['indices.get', 'xpack.info'],
Filter: ['_global.termvectors', 'ml._types'],
IndexingPressure: ['cluster.stats', 'indices._types', 'nodes._types'],
IndexingPressureMemory: ['cluster.stats', 'indices._types', 'nodes._types'],
Ingest: ['ingest._types', 'nodes._types'],
MigrationFeature: ['migration.get_feature_upgrade_status', 'migration.post_feature_upgrade'],
Operation: ['_global.mget', '_global.mtermvectors'],
Phase: ['ilm._types', 'xpack.usage'],
Phases: ['ilm._types', 'xpack.usage'],
Pipeline: ['ingest._types', 'logstash._types'],
Policy: ['enrich._types', 'ilm._types', 'slm._types'],
RequestItem: ['_global.msearch', '_global.msearch_template'],
ResponseItem: ['_global.bulk', '_global.mget', '_global.msearch'],
RoleMapping: ['security._types', 'xpack.usage'],
RuntimeFieldTypes: ['cluster.stats', 'xpack.usage'],
ShardsStats: ['indices.field_usage_stats', 'snapshot._types'],
ShardStats: ['ccr._types', 'indices.stats'],
Source: ['_global.reindex', 'transform._types'],
Token: ['_global.termvectors', 'security.authenticate', 'security.create_service_token', 'security.enroll_kibana']
}

// collect namespaces for each type name
const typeNames = new Map<string, string[]>()
for (const type of apiModel.types) {
const name = type.name.name
if (name !== 'Request' && name !== 'Response' && name !== 'ResponseBase') {
const namespaces = typeNames.get(name) ?? []
namespaces.push(type.name.namespace)
typeNames.set(name, namespaces)
}
}

// check for duplicates
for (const [name, namespaces] of typeNames) {
if (namespaces.length > 1) {
const allowedDuplicates = existingDuplicates[name] ?? []
const hasUnexpectedDuplicate = namespaces.some(ns => !allowedDuplicates.includes(ns))
if (hasUnexpectedDuplicate) {
modelError(`${name} is present in multiple namespaces: ${namespaces.sort().join(' and ')}`)
}
}
}
}

/**
* Validate an endpoint
*/
Expand Down
4 changes: 2 additions & 2 deletions output/schema/schema-serverless.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions output/schema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions specification/watcher/_types/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ export class HttpInputRequestDefinition {
scheme?: ConnectionScheme
url?: string
}

export class Input {}

/**
* @variants container
*/
Expand Down