-
-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing Validation: Inheritance #224
Comments
Yes, this is a problem.. but because I mainly use NJsonSchema for code generation (http://nswag.org) it was not an issue... |
The problem is that for validation we need oneOf inheritance (ie define the child classes): #13 ... and for swagger generation we need allOf inheritance (ie define parent classes) |
But oneOf inheritance is not supported by swagger (oneOf is not defined) |
As there is yet no real property inheritance / overwrite support in the json schema standard I handle validation with a custom json schema structure. For instance: I have two classes Person and Player. The Player class inherits all the properties from the Person class. Validaton should pass for instances of both classes. AddtionalProperties should be restricted. My working json schema looks as follows:
As you can see, I had to duplicate the Person properties within the Player schema and use a enum restricted Type string property as suggested here. Leaving out the allOf reference in the Player schema to the Person schema will somehow break the inheritance configuration, but using allOf does then only pass validation if I set addtionalProperties to true on the Person and Player schemas. Something I want to avoid. I also tried out other allOf, oneOf configurations and relocations of the Type property without any success. Property inheritance and overwrites are not yet supported. There might be a better approach here and I would be happy for any inputs. However, I am sure that the output provided by NJsonSchema does not yet create the json schema structure for the validations I need. |
Did you also try the FlattenInheritanceHierarchy option? |
For validation we need: #13 |
There seems to be a problem with the validation of inherited values.
By adding the following two lines of code
at the end of the test method When_JsonInheritanceConverter_is_used_then_inheritance_is_correctly_serialized_and_deserialized() validation will return 1 error.
Am I doing something wrong or is this a known issue?
The text was updated successfully, but these errors were encountered: