Skip to content

Commit

Permalink
errorschema fix (#208)
Browse files Browse the repository at this point in the history
* FIRECERT-2274-errorschema fix

* FIRECERT-2274-parse fix

* FIRECERT-2274-dummy commit

* FIRECERT-2274-reverted dummy commit
  • Loading branch information
Nandana-NNR authored Sep 2, 2024
1 parent 1b722d4 commit 80b6610
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/EventInvocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class EventInvocation {
let schemaValidationResult = {};
let schemaValidationStatus = CONSTANTS.PASS;
if (message.params.isNotSupportedApi == true) {
schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(listenerResponse);
schemaValidationStatus = CONSTANTS.FAIL;
}
registrationResponse['eventListenerSchemaResult'] = {
Expand All @@ -153,7 +153,7 @@ export class EventInvocation {
}
registrationResponse['eventListenerResponse'] = { result: null, error: listenerResponse };
// In case of error, validate error against errorschema
const schemaValidationResult = errorSchemaCheck(listenerResponse, process.env.COMMUNICATION_MODE);
const schemaValidationResult = errorSchemaCheck(listenerResponse);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
registrationResponse['eventListenerSchemaResult'] = {
status: CONSTANTS.FAIL,
Expand Down
4 changes: 2 additions & 2 deletions src/MethodInvoker.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class MethodInvoker {
if (process.env.STANDALONE == true) {
// if the method is not supported and it gives a valid response, validate against errorschema instead of api schema
if (message.params.isNotSupportedApi == true && response != undefined) {
schemaValidationResult = errorSchemaCheck(response, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(response);
}
}
} catch (error) {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class MethodInvoker {
let apiResponse, responseCode, schemaValidationStatus;
if (err) {
apiResponse = { result: null, error: err };
schemaValidationResult = errorSchemaCheck(err, process.env.COMMUNICATION_MODE);
schemaValidationResult = errorSchemaCheck(err);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
if (err.message != undefined && CONSTANTS.ERROR_LIST.includes(err.message)) {
responseCode = CONSTANTS.STATUS_CODE[3];
Expand Down
14 changes: 7 additions & 7 deletions src/Test_Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const utils = require('./utils/Utils');
import LifecycleHistory from './LifeCycleHistory';
import { Device } from '@firebolt-js/sdk';
import { MODULE_MAP } from './FireboltExampleInvoker';
import errorSchema from './source/errorSchema.json';
import errorSchemaObject from './source/errorSchema.json';
const $RefParser = require('@apidevtools/json-schema-ref-parser');
const Validator = require('jsonschema').Validator;
const validator = new Validator();
Expand All @@ -52,7 +52,7 @@ const TAG = '[Test_Runner]: ';
*/
let execMode;
let invokedSdk;
let errorSchemaBasedOnMode;
let errorSchemaValue;

/*
Start and End time of API invocation
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Test_Runner {
const resultStartTime = new Date();
let suiteStartTime = new Date();
let errorSchemaResult;
errorSchemaBasedOnMode = process.env.COMMUNICATION_MODE == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK];
errorSchemaValue = errorSchemaObject.errorSchema;

// This is the list of validation Results for each api ,This is the list that will be used for creating the report
for (const executionMode of execModes) {
Expand Down Expand Up @@ -204,9 +204,9 @@ export class Test_Runner {
}
if (this.methodFilters.isExceptionMethod(methodObj.name, example.params)) {
if (method.examples[exampleIndex].schema) {
method.examples[exampleIndex].schema = errorSchemaBasedOnMode;
method.examples[exampleIndex].schema = errorSchemaValue;
} else {
method.result.schema = errorSchemaBasedOnMode;
method.result.schema = errorSchemaValue;
}
}
if (communicationMode == CONSTANTS.TRANSPORT) {
Expand Down Expand Up @@ -1222,15 +1222,15 @@ export class Test_Runner {
let obj;
const NOT_SUPPORTED_ERROR_MESSAGES = ['Unsupported', 'Not supported', 'not supported'];
const errMessage = '{"code":' + error.code + ',"message":' + error.message + '}';
const schemaValidationResult = errorSchemaCheck(error, process.env.COMMUNICATION_MODE);
const schemaValidationResult = errorSchemaCheck(error);
if (schemaValidationResult && schemaValidationResult.errors && schemaValidationResult.errors.length > 0) {
obj = {
error: error,
param: example.params,
errorSchemaResult: true,
methodWithExampleName: methodWithExampleName,
methodUuid: this.createUUID(),
schemaData: errorSchemaBasedOnMode,
schemaData: errorSchemaValue,
apiExecutionStartTime: apiExecutionStartTime,
apiExecutionEndTime: apiExecutionEndTime,
};
Expand Down
2 changes: 0 additions & 2 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,4 @@ export const CONSTANTS = {
EXCLUDED_METHODS_FOR_MFOS: [],
...CONFIG_CONSTANTS,
VERSIONS: 'Versions',
ERROR_SCHEMA_TRANSPORT: 'errorSchemaTransport',
ERROR_SCHEMA_SDK: 'errorSchemaSDK',
};
76 changes: 21 additions & 55 deletions src/source/errorSchema.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,23 @@
{
"errorSchemaSDK": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": [
"code",
"message"
],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
},
{
"type": "string"
}
]
},
"errorSchemaTransport": {
"type": "object",
"additionalProperties": false,
"required": [
"code",
"message"
],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
"errorSchema": {
"type": "object",
"additionalProperties": false,
"required": ["code", "message"],
"properties": {
"code": {
"title": "errorObjectCode",
"description": "A Number that indicates the error type that occurred. This MUST be an integer. The error codes from and including -32768 to -32000 are reserved for pre-defined errors. These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api.",
"type": "integer"
},
"message": {
"title": "errorObjectMessage",
"description": "A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
},
"data": {
"title": "errorObjectData",
"description": "A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.)."
}
}
}
}
}
9 changes: 4 additions & 5 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { CONSTANTS } from '../constant';
import FireboltExampleInvoker from '../FireboltExampleInvoker';
import errorSchema from '../source/errorSchema.json';
import errorSchemaObject from '../source/errorSchema.json';
import censorDataJson from 'CensorData';

const { v4: uuidv4 } = require('uuid');
Expand Down Expand Up @@ -292,11 +292,10 @@ function filterExamples(programlist, programType, offeringType) {
return offeringList;
}

function errorSchemaCheck(err, communicationMode) {
function errorSchemaCheck(err) {
let schemaValidationResult;
if (errorSchema) {
const errorSchemaBasedOnMode = communicationMode == CONSTANTS.TRANSPORT ? errorSchema[CONSTANTS.ERROR_SCHEMA_TRANSPORT] : errorSchema[CONSTANTS.ERROR_SCHEMA_SDK];
schemaValidationResult = validator.validate(err, errorSchemaBasedOnMode);
if (errorSchemaObject) {
schemaValidationResult = validator.validate(err, errorSchemaObject.errorSchema);
}
return schemaValidationResult;
}
Expand Down

0 comments on commit 80b6610

Please sign in to comment.