Closed floxay closed 1 year ago
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?
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 Example
instances for per field examples as those are not supposed to be OpenAPI Example Objects? Not sure where the logic for this is or what it looks like, just seems like a reasonable approach.
Based on "Edit 2": https://github.com/litestar-org/litestar/compare/main...floxay:litestar:exp/openapi-example-serialization
Seems to work but unsure about the Pydantic v2 json_schema_extra
callable stuff.
there should be a field called examples
: [...], I think. So this is a bug.
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 JsonSchemaExtraCallable
in Pydantic's ConfigDict.json_schema_extra
.
Additionally, while I were correcting some tests I've also noticed that the examples
field of OpenAPI Parameter Objects
is supposed to be a string
to Example Object | Reference Object
mapping, meaning the list litestar.Parameter
takes is somewhat problematic as example names cannot be provided to build the map.
Plus, currently these examples provided as Example
objects are serialized into ParamObj.schema.examples rather than ParamObj.examples:
Due to the above tests/unit/test_openapi/test_parameters.py::test_create_parameters
still fails in #2299
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
https://github.com/litestar-org/litestar/blob/3b3ed502de26bb945857fa8b94af45afdde7e075/litestar/openapi/spec/base.py#L22-L23
MCVE
Steps to reproduce
Screenshots
No response
Logs
No response
Litestar Version
2.0.1
Platform
Funding