Open gz-95 opened 1 year ago
I've just tried the example code from the README
on version v2.8.2
as follow:
const userSchema = {
$id: "http://example.com/schemas/user.json",
type: "object",
properties: {
name: { type: "string" },
age: { type: "integer" },
},
required: ["name", "age"],
additionalProperties: false,
} as const;
const usersSchema = {
type: "array",
items: {
$ref: "http://example.com/schemas/user.json",
},
} as const;
type Users = FromSchema<typeof usersSchema, { references: [typeof userSchema] }>;
// => {
// name: string;
// age: string;
// }[]
const anotherUsersSchema = {
$id: "http://example.com/schemas/users.json",
type: "array",
items: { $ref: "user.json" },
} as const;
const root = {
$ref: "http://example.com/schemas/users.json",
} as const;
type Root = FromSchema<
typeof root,
{
references: [typeof userSchema, typeof anotherUsersSchema];
}
>;
It seems Root
resolves to []
whereas I was expecting it to be { name: string; age: number; }[]
. I'm not really sure how references
is supposed to work at this point. Any help would be greatly appreciated!
Hello @gz-95 !
Good catch 👍 It seems like relative references work but only one-level deep (the README
example works but not yours), probably because the $id
is built by prefixing by the $ref
prefix (here http://example.com/schemas/
), which is not passed to the second reference.
I'll look into that ASAP and let you know!
Thanks for this really useful library! I was just wondering if this library supports relative references? The following is an example of what I'm trying to achieve:
Version
2.7.2
currently resolvesRoot
tonever
, whereas I was expecting it to resolve tonumber
.