-
Notifications
You must be signed in to change notification settings - Fork 370
Implement recursive model validation #415
Comments
I'm not sure what version of swagger-tools you're using but this should be working. Here is the code that tells the validator to not stop after the first error: https://github.com/apigee-127/swagger-tools/blob/master/lib/helpers.js#L61 |
i'm using
|
Oh, I know what is up. Your model is circular and so the circular reference gets replaced with |
But swagger specs do not deny circular references. So is it something, which will be improved and allowed in the near future? |
In additional, schema above with the circular reference was successfully validated. So I want to understand where this restiction come from... |
Circular references are allowed, which is why your Swagger document does not get flagged as invalid. But when you want to validate a value against a schema defined in your Swagger document, circular references break any JSON Schema validator out there. swagger-tools uses z-schema and it will fail if you have a schema that is circular. In fact, we use to use jjv and it had the same limitation. So while Swagger and swagger-tools will work with circular references, validation against models that are circular are currently impacted by json-refs just turning the circular reference into a |
I'm wondering if json-ref could be replaced with something more tolerant to circular references? Like https://github.com/BigstickCarpet/json-schema-ref-parser |
No because the problem isn't tolerance, json-refs can gladly give you circular references. The issue is that the JSON Schema validator libraries fail using them so they have to be scrubbed somewhere and right now, json-refs is the place that happens...it's just too aggressive. |
Sadly to hear this :( Thanks for the explanations! |
Once json-refs is updated to better handle this, swagger-tools and sway will be updated. While it isn't to your liking, I hope the reasoning behind the issue makes sense. To reiterate, this isn't an issue with json-refs or Swagger or swagger-tools supporting circular references. The issue is that JSON Schema validation libraries do not handle circular references and so somewhere, they have to be scrubbed. The real fix is to make this configurable in json-refs, something that is already planned. As for |
Yeah, completely makes sense. So be waiting for updates. |
I plan on working on json-refs over the weekend. Hopefully I can get this sorted and get swagger-tools/sway updated as a result. |
would be amazing! |
@whitlockjc Has there been any progress on this? |
Resolver is done, rewriting tests. Once |
I have an obhect represented the tee of pages. It looks like this:
I'm trying to validate it with the following schema using
require('swagger-tools').specs.v2.validateModel()
method:It validates just root node for me and does not dive in depth (display error just about missed required "title" field at the top level; missing required "title" field for sub-item is not reported). Is there any chance to fix this?
The text was updated successfully, but these errors were encountered: