Skip to content

Commit

Permalink
Merge pull request #16 from lifeomic/actually-stop-requiring-request
Browse files Browse the repository at this point in the history
fix: actually stop requiring request
  • Loading branch information
swain authored May 31, 2022
2 parents 750327d + b24661b commit 25cbcab
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/meta-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25cbcab

Please sign in to comment.