Example of using json-ref-resolver within docusaurus-json-schema-plugin #39
-
Hi, love the plugin thank you loads for it. Was wondering if you'd have an example for how to dereference. I have a schema that has two properties that ref from two other schemas. I have a .mdx that refs the base schema
Am I right in thinking that this type is correct? is it the uri that's incorrect or am I miles off? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @PaulHanlon, In the documentation, I have an example with a local dereference but you are right : a dereference with local file resolution might help how to use it to fit your case. Yes, this type is correct. One example could be : import CodeBlock from '@theme/CodeBlock';
import Schema from "@site/static/schemas/base.schema.json";
import JSONSchemaViewer from "@theme/JSONSchemaViewer";
import useBaseUrl from '@docusaurus/useBaseUrl';
const resolverOptions = {
resolvers: {
file: {
// Inspired by @stoplight/json-ref-readers
resolve: (ref: string) => {
return new Promise((resolve, reject) => {
// TODO
}
}
}
}
};
# assessment-v1.1.schema
<JSONSchemaViewer schema={Schema} resolverOptions={resolverOptions} />
# source :
<CodeBlock language="json">{JSON.stringify(Schema, null, 2)}</CodeBlock> And the related schema could be : {
"type": "object",
"properties": {
"prop1": { "$ref": "file://prop1-schema.json" },
"prop2": { "$ref": "file://prop2-schema.json" }
}
} Or {
"type": "object",
"properties": {
"prop1": { "$ref": "../models/user.json" },
"prop2": { "$ref": "./rank.json" }
}
} |
Beta Was this translation helpful? Give feedback.
-
@PaulHanlon I updated https://jy95.github.io/docusaurus-json-schema-plugin/docs/category/-references with valid examples of local / remote $ref. While it isn't a bulletproof solution to meet everyone needs ($ref handling can be quite complex), it should help to achieve 80% of what people want. If you or somebody else have ideas on how to improve it, be my guest ;) |
Beta Was this translation helpful? Give feedback.
@PaulHanlon I updated https://jy95.github.io/docusaurus-json-schema-plugin/docs/category/-references with valid examples of local / remote $ref.
While it isn't a bulletproof solution to meet everyone needs ($ref handling can be quite complex), it should help to achieve 80% of what people want. If you or somebody else have ideas on how to improve it, be my guest ;)