From 276a20f2bcaa219206f24bb4047882d41d85bc0e Mon Sep 17 00:00:00 2001 From: Like Zhu Date: Fri, 25 Jun 2021 12:28:31 -0700 Subject: [PATCH] EDM path works --- packages/odata/src/cli/odata-gen.js | 6 ++---- packages/odata/src/edm/schema-plugin.js | 6 ++---- packages/odata/src/edm/types-plugin.js | 4 +++- packages/odata/src/schema/export-schema-model.js | 6 ++++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/odata/src/cli/odata-gen.js b/packages/odata/src/cli/odata-gen.js index 59e9587..52a4c3c 100644 --- a/packages/odata/src/cli/odata-gen.js +++ b/packages/odata/src/cli/odata-gen.js @@ -27,11 +27,9 @@ const { defineConstProperty } = require('../edm/reflection'); const rootPropertyName = 'Customers'; const rootPropertyModelName = 'Model/McaCustomer'; - const mappedModel = {}; - Object.keys(model || {}).forEach(key => { const schema = model[key]; - mappedModel[key] = { + model[key] = { ...schema, $$ref: key, }; @@ -55,7 +53,7 @@ const { defineConstProperty } = require('../edm/reflection'); ], }, }, - ...mappedModel, + ...model, }, }); diff --git a/packages/odata/src/edm/schema-plugin.js b/packages/odata/src/edm/schema-plugin.js index bd5fa4c..9066cbe 100644 --- a/packages/odata/src/edm/schema-plugin.js +++ b/packages/odata/src/edm/schema-plugin.js @@ -145,8 +145,7 @@ module.exports = (edm, { Object.keys(acts[key].Parameter || {}).forEach(k => { const parameter = acts[key].Parameter[k]; - // eslint-disable-next-line no-param-reassign - acts[key].Parameter[k] = getTypeName([], parameter); + parameters[k] = getTypeName([], parameter); }); actions.push(new ActionType({ @@ -163,8 +162,7 @@ module.exports = (edm, { Object.keys(funcs[key].Parameter || {}).forEach(k => { const param = funcs[key].Parameter[k]; - // eslint-disable-next-line no-param-reassign - funcs[key].Parameter[k] = getTypeName([], param); + parameters[k] = getTypeName([], param); }); functions.push(new FunctionType({ diff --git a/packages/odata/src/edm/types-plugin.js b/packages/odata/src/edm/types-plugin.js index 667dab5..7e3574a 100644 --- a/packages/odata/src/edm/types-plugin.js +++ b/packages/odata/src/edm/types-plugin.js @@ -260,7 +260,7 @@ module.exports = edm => { defineConstProperty(this, 'properties', compileProperties.call(this, properties)); defineConstProperty(this, 'navigationPropertyNames', navigationPropertyNames.slice()); - defineProducedProperty(this, 'navigationProperties', () => _.pick(this.properties, (property, propertyName) => _.contains(this.navigationPropertyNames, propertyName))); + defineProducedProperty(this, 'navigationProperties', () => _.pickBy(this.properties, (property, propertyName) => _.includes(this.navigationPropertyNames, propertyName))); if (baseTypeName) { defineConstProperty(this, 'baseTypeName', baseTypeName); defineProducedProperty(this, 'baseType', () => resolveType(this.baseTypeName, this.namespace)); @@ -402,6 +402,8 @@ module.exports = edm => { const { typeName } = parameters[name]; ret[name] = new Parameter({ name, namespace, typeName }); }); + + return ret; } /** diff --git a/packages/odata/src/schema/export-schema-model.js b/packages/odata/src/schema/export-schema-model.js index 96092dd..2002bdb 100644 --- a/packages/odata/src/schema/export-schema-model.js +++ b/packages/odata/src/schema/export-schema-model.js @@ -60,7 +60,8 @@ function replacer(schema, model) { if (key === '$ref') { if (!urlRegex.test(refSchemaName)) { // eslint-disable-next-line no-proto - extension.__proto__ = model[refSchemaName]; + // extension.__proto__ = model[refSchemaName]; + Object.setPrototypeOf(extension, model[refSchemaName]); } if (/^Model\//.test(refSchemaName)) { extension.schema = model[refSchemaName]; @@ -82,9 +83,10 @@ function replacer(schema, model) { if (_.isArray(schema)) { return schema; } + return Object.assign( - schema, extension, + schema, ); }