Comments (3)
While I'm not sure this is a bug in django-ninja per se (since the generated schema seems correct and that's what matters in the first place), I have found an ugly workaround to bring the dropdowns back thanks to Pydantic's json_schema_extra
. Leaving it here for anyone facing the same issue:
class MySchema(Schema):
my_enum: MyEnum
# my_opt_enum: MyEnum | None = None
my_opt_enum: MyEnum | None = Field(None, json_schema_extra={"enum": [e.value for e in MyEnum]})
π
This forcefully adds the "enum" spec right into the OpenAPI schema for my_opt_enum
:
{"in": "query", "name": "my_opt_enum", "schema": {"anyOf": [{"$ref": "#/components/schemas/MyEnum"}, {"type": "null"}], "enum": ["foo", "bar", "baz"]}, "required": false}
This workaround scales poorly and is ugly, so I would be glad to learn other solutions to this problem.
from django-ninja.
Is there a way to extend and overwrite schema generator classes to add extra json schema data?
from django-ninja.
When generating api clients, a $ref
is preferable in every single case, because the extracted types will rely on the schema components, and the enum should be referred to as the same type whether it is in the querystring, or somewhere else, otherwise the type extractions will create a new type just for this querystring param...
The swagger UI should not be the reference point for this...
The bug here is that sometimes, the schema does not use a $ref
for enums, not the other way around...
This is correctly done in FastAPI.
from django-ninja.
Related Issues (20)
- `get_openapi_schema` outputs types using `anyOf` style - doesn't work with the Swift OpenAPI generator HOT 1
- Error when trying to do django runserver -> pydantic.errors.PydanticSchemaGenerationError HOT 1
- [BUG] Using `pydantic.Json[SomeModel]` in a query param fails
- [BUG] Async Error Handlers Return Unawaited Coroutines Instead of HttpResponse in Django Ninja
- Dependency Injection support with `anydi`
- [BUG] `models.URLField` serialized & validated as `str` HOT 1
- Exceptions log level HOT 1
- [BUG] CustomParser request header issue when sending json and file
- [BUG] `ModelSchema` produces `id > (integer | null)` openapi HOT 1
- How to set query param for test.
- When are we getting a new release? HOT 3
- How to detect client disconnects on StreamingHttpResponse (Server Side Events)? HOT 4
- Support "Accept" & "Content-Type" Headers
- [BUG] no Response object generated for ASGI api route HOT 1
- Change settings access to support FastAPI-style single file apps
- How to test api.exception_handler
- Not required fields in FilterSchema
- Any way to run auth before route decorators?
- δΈζζζ‘£δΈηΊΏδΊ
- Some way to deal with auth
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-ninja.