diff --git a/packages/language/src/validators/attribute-application-validator.ts b/packages/language/src/validators/attribute-application-validator.ts index 17d1b9904..cdb0ed969 100644 --- a/packages/language/src/validators/attribute-application-validator.ts +++ b/packages/language/src/validators/attribute-application-validator.ts @@ -463,9 +463,13 @@ export default class AttributeApplicationValidator implements AstValidator arg.$resolvedParam?.name === 'version'); + if (!versionArg) { + return; + } + const version = getNumberLiteral(versionArg.value); if (version !== undefined && version !== 4 && version !== 7) { - accept('error', `\`@uuid\` version must be \`4\` or \`7\``, { node: attr.args[0]! }); + accept('error', `\`@uuid\` version must be \`4\` or \`7\``, { node: versionArg }); } } diff --git a/packages/language/test/attribute-application.test.ts b/packages/language/test/attribute-application.test.ts index 190e4096f..9abe8ffe9 100644 --- a/packages/language/test/attribute-application.test.ts +++ b/packages/language/test/attribute-application.test.ts @@ -661,6 +661,50 @@ describe('Attribute application validation tests', () => { /`@uuid` version must be `4` or `7`/, ); }); + + it('resolves the version arg by name regardless of argument order', async () => { + await loadSchema( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid', version: 7) + } + `, + ); + + await loadSchemaWithError( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid', version: 1) + } + `, + /`@uuid` version must be `4` or `7`/, + ); + }); + + it('does not treat a message-only arg as a version', async () => { + await loadSchema( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + model User { + id String @id @uuid(message: 'invalid uuid') + } + `, + ); + }); }); describe('Native type mapping attributes', () => {