From b24661b108ea6f4b9a7ab9c3cbc126e81281ce3b Mon Sep 17 00:00:00 2001 From: Swain Molster Date: Tue, 31 May 2022 15:23:14 -0400 Subject: [PATCH] fix: actually stop requiring request --- src/meta-schema.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/meta-schema.ts b/src/meta-schema.ts index 32be422..46c53d4 100644 --- a/src/meta-schema.ts +++ b/src/meta-schema.ts @@ -33,7 +33,7 @@ const ONE_SCHEMA_META_SCHEMA: JSONSchema4 = { '.*': { type: 'object', additionalProperties: false, - required: ['Name', 'Request', 'Response'], + required: ['Name', 'Response'], properties: { Name: { type: 'string', pattern: '[a-zA-Z0-9]+' }, Request: { @@ -52,6 +52,11 @@ const ONE_SCHEMA_META_SCHEMA: JSONSchema4 = { }; export const validateSchema = (spec: OneSchemaDefinition) => { + const ajv = new Ajv(); + if (!ajv.validate(ONE_SCHEMA_META_SCHEMA, spec)) { + throw new Error('Detected invalid schema: ' + ajv.errorsText(ajv.errors)); + } + for (const [name, { Request }] of Object.entries(spec.Endpoints)) { if (Request) { // Requests must be object type. @@ -162,11 +167,6 @@ export const loadSchemaFromFile = ( ): OneSchemaDefinition => { const spec = load(readFileSync(filename, { encoding: 'utf-8' })); - const ajv = new Ajv(); - if (!ajv.validate(ONE_SCHEMA_META_SCHEMA, spec)) { - throw new Error('Detected invalid schema: ' + ajv.errorsText(ajv.errors)); - } - validateSchema(spec as OneSchemaDefinition); return withAssumptions(spec as OneSchemaDefinition, assumptions);