marklogic / entity-services

Data modeling and code scaffolding for data integration in MarkLogic
https://docs.marklogic.com/guide/entity-services
Apache License 2.0
7 stars 10 forks source link

Syntax error in version translate for property that is an internal reference #351

Closed bsrikan closed 7 years ago

bsrikan commented 7 years ago

For a property say "hasCustomerID" that is an internal ref in model2, version translator produces a syntax error on deploying the artifact.

Model1:

 "hasProductID":{  
               "datatype":"integer"
            }

Model2:

"hasCustomerID": {
          "$ref": "#/definitions/Customer"
        }

Code in version translator that produces syntax err:

let $hasCustomerID := $source-node/hasCustomerID ! es:init-instance(?, 'Customer')
=>es:with-namespace('http://marklogic.com/customer','cust')(.)

expected: let $hasCustomerID := $source-node/hasCustomerID ! $extract-reference-Customer(.)

grechaw commented 7 years ago

I'm in this code right now fixing issue #349 so I'll try to get it snuck in at this late stage. Not good to ship a syntax error.

grechaw commented 7 years ago

I see now why I hit this error. the partial function is not composable with the es:with-namespace expression in the way I would have expected. interesting. I need to look more closely at your expected value though...

bsrikan commented 7 years ago

Ok. I mentioned it so, since that version worked for me. But you are right, please check for other scenarios too.

grechaw commented 7 years ago

This particular property is hitting the 'reference from scalar' logic. The expected value needs to be its own function, which could go in a variable or inline. Here's the inline version:


    let $hasCustomerID := $source-node/hasCustomerID ! function($src-node) {
       es:init-instance($src-node, 'Customer')
       =>es:with-namespace('http://y','y')}(.)
bsrikan commented 7 years ago

Test in e2e verified this bug and is working as expected. Shipping.