Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Using JsonSchema #35

Closed
VonD opened this issue Jun 18, 2014 · 7 comments
Closed

Using JsonSchema #35

VonD opened this issue Jun 18, 2014 · 7 comments

Comments

@VonD
Copy link

VonD commented Jun 18, 2014

I'm having trouble using JsonSchema : when i use the validate method, gavel seems to check for body identity : how can i only validate the schema ?
Is there a reason why the gavelmain module doesn't export JsonSchema?

Many thanks for your help.

@netmilk
Copy link
Contributor

netmilk commented Jun 30, 2014

Hi, gavel is not assuring json schema validity. There is no way how to validate schema itself in current gavel's API. It can be done by validating user provided schema against JSON Schema meta schema.

@VonD
Copy link
Author

VonD commented Jun 30, 2014

Ok. Many thanks for your answer.

@netmilk
Copy link
Contributor

netmilk commented Jun 30, 2014

Hi, I'm sorry I realised that's not bad idea at all to validate also schemas. I'll add it to gavel in next release.

@netmilk netmilk reopened this Jun 30, 2014
@honzajavorek
Copy link
Contributor

@netmilk I think Gavel should stay to be a tool to validate HTTP messages. To me, validating the schema seems to be a similar feature request as apiaryio/dredd#462 is for Dredd.

@artem-zakharchenko
Copy link
Contributor

artem-zakharchenko commented Jun 21, 2019

Isn't JSON schema parsed/validated during the Gavel's validation by third-party validators (TV4, Amanda)?

What is the status of this issue in regards to #90? If we adopt AJV, I expect it to throw upon invalid input. Gavel can handle that exception and, probably, present it in its public API.

@honzajavorek
Copy link
Contributor

I think this should be handled by the validator. Gavel checks if JSON Schema is a valid JSON document, but the validator should check whether it is a valid schema document. If it does not (does Amanda do that?), Gavel can use that schema's meta schema to validate whether the document complies with the schema spec. And AFAIK Gavel already does that in some cases, or at least the meta schemas are for some reason part of the package. Since @netmilk's comment is from 2014, my hunch would be this has been implemented, but the issue accidentally wasn't closed.

@artem-zakharchenko
Copy link
Contributor

I confirm JSON schemas of V3 and V4 being validated by tv4 (not Gavel) as a part of JsonSchema validator functionality:

const validationResult = tv4.validateResult(this.schema, metaSchema);
if (!validationResult.valid) {
throw new errors.JsonSchemaNotValid(
`JSON schema is not valid draft ${this.jsonSchemaVersion}! ${
validationResult.error.message
} at path "${validationResult.error.dataPath}"`
);
}

metaSchema is derived from the given expected JSON schema, and may be V3 or V4.

I would consider this issue closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants