-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add reproducer for #20 #55
Conversation
This is the de facto way to run unit tests for most Python projects. The tox-poetry extension is used to provide integration with poetry. Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
This is a known bug. Add a test for it so we can work on fixing it. Signed-off-by: Stephen Finucane <stephen@that.guru> Related-bug: python-openapi#20
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=========================================
Coverage ? 78.78%
=========================================
Files ? 6
Lines ? 264
Branches ? 41
=========================================
Hits ? 208
Misses ? 46
Partials ? 10 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
def test_allof_nullable(self): | ||
schema = { | ||
"allOf": [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subschema is invalid (not nullable). That means the whole allof
should be invalid isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
"nullable": True, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/$defs/Pet", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subschema is invalid (not nullable). That means the whole allof should be invalid isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it? I'd have expected the reference this to flatten to:
{
"nullable": true,
"allOf": [
{
"required": ["id", "name"],
"properties": {
"id": {"type": "integer", "format": "int64"},
"name": {"type": "string"},
"tag": {"type": "string"}
}
}
]
}
which would in-turn flatten to:
{
"nullable": true,
"required": ["id", "name"],
"properties": {
"id": {"type": "integer", "format": "int64"},
"name": {"type": "string"},
"tag": {"type": "string"}
}
}
Is my understanding incorrect? It might well be! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, wait, I see your top-level comment now.
allOf can not be used to “extend” a schema to add more details to it in the sense of object-oriented inheritance. Instances must independently be valid against “all of” the schemas in the allOf. See the section on Extending Closed Schemas for more information.
json-schema.org/understanding-json-schema/reference/combining.html#allof
So this being the case, I wonder if the schemas should be outright rejected as invalid?
It looks like the case of the following:
https://json-schema.org/understanding-json-schema/reference/combining.html#allof |
Sorry for hugely delayed response here. I forgot about this 🙈 |
I think I have mentioned it somewhere in here, but this thread is worth a read OAI/OpenAPI-Specification#1368. Specifically, this comment suggests what I'm doing here as a workaround, and it seems from #20 that many people were expecting this workaround to work here as it did previously. I guess it would be good to either (a) start supporting that workaround again or (b) formally reject this workaround and insist users upgrade to OpenAPI 3.1 which works around this issue. fwiw, I just upgraded the project I was seeing this issue on to OpenAPI 3.1 and it was a relatively smooth process. |
Add a reproducer for #20. I was hoping to actually fix this issue in this PR, but I suspect fixing this will require more extensive changes than originally planned so I only add tests for now.
In addition to the reproducer for #20, I also add some other tests related to the nullable type, fix some typos in the README, and add a simple
tox.ini
file.PS: As a long-term fix for #20, I'm thinking that we could remove the
include_nullable_validator
function and instead do an initial one time scan of the schema, settingnullable = False
where it makes sense (i.e. wherever a sibling attribute wouldn't override it). To be able to do this though, we'd also need to do up front resolution of JSON references. I'm looking into this approach.Commits:
Add tox file
README: Correct some typos
tests: Add tests for nullable object type
tests: Add test for nullable refs