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
Support for nullable property in OpenAPI 3 #86
Comments
workaround I'm using for null
|
Okay so I discovered something in plain sight that actually seems to have a big impact. Since the null union is a OpenAPI 3.1 feature (not 3.0), it is of course important that SwaggerUI is parsing 3.1. However, the default seems to be 3.0. Default and incorrect setup
Notice how it says "OAS 3.0" in the green badge up top of the web page. const app = new Elysia()
.use(swagger())
.post("/", () => "Hello Elysia", {
body: t.Object({
nullableString: t.Nullable(t.String()),
}),
})
.listen(3000); Changing the OpenAPI version for Swagger seems to make it handle the correct types that Corrected version matching
const app = new Elysia()
.use(
swagger({
documentation: {
openapi: "3.1.0", // Add this
},
})
)
.post("/", () => "Hello Elysia", {
body: t.Object({
nullableString: t.Nullable(t.String()),
}),
})
.listen(3000); I think the suggested fix here is to use 3.1.0 as the default version for Swagger unless otherwise specified, to be in sync with what the default format is from the schema generation. But perhaps there's some important reason why 3.0.3 is used instead that I'm not aware of. |
Yes, @Mudbill has the proper good workaround, worked for me. I also agree, that maybe |
I have model defined like
This generates expected type
TUnion<[TNumber, TNull]>
.And in OpenAPI I'm getting
OpenAPI spec says
So, the expected OpenAPI schema would be
SwaggerUI also has problem rendering model example, saying
"numericProp": "Unknown Type: null",
The text was updated successfully, but these errors were encountered: