-
Notifications
You must be signed in to change notification settings - Fork 165
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
How to get an object from Type.Object without Symbol(TypeBox.Kind)? #309
Comments
@benevbright Hi. You can use https://www.typescriptlang.org/play Keep me posted |
@sinclairzx81 Thanks for your support! Here you go. reproduce sample
|
By the way, as you pointed out, the symbol properties didn't seem the original cause. Thanks. |
@benevbright Hi, So, had a look. It seems as though the import { OpenAPIV3 } from "openapi-types"
const T2: OpenAPIV3.SchemaObject = {
foo: 'bar' // error: not permissive of additional properties
} You can work around this by using the const T2 = Type.Object({
name: Type.String(),
city: Type.Optional(Type.Union([Type.Null(), Type.String()])),
}) as OpenAPIV3.SchemaObject // use an `as` assertion here. It might be worth while submitting an issue on the I'd be interested to hear their thoughts, did you want to submit an issue and link back to this issue? |
@benevbright Actually, had a bit more of a look into this....There's something unusual happening with the way import { Type } from '@sinclair/typebox'
import { OpenAPIV3 } from "openapi-types"
// Ok
const A: OpenAPIV3.SchemaObject = Type.Union([Type.String()])
// Ok
const C: OpenAPIV3.SchemaObject = Type.Union([Type.Boolean()])
// Error: Type 'TUnion<[TNumber]>' is missing the following properties from type 'ArraySchemaObject': type, items
const B: OpenAPIV3.SchemaObject = Type.Union([Type.Number()])
// Error: Type 'TUnion<[TNull]>' is missing the following properties from type 'ArraySchemaObject': type, items
const D: OpenAPIV3.SchemaObject = Type.Union([Type.Null()]) Looking through their definitions, I can't see anything obvious standing out, but the above success and failure cases are curious, especially as the error is reporting that |
hm... it's openapi-types code. |
@benevbright Yeah, that's pretty much what I saw too :( Unfortunately, I can't think of a solution to this issue that would be truly ideal. In I will say, I feel the more "user friendly" solution here would be for I guess you could ask the const OK = Type.Union([Type.Null(), Type.String()]) as OpenAPIV3.SchemaObject It's not much of a solution, but I do hope this helps. Will leave this issue open for a day or so. If you do want to ping them an issue though, feel free to link back to this thread. |
Ok, actually the symbol is not a problem anymore. It was my bad. The problem is the fact that OpenApi doesn't support indeed there is no null type: https://swagger.io/docs/specification/data-models/data-types/#null
I didn't realize that openApi doesn't follow JSON schema. |
Ah ok. https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0 |
fastify/fastify-swagger#639 |
|
result
Hi,
it's not a big problem but these
[Symbol(TypeBox.Kind)]
properties give type error in some case.For example, I'm passing it to Fastify-swagger's schema.
Is there any way to omit these properties ? Thanks.
The text was updated successfully, but these errors were encountered: