-
Notifications
You must be signed in to change notification settings - Fork 19
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
Boolean JSON Schemas are not supported #4
Comments
According to https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object, although it claims to follow the 2020-12 draft, the examples much assume that the Schema is an object, instead of a pure Since the This issue should have no relation to |
Thanks for the quick response!
Not sure I'm reading this correctly but to me it sounds like the OpenAPI spec is referring to a schema as "objects, but also primitives and arrays", so in this case also booleans? The examples don't show this, but it's not invalid to the spec as far as I understand.
The issue here is how Whenever you generate a schema out of a Pydantic model in the As you then try to create Here's a code snippet that would reproduce this issue: from pydantic import BaseModel, Extra
class PyModel(BaseModel):
some_field: str
class Config:
extra = Extra.forbid
from pydantic.schema import schema
defs = schema([PyModel])
from openapi_schema_pydantic import Schema
Schema.parse_obj(defs["definitions"]["PyModel"]) The last line will throw the following error:
If you look at the schema for the model you'll see why: print(PyModel.schema_json(indent=2))
{
"title": "PyModel",
"type": "object",
"properties": {
"some_field": {
"title": "Some Field",
"type": "string"
}
},
"required": [
"some_field"
],
"additionalProperties": false
} Having said all this I completely sympathise with you, and respect that you may not want to complicate things. I have a workaround for this for now, but just thought you'd want to know that there is a perfectly valid scenario that will cause an exception. |
Thank you very much for the information. I didn't aware that Pydantic sets I will address this issue in upcoming release. |
Thanks @kuimono, to be honest I debated to submit an issue to Pydantic themselves, since like you say, having an object with Let me know if you need anything else from me! |
See https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.4.3.2 on the 2020-12 Draft, the values
false
andtrue
are valid JSON Schemas.Unless I'm mistaken, I think the
Schema
model (in v3.1.0, not sure if this applies to v3.0.1) should supportbool
as a type in all instances whereSchema
is allowed. E.g. changeUnion[Reference, "Schema"]
toUnion[Reference, "Schema", bool]
.Without the support of boolean schemas, using Pydantic classes as schemas fails if the Pydantic schema is configured with
extra = False
as this sets"additionalProperties": false
on the schema, but your model is only acceptingUnion[Reference, "Schema"]
.The text was updated successfully, but these errors were encountered: