Created
August 23, 2020 08:17
-
-
Save mgesmundo/07d6ea3958ed4c7d19d1161551fa46ca to your computer and use it in GitHub Desktop.
Vue cli 3 json schema loader with reference and pointer implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $RefParser = require('@apidevtools/json-schema-ref-parser') | |
/** | |
* Vue cli 3 usage example. | |
* | |
* // vue.config.js file | |
* module.exports = { | |
* chainWebpack: config => { | |
* config.module | |
* .rule('yaml') | |
* .test(/\.ya?ml?$/) | |
* .use('./path-to-this-file') | |
* .loader('./path-to-this-file') | |
* .end() | |
* .rule('json') | |
* .test(/\.json$/) | |
* .use('./path-to-this-file') | |
* .loader('./path-to-this-file') | |
* .end() | |
* } | |
* } | |
* } | |
* | |
* // App.vue file | |
* <template> | |
* <div> | |
* YOUR APP HERE | |
* </div> | |
* </template> | |
* | |
* <script> | |
* import yamlSchema from './assets/schema.yaml' | |
* import jsonSchema from './assets/schema.json' | |
* | |
* export default { | |
* created () { | |
* console.log('yamlSchema', yamlSchema) | |
* console.log('jsonSchema', jsonSchema) | |
* } | |
* } | |
* </script> | |
*/ | |
module.exports = async function () { | |
const parser = new $RefParser() | |
const schema = await parser.dereference(this.resourcePath, { | |
dereference: { | |
circular: false | |
} | |
}) | |
const resolve = await parser.resolve(this.resourcePath, { | |
dereference: { | |
circular: false | |
} | |
}) | |
for (const dep in resolve._$refs) { | |
this.addDependency(dep) | |
} | |
return JSON.stringify(schema) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment