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 @@ -5,6 +5,7 @@ import {
isDataModel,
isStringLiteral,
ReferenceExpr,
isEnum,
} from '@zenstackhq/language/ast';
import { getLiteral, getModelIdFields, getModelUniqueFields } from '@zenstackhq/sdk';
import { AstNode, DiagnosticInfo, getDocument, ValidationAcceptor } from 'langium';
Expand Down Expand Up @@ -61,8 +62,13 @@ export default class DataModelValidator implements AstValidator<DataModel> {
if (idField.type.optional) {
accept('error', 'Field with @id attribute must not be optional', { node: idField });
}
if (idField.type.array || !idField.type.type || !SCALAR_TYPES.includes(idField.type.type)) {
accept('error', 'Field with @id attribute must be of scalar type', { node: idField });

const isArray = idField.type.array;
const isScalar = SCALAR_TYPES.includes(idField.type.type as typeof SCALAR_TYPES[number])
const isValidType = isScalar || isEnum(idField.type.reference?.ref)

if (isArray || !isValidType) {
accept('error', 'Field with @id attribute must be of scalar or enum type', { node: idField });
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/tests/schema/stdlib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Stdlib Tests', () => {
}`
);
}
throw new SchemaLoadingError(validationErrors.map((e) => e.message));
throw new SchemaLoadingError(validationErrors);
}
});
});
Loading