openmeter / api /spec /packages /aip /lib /rules /operation-id.js
Leon4gr45's picture
Upload folder using huggingface_hub
048b1e8 verified
Raw
History Blame Contribute Delete
994 Bytes
import { createRule, paramMessage } from '@typespec/compiler'
import { isKebabCase } from './utils.js'
export const operationIdKebabCaseRule = createRule({
name: 'operation-id-kebab-case',
severity: 'error',
description: 'Ensure @operationId values are in kebab-case.',
messages: {
default: paramMessage`The operationId "${'operationId'}" should be in kebab-case.`,
},
create: (context) => ({
operation: (node) => {
const operationIdDecorator = node.decorators.find(
(d) => d.decorator.name === '$operationId',
)
if (operationIdDecorator) {
const operationId = operationIdDecorator.args[0]?.jsValue
if (
operationId &&
typeof operationId === 'string' &&
!isKebabCase(operationId)
) {
context.reportDiagnostic({
format: {
operationId,
},
target: node,
messageId: 'default',
})
}
}
},
}),
})