Required properties in the models with inheritance
Closed this issue · 5 comments
There are such definitions in our spec:
Foo:
type: object
properties:
req2:
type: string
opt1:
type: string
Bar:
allOf:
- $ref: '#/definitions/Foo'
- type: object
required:
- req1
- req2
properties:
req1:
type: string
We created issue OAI/OpenAPI-Specification#1870 to clarify if above spec is valid. And got a positive answer. But only properties defined in the Bar entity are considered during the required properties check in the swagger-validator plugin. And I got the validation error.
Could I add properties from all ref-models from "allOf" definition section when VisitableModel is created in SemanticValidationService?
Hi @oyeli, I see your point and I think you are right. Honestly, I never thought about this possibility.
I had a look at the codebase and I think this is not an easy task. Anyway, if you have some ideas and want to submit a PR, I can help reviewing :)
Hi @giuliopulina! I want to submit PR for this issue. Could you please help me with the review: oyeli@23adb4f ?
I also add a small fix regarding consumes and produces sections. For example we have a spec:
swagger: '2.0'
info:
version: '2'
title: My spec
basePath: /path/2
produces:
- application/json
consumes:
- application/json
........
paths:
/actions1:
post:
consumes: []
/actions2:
post:
In case of "actions1" it's an error to specify "consumes[]", because post operation must have a payload. But in case of "actions2" there is no errors, because "consumes" is inherited from general section. But now we can't differ these two cases because in the OperationWrapper consumes (and produces as well) is initialized as new ArrayList<>().
I've left consumes and produces sections in OperationWraper non-initialized to be able to distinguish these two cases. Please look at com.github.sylvainlaurent.maven.swaggervalidator.semantic.node.path#OperationWrapper in the PR. What do you think about it?
Hi @oyeli, I had a look at your commit and I think that is good:
- Consumes/Produces change: I think you are right on it. It would be great if you can add a couple of unit tests (both valid and invalid cases) for this validation.
I think that, to be fully compliant with the spec, the validator should also check for validity of the mime type as specified here, but I don't know if there is any MimeType validator available in Java language:) - Required properties validation enhancement: I liked the idea to remove RequiredPropertiesValidator and merge the validation with InheritanceChainPropertiesValidator, it really simplifies things.
- Cyclic model reference validation: it seems OK to me.
Hi @giuliopulina! I've added MIME type validator with consumes and produces sections validation and tests for several cases. I've also added opportunity to specify custom MIME types in pom-configuration. Could you please look at my changes oyeli@09a6786?
PR #20 has been merged and release 1.2.6 published to maven central (may take a few hours).
Thanks everyone!