-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Bug: Incorrectly serialized examples in OpenAPI schema #2272
Comments
Hello Sorry that I don't have much experience with OpenAPI yet. I would like to clarify that the correct serialization according to the OpenAPI specs is: {
"field1": "the answer",
"field2": 42
} Is that correct? |
you can see the openapi spec: https://spec.openapis.org/oas/latest.html#requestBodyObject |
I am actually not certain this bug report is correct- https://spec.openapis.org/oas/latest.html#exampleObject. We need a reproduction of this with openapi 3.1 schema that fails an up to date validator. |
Yes, this is a little bit confusing but I believe this is incorrect:
Edit: This seems to work and to me makes the most sense Edit 2: Maybe it's enough to just not make |
Based on "Edit 2": main...floxay:litestar:exp/openapi-example-serialization Pydantic v2 with `json_schema_extra`class TestBody(BaseModel):
field1: str = Field(examples=["the answer", "the other answer"])
field2: int = Field(examples=[42])
model_config = {
"json_schema_extra": {
"examples": [
{
"field1": "the answer",
"field2": 42
}
]
}
}
|
there should be a field called PR with a fix and proper tests is highly welcome. |
@floxay do you want to take this over? |
Sure, I think I can do it later today. |
Unfortunately I still have no clue how to resolve the Additionally, while I were correcting some tests I've also noticed that the
Due to the above |
Description
The provided example values are serialized incorrectly into the OpenAPI schema.
The issue seem to be that due to inheritance simply the
BaseSchemaObject.to_schema()
method is called forExample
instances during the schema serialization, because of this all of the fields ofExample
ends up being serialized under the example "section" instead of just the value of theExample.value
field.URL to code causing the issue
litestar/litestar/openapi/spec/base.py
Lines 22 to 23 in 3b3ed50
MCVE
Steps to reproduce
Screenshots
No response
Logs
No response
Litestar Version
2.0.1
Platform
Funding
The text was updated successfully, but these errors were encountered: