import Ajv from 'ajv' ; import * as apiTypes from './api-types' ; const SCHEMA = { "$schema" : "http://json-schema.org/draft-07/schema#" , "$ref" : "#/definitions/AuthorizedRequestQuery" , "definitions" : { "AuthorizedRequestQuery" : { "type" : "object" , "properties" : { "state" : { "type" : "string" } , "code" : { "type" : "string" } } , "required" : [ "state" , "code" ] , "additionalProperties" : false } } } ; const ajv = new Ajv ( { removeAdditional : true } ) . addSchema ( SCHEMA , "SCHEMA" ) ; export function validateAuthorizedRequestQuery ( payload ) { if ( ! isAuthorizedRequestQuery ( payload ) ) { const error = new Error ( 'invalid payload: AuthorizedRequestQuery' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isAuthorizedRequestQuery ( payload ) { /** Schema is defined in  SCHEMA . definitions . AuthorizedRequestQuery * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/AuthorizedRequestQuery" } ) ; return ajvValidate ( payload ) ; }