-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Bundling schema with urn ID does not replace urn $ref #63
Comments
The However, there are a couple of unusual things happening here. First, I think it should be emitting a But, despite a couple ways that things are awkward when using URNs (I'll work on it), the resulting schema should work just fine. Are you getting errors when trying to use the bundled schema? |
Thanks for the quick reply! I would have thought that the What I am trying to do is get TypeScript types from my JSON Schema. I tried using json-schema-to-typescript, which uses json-schema-ref-parser under the hood to resolve references, but it couldn't find the other schemas, which makes sense as it doesn't have any way of registering schemas, so it can't resolve them based on the URN. Running the result schema from my earlier post into stack: 'ResolverError: Error opening file "urn:test:something/schemas/Address" \n' +
"ENOENT: no such file or directory, open 'urn:test:something/schemas/Address'\n" +
' at Object.read (/Users/andersbreilid/workspace/dnb-web-codd-apps/node_modules/.pnpm/@[email protected]/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/file.js:61:19)',
code: 'ERESOLVER',
name: 'ResolverError',
message: 'Error opening file "urn:test:something/schemas/Address" \n' +
"ENOENT: no such file or directory, open 'urn:test:something/schemas/Address'",
source: 'urn:test:something/schemas/Address',
path: null,
toJSON: [Function: toJSON],
ioErrorCode: 'ENOENT',
footprint: 'null+urn:test:something/schemas/Address+ERESOLVER+Error opening file "urn:test:something/schemas/Address" \n' +
"ENOENT: no such file or directory, open 'urn:test:something/schemas/Address'",
toString: [Function: toString] This error is the same as I would get using a non-bundled schema, naturally, as it cannot resolve the URN. {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "urn:test:something/schemas/CompanyCertificate",
"type": "object",
"title": "Company Certificate",
"description": "It's the Company Certificate",
"properties": {
"companyInformation": {
"type": "object",
"properties": {
"businessAddress": { "$ref": "urn:test:something/schemas/Address" }
}
}
},
"$defs": {
"Address": {
"$id": "urn:test:something/schemas/Address",
"type": "object",
"required": ["addressLine1", "postalCode", "postalPlace"],
"properties": {
"addressLine1": { "type": "string" },
"postalCode": { "type": "string" },
"postalPlace": { "type": "string" }
}
}
}
} They don't seem to be working towards implementing the JSON Schema spec as indicated in this thread, where they state that it is really a OpenAPI 3.0 tool. You might be correct in that the resulting JSON Schema should work, but I cannot find a tool that can generate types from it, at least not when using URNs. |
Yeah, Instead of using URNs, don't use use So, I think the following should work in
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"title": "Company Certificate",
"description": "It's the Company Certificate",
"properties": {
"companyInformation": {
"type": "object",
"properties": {
"businessAddress": {
"$ref": "./address/schema.json"
}
}
}
}
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["addressLine1", "postalCode", "postalPlace"],
"properties": {
"addressLine1": {
"type": "string"
},
"postalCode": {
"type": "string"
},
"postalPlace": {
"type": "string"
}
}
} And if you bundle, it should work in ajv. // No registering schemas needed
const bundledSchema = await bundle("./schemas/company-certificate.schema.json");
// Then load into ajv and validate Or you could use this library to do the validation without needing to bundle. // No registering schemas needed
const result = await validate("./schemas/company-certificate.schema.json", subject); |
Thanks, this seems like a good enough solution for now. Thanks for quick and detailed help! |
Hi,
I'm trying to bundle a schema with urn identifiers.
I added the urn plugin for
@hyperjump/browser
based on the example.The external schema (Address) is added to
$defs
in the resulting schema, but the$ref
is not changed to refer to$defs
.What am I doing wrong?
Combining the two following schemas:
With this code:
Results in this:
Thanks!
The text was updated successfully, but these errors were encountered: