I'm trying to refactor some JSONSchema checks to include one schema in another using a $ref include.
As I'm using AJV for validation of the schemas, I've been trying to use the addSchema function to load the two schemas but I keep getting the error schema should be object or boolean but as far as I know I've defined the schema correctly.
My JS code reads as:
var Ajv = require('ajv');
var ajv = new Ajv({ allErrors: 'true', verbose: 'true' });
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
ajv.addSchema('../../schema/sport_schema/tennis_sport_schema.json', 'tennis_sport_schema.json');
ajv.addSchema('../../schema/sport_schema/tennis_event_schema.json', 'tennis_event_schema.json');
The schema tennis_sport_schema.json looks like this:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Tennis Sport endpoint schema",
"description": "The Tennis Sport endpoint for Sport API",
"required": ["offset", "limit", "hasNext", "hasPrevious", "items"],
"type": "object",
"properties": {
"offset": {
"type": "number",
"const": 0
},
"limit": {
"type": "number",
"const": 20
},
"hasNext": {
"type": "boolean",
"const": true
},
"hasPrevious": {
"type": "boolean",
"const": false
},
"items": {
"type": "array",
"minItems": 1,
"maxItems": 20,
"items": {
"$ref": "tennis_event_schema.json"
}
}
}
}
Error output is:
mocha "test/sport_tests/tennis_schema.js"
/Users/framps01/Workspace/sport-store-test-framework/node_modules/ajv/lib/ajv.js:300
throw new Error('schema should be object or boolean');
^
Error: schema should be object or boolean
at Ajv._addSchema (/Users/framps01/Workspace/sport-store-test-framework/node_modules/ajv/lib/ajv.js:300:15)
at Ajv.addSchema (/Users/framps01/Workspace/sport-store-test-framework/node_modules/ajv/lib/ajv.js:136:31)
at Object.<anonymous> (/Users/framps01/Workspace/sport-store-test-framework/test/sport_tests/tennis_schema.js:4:5)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at /Users/framps01/Workspace/sport-store-test-framework/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/Users/framps01/Workspace/sport-store-test-framework/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/Users/framps01/Workspace/sport-store-test-framework/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/Users/framps01/Workspace/sport-store-test-framework/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! Test failed. See above for more details.
Can any one point me to where I'm going wrong? tennis_sport_schema.json is defined as an 'object' so not sure why the error is being thrown to suggest it isnt.
The first argument to addSchema needs to be an object, not a path to a json file.
.addSchema(Array<Object>|Object schema [, String key]) -> Ajv
source
so that would be:
let obj = {"$id": "mySuperSchema"}; //inc the rest of your json schema object.
ajv.addSchema(obj, 'mySuperSchema');
Alternatvily, it accepts an array of schema objects, assuming the $id is set in them correctly (second agument is then ignored).
Related
Crosspost from: https://repost.aws/questions/QUp5jDZ6bsRkeXhIwHgQaWkg/app-sync-request-mapping-template-errors-not-logged-in-cloud-watch
I have a simple resolver that has a simple Lambda function as a data source. This function always throws an error (to test out logging).
The resolver has request mapping template enabled and it is configured as follows:
$util.error("request mapping error 1")
The API has logging configured to be as verbose as possible yet I cannot see this request mapping error 1 from my CloudWatch logs in RequestMapping log type:
{
"logType": "RequestMapping",
"path": [
"singlePost"
],
"fieldName": "singlePost",
"resolverArn": "xxx",
"requestId": "bab942c6-9ae7-4771-ba45-7911afd262ac",
"context": {
"arguments": {
"id": "123"
},
"stash": {},
"outErrors": []
},
"fieldInError": false,
"errors": [],
"parentType": "Query",
"graphQLAPIId": "xxx"
}
The error is not completely lost because I can see this error in the query response:
{
"data": {
"singlePost": null
},
"errors": [
{
"path": [
"singlePost"
],
"data": null,
"errorType": null,
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "request mapping error 1"
}
]
}
When I add $util.appendError("append request mapping error 1") to the request mapping template so it looks like this:
$util.appendError("append request mapping error 1")
$util.error("request mapping error 1")
Then the appended error appears in the RequestMapping log type but the errors array is still empty:
{
"logType": "RequestMapping",
"path": [
"singlePost"
],
"fieldName": "singlePost",
"resolverArn": "xxx",
"requestId": "f8eecff9-b211-44b7-8753-6cc6e269c938",
"context": {
"arguments": {
"id": "123"
},
"stash": {},
"outErrors": [
{
"message": "append request mapping error 1"
}
]
},
"fieldInError": false,
"errors": [],
"parentType": "Query",
"graphQLAPIId": "xxx"
}
When I do the same thing with response mapping template then everything works as expected (errors array contains $util.error(message) and outErrors array contains $util.appendError(message) messages.
Is this working as expected so the $util.error(message) will never show up in RequestMapping type CloudWatch logs?
Under what conditions will errors array in RequestMapping log type be populated?
Bonus question: can the errors array contain more than 1 item for either RequestMapping or ResponseMapping log types?
I cannot find a way to set serializableCheck to false only for specific slice.
const store = configureStore({
reducer: {
ApiSignalMenu: ApiSignalMenuSlice.reducer,
ApiSignalData: ApiSignalDataSlice.reducer,
ApiHistoricalMenu: ApiHistoricalMenuSlice.reducer,
ApiHistoricalYearData: ApiHistoricalYearDataSlice.reducer,
ApiUpProbabilityMenu: ApiUpProbabilityMenuSlice.reducer,
ApiUpProbabilityData: ApiUpProbabilityDataSlice.reducer,
ApiMoverData: ApiMoverDataSlice.reducer,
ApiChartingMenu: ApiChartingMenuSlice.reducer,
ApiChartingData: ApiChartingDataSlice.reducer,
ApiTicker: ApiTickerSlice.reducer
},
// middleware: (getDefaultMiddleware) =>
// getDefaultMiddleware({
// serializableCheck: false
// }
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
serializableCheck: {
ignoredPaths: ['ApiMoverData.apiData.0'],
}
})
});
I have array data in : ApiMoverData
If I set : ignoredPaths: ['ApiMoverData.apiData.0'],
Then I got error again for A non-serializable value was detected in an action, in the path: payload.0. Value:, ApiMoverData
And
Then I got error again for Then I got error again for A non-serializable value was detected in the state, in the path: ApiMoverData.apiData.0
ApiMoverData.apiData.1, Then ApiMoverData.apiData.2, again.
How to set serializableCheck to false to all my array data in specific slice ?
This post : Is there a way to set the serializableCheck to false for one reducer only in redux?
did not tell a specific answer.
Thank You
EDIT :
My structure data looks like this :
Array [
ApiMoverData {
"change": "1,43",
"company": "Garuda Maintenance Facility Aero Asia Tbk.",
"id": 0,
"last": "71",
"ticker": "GMFI",
"value": "99.343.200",
"volume": "13.992",
},
ApiMoverData {
"change": "1,44",
"company": "Kimia Farma Tbk.",
"id": 1,
"last": "1.765",
"ticker": "KAEF",
"value": "956.208.000",
"volume": "5.433",
}
]
If I set : ignoredPaths: ['ApiMoverData.apiData']
Then I got error again for A non-serializable value was detected in an action, in the path: payload.0. Value:, ApiMoverData
And
Then I got error again for A non-serializable value was detected in the state, in the path: ApiMoverData.apiData.0
ApiMoverData.apiData.1, Then ApiMoverData.apiData.2, again.
Same Error
recomended by #phry do not use class instance in redux-toolkit. Because it will effect negative in future. Also we will not be able to use Redux-Persist. Just use non-class javascript object and store that.
I got the below error on call npm publish. I was trying publish an existing package on private feed:
npm ERR! Unexpected token u in JSON at position 0
My package.json:
{
"name": "XXXXXXXXXXXX",
"version": "0.0.6",
"description": "XXXXXXXXXXXX",
"types": "./types/index.d.ts",
"repository": {
"type": "git",
"url": "XXXXXXXXXXXX"
},
"engines": {
"cordovaDependencies": {
"0.2.3": {
"cordova": ">=3.1.0"
},
"4.0.0": {
"cordova": ">100"
}
}
}
}
To me, its happened because of the "engines" group in package.json. I removed it, and npm publish works.
I'm learning Nightwatch and have successfully got my first tests running. I'd now like to organise my tests a little better and use have a bunch of reusable common tests that I can build a main test with going forward. I've attempted to set this up using the code below but I'm not too familiar with Node exports, (truth be known I would prefer to use es6 import / export so if anyone can shed any light on this I'd be grateful) so I've probably made some fundamental error:
File structure
Tests
-auth
-- auth.js
index.js
nightwatch.json
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"selenium" : {
"start_process" : true,
"server_path" : "./bin/selenium-server-standalone-3.8.1.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./bin/chromedriver"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
package.json
{
"name": "mostesting",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test-e2e": "nightwatch"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-plugin-add-module-exports": "^0.2.1",
"nightwatch": "^0.9.19",
"selenium-webdriver": "^4.0.0-alpha.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.24.1"
}
}
index.js
const auth = require('./auth/auth.js')
module.exports = {
'Log into system': auth.login()
}
auth.js
exports.login = function (client) {
client
.url('http://myurl.co.uk')
.waitForElementVisible('body', 1000)
.assert.title('Reach - Log in')
.assert.visible('#UserName')
.setValue('#UserName', 'XXXX')
.assert.visible('#Password')
.setValue('#Password', 'XXXX')
.assert.visible('input[value="Login"]')
.click('input[value="Login"]')
.waitForElementVisible('img.test', 10000, false)
}
When I run the test it opens, it runs and passes but at the end I get the following console error:
OK. 6 assertions passed. (8.549s)
There was an error while starting the test runner:
TypeError: Cannot read property 'url' of undefined
at Object.exports.login (/Applications/MAMP/htdocs/mostesting/tests/auth/auth.js:3:5)
at Object.<anonymous> (/Applications/MAMP/htdocs/mostesting/tests/index.js:4:27)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at new Module (/Applications/MAMP/htdocs/mostesting/node_modules/nightwatch/lib/runner/module.js:7:23)
Please can anyone point me to where I'm going wrong?
Many thanks in advance.
When you're defining your test run, no need to call test run function auth.login(). What you need is to export this function, so Nightwatch can execute it:
// index.js
const auth = require('./auth/auth.js')
module.exports = {
'Log into system': auth.login
}
I'm converting our aurelia project to use aurelia-cli.
I added aurelia-18n, i18n and i18next-xhr-backend to aurelia-json but when I ran 'au build', I got error:
{ uid: 8,
name: 'writeBundles',
branch: false,
error:
{ [Error: ENOENT: no such file or directory, open 'd:\aurelia\src\relativeTim
e.js']
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'd:\\aurelia\\src\\relativeTime.js',
moduleTree: [ 'aurelia-i18n' ],
fileName: 'd:/aurelia/node_modules/aurelia-i18n/dist/amd/aurelia-i18n.js' }
,
duration: [ 1, 757878244 ],
time: 1469807422109 }
How do I overcome it? I do not use relativeTime, tried to add it but it required cldr-data which brought 240Mb to node_modules and still had the problem.
I've got advice how to configure i18n with aurelia-cli and it worked:
{
"name": "aurelia-i18n",
"path": "../node_modules/aurelia-i18n/dist/amd",
"main": "index"
},
{
"name": "i18next-xhr-backend",
"path": "../node_modules/i18next-xhr-backend/dist/umd",
"main": "i18nextXHRBackend"
},
{
"name": "i18next",
"path": "../node_modules/i18next/dist/umd",
"main": "i18next"
},