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

Invalid variableName in IriTemplateMapping breaks API #27

Open
mchlrch opened this issue Sep 4, 2018 · 0 comments
Open

Invalid variableName in IriTemplateMapping breaks API #27

mchlrch opened this issue Sep 4, 2018 · 0 comments

Comments

@mchlrch
Copy link
Member

mchlrch commented Sep 4, 2018

I have a generated Hydra API description that contains a variable with an invalid variable-name 0he.

On startup, hydra routes get created sucessfully, no errors. Some parts of the API can be called successfully, while others fail with HTTP 500. Interesting is, that besides the part where the invalid variable-name is used, also not directly related parts are failing.

I propose to:

  • investigate why not directly related parts are failing
  • consider validating the API description on startup, in order to fail fast

Following are the steps to reproduce:

Software under test: https://github.com/statistikstadtzuerich/stat.stadt-zuerich.ch

  • branch: testcases4stack
  • commit: bc3a655d24a50e223bb2df1e231fedcfe1766ea0

Start the API Backend:

$ npm run start-apidev

Without any modifications to the source, the Shape-API only contains one Dataset (BEW-RAUM-ZEIT-HEL). The API description is in the folder api_apidev.

Let's hit the API with curl:

$ curl -s -i -H "accept:application/ld+json" http://localhost:8080/dataset/BEW-RAUM-ZEIT-HEL | head -1
HTTP/1.1 200 OK

In order to be able to update the API afterwards, setting the password for the SPARQL Endpoint as environment variable is necessary. Endpoint and user are defined in api-config.apidev.js.

$ export SPARQL_ENDPOINT_PASSWORD=foopass!_987

Now we will add Dataset BES-RAUM-ZEIT-0-0HE-BE to the API. Activate BES-RAUM-ZEIT-0-0HE-BE in the WHITELISTING viewFilter, in the configuration-file api-config.apidev.js and update the API with the following command. The Shape-API will be generated for all Datasets matching the viewFilter.

$ npm run update-api-apidev
$ ls -w1 api_apidev
api.jsonld
BES-RAUM-ZEIT-0-0HE-BE-shape.sparql.es6
BES-RAUM-ZEIT-0-0HE-BE-slice.sparql.es6
BEW-RAUM-ZEIT-HEL-shape.sparql.es6
BEW-RAUM-ZEIT-HEL-slice.sparql.es6
shape.context.jsonld
slice.context.jsonld

Restart the backend:

$ npm run start-apidev
...
loading: hydraBox
IriTemplate route: /dataset/{?dimension,topic,attributeValue,location,time,other}
IriTemplate route: /tags/{?query,dimension,topic,attributeValue,other}
IriTemplate route: /dataset/BES-RAUM-ZEIT-0-0HE-BE/slice{?0he,be,from,to,other}
IriTemplate route: /dataset/BEW-RAUM-ZEIT-HEL/slice{?hel,raum,from,to,other}
HydraView route: (get) /dataset/
HydraView route: (get) /dataset/BES-RAUM-ZEIT-0-0HE-BE/slice
HydraView route: (get) /dataset/BES-RAUM-ZEIT-0-0HE-BE
HydraView route: (get) /dataset/BEW-RAUM-ZEIT-HEL/slice
HydraView route: (get) /dataset/BEW-RAUM-ZEIT-HEL
HydraView route: (get) /tags/
...

No errors on startup. Hit the API again with curl:

$ curl -s -i -H "accept:application/ld+json" http://localhost:8080/dataset/BEW-RAUM-ZEIT-HEL | head -1
HTTP/1.1 500 Internal Server Error

Stacktrace:

SyntaxError: Invalid or unexpected token
    at Function (<anonymous>)
    at Function.evalTemplateString (/home/mira/git/stat.stadt-zuerich.ch/node_modules/hydra-box/lib/SparqlView.js:90:22)
    at SparqlView._handle (/home/mira/git/stat.stadt-zuerich.ch/node_modules/hydra-box/lib/SparqlView.js:41:30)
    at Layer.handle [as handle_request] (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/layer.js:95:5)
    at /home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/index.js:335:12)
    at next (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/index.js:275:10)
    at next (/home/mira/git/stat.stadt-zuerich.ch/node_modules/express/lib/router/route.js:127:14)
    at tryCatcher (/home/mira/git/stat.stadt-zuerich.ch/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/mira/git/stat.stadt-zuerich.ch/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/mira/git/stat.stadt-zuerich.ch/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/mira/git/stat.stadt-zuerich.ch/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/mira/git/stat.stadt-zuerich.ch/node_modules/bluebird/js/release/promise.js:693:18)

Other parts of the API still work:

$ curl -s -i -H "accept:application/ld+json" http://localhost:8080/dataset/ | head -1
HTTP/1.1 200 OK

The culprit seems to be in api_apidev/api.jsonld. If I remove the following snippet, the aforementioned API call doesn't fail anymore:

{
    "@type": "IriTemplateMapping",
    "variable": "0he",
    "property": "https://stat.stadt-zuerich.ch/schema/dataset/BES-RAUM-ZEIT-0-0HE-BE/property/0HE"
},

Notice, that we call the API for BEW-RAUM-ZEIT-HEL, whereas the problem comes in with BES-RAUM-ZEIT-0-0HE-BE, a different dataset.

I guess that with the respective API calls, also the following two occurrences of the variable 0he would cause failure. I didn't try it out though:

in api.jsonld:

"template": "/dataset/BES-RAUM-ZEIT-0-0HE-BE/slice{?0he,be,from,to,other}"

in BES-RAUM-ZEIT-0-0HE-BE-slice.sparql.es6:

${typeof 0he !== 'undefined' ? 'FILTER (?0heNotation IN (' + (0he.join ? 0he.map(v => v.toCanonical()).join() : 0he.toCanonical()) + '))' : ''}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants