Closed xddq closed 10 months ago
Hey @tet-lenovo,
Thanks for your writeup here. It helped me implement this way faster. Also, can you check if this branch fullfills your requirements?
Also (admittedly, this is a little late :D ). I would want to know why this feature should be added. Honest question, what is the difference between using X and Y here?
import { Static, Type } from "@sinclair/typebox";
export type T = Static<typeof T>;
export const T = Type.Object({ a: Type.Number() }, { $id: "T" });
export const X = Type.Object({ a: Type.Ref(T) });
export const Y = Type.Object({ a: T });
@xddq to answer the embarrassing question first, other than my apparent lack of knowledge, either X or Y would work for my situation. Otherwise, the code does seem to work.
As a follow up, we are using this for REST request and response validation and the way we currently have this structured, we will need all of the defined schema to have a $id defined so this is a good change regardless.
@tat-lenovo
Oh, I see.. I should ask beforehand for upcoming issues : D
Could you explain why the $id field is needed in your setup? I still don't see the need. Will probably merge this through after your response and release in the next couple of days. I am somewhat busy atm.
@tet-lenovo Hey!
Any update on this?
Sorry for the delay with this. With the holiday, I haven't been around much the last couple of weeks. Our main use case for this is that we use the generated schemas with AJV for request/response validation. When you register a schema with AJV, you either provide an ID or it will use the $id defined with the schema. So we don't have to maintain another ID, we use the $id generated with the schema.
@xddq Any idea when you plan to merge this code?
@tet-lenovo hey! Sorry, I did forget about it. Will probably have a look at merging (and publishing a new release) on thursday.
Summary
Based on issue #32 . This ensures that the generated typebox code will always contain an $id property. Additional test cases for checking the schemaOptions were added
TODO: