Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,13 @@ export default class AttributeApplicationValidator implements AstValidator<Attri

@check('@uuid')
private _checkUuid(attr: AttributeApplication, accept: ValidationAcceptor) {
const version = getNumberLiteral(attr.args[0]?.value);
const versionArg = attr.args.find((arg) => 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 });
}
}

Expand Down
44 changes: 44 additions & 0 deletions packages/language/test/attribute-application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading