Skip to content
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

Fixed parsing for Collections. Resolves Breeze/breeze.js#97 #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 25 additions & 6 deletions src/a40_entityMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ var CsdlMetadataParser = (function () {
var dp;
var typeParts = csdlProperty.type.split(".");
// Both tests on typeParts are necessary because of differing metadata conventions for OData and Edmx feeds.
if (typeParts[0] === "Edm" && typeParts.length === 2) {
if (typeParts[0].endsWith("Edm") && typeParts.length === 2) {
dp = parseCsdlSimpleProperty(parentType, csdlProperty, keyNamesOnServer);
} else {
if (isEnumType(csdlProperty, schema)) {
Expand All @@ -912,7 +912,9 @@ var CsdlMetadataParser = (function () {
}

function parseCsdlSimpleProperty(parentType, csdlProperty, keyNamesOnServer) {
var dataType = DataType.fromEdmDataType(csdlProperty.type);
var isCollectionType = isCollection(csdlProperty.type);
var propertyType = getCollectionType(csdlProperty.type) || csdlProperty.type;
var dataType = DataType.fromEdmDataType(propertyType);
if (dataType == null) {
parentType.warnings.push("Unable to recognize DataType for property: " + csdlProperty.name + " DateType: " + csdlProperty.type);
return null;
Expand All @@ -936,6 +938,7 @@ var CsdlMetadataParser = (function () {
dataType: dataType,
isNullable: isNullable,
isPartOfKey: isPartOfKey,
isScalar: !isCollectionType,
maxLength: maxLength,
defaultValue: csdlProperty.defaultValue,
// fixedLength: fixedLength,
Expand All @@ -948,17 +951,31 @@ var CsdlMetadataParser = (function () {
return dp;
}

var RX_COLLECTION = /Collection\((?<type>.*)\)/;

function isCollection(propertyType) {
return RX_COLLECTION.test(propertyType);
}

function getCollectionType(propertyType) {
var match = propertyType.match(RX_COLLECTION);
return match ? match.groups.type : null;
}

function parseCsdlComplexProperty(parentType, csdlProperty, schema) {

// Complex properties are never nullable ( per EF specs)
// var isNullable = csdlProperty.nullable === 'true' || csdlProperty.nullable == null;
// var complexTypeName = csdlProperty.type.split("Edm.")[1];
var complexTypeName = parseTypeNameWithSchema(csdlProperty.type, schema).typeName;
var isCollectionType = isCollection(csdlProperty.type);
var propertyType = getCollectionType(csdlProperty.type) || csdlProperty.type;
var complexTypeName = parseTypeNameWithSchema(propertyType, schema).typeName;
// can't set the name until we go thru namingConventions and these need the dp.
var dp = new DataProperty({
nameOnServer: csdlProperty.name,
complexTypeName: complexTypeName,
isNullable: false
isNullable: false,
isScalar: !isCollectionType
});

return dp;
Expand Down Expand Up @@ -1025,7 +1042,8 @@ var CsdlMetadataParser = (function () {

function isEdmxEnumType(csdlProperty, schema) {
var enumTypes = __toArray(schema.enumType);
var typeParts = csdlProperty.type.split(".");
var propertyType = getCollectionType(csdlProperty.type) || csdlProperty.type;
var typeParts = propertyType.split(".");
var baseTypeName = typeParts[typeParts.length - 1];
return enumTypes.some(function (enumType) {
return enumType.name === baseTypeName;
Expand All @@ -1036,7 +1054,8 @@ var CsdlMetadataParser = (function () {
var enumTypes = schema.extensions.filter(function (ext) {
return ext.name === "EnumType";
});
var typeParts = csdlProperty.type.split(".");
var propertyType = getCollectionType(csdlProperty.type) || csdlProperty.type;
var typeParts = propertyType.split(".");
var baseTypeName = typeParts[typeParts.length - 1];
return enumTypes.some(function (enumType) {
return enumType.attributes.some(function (attr) {
Expand Down