在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:APIDevTools/json-schema-ref-parser开源软件地址:https://github.com/APIDevTools/json-schema-ref-parser开源编程语言:JavaScript 98.6%开源软件介绍:JSON Schema $Ref ParserParse, Resolve, and Dereference JSON Schema $ref pointersThe Problem:You've got a JSON Schema with {
"definitions": {
"person": {
// references an external file
"$ref": "schemas/people/Bruce-Wayne.json"
},
"place": {
// references a sub-schema in an external file
"$ref": "schemas/places.yaml#/definitions/Gotham-City"
},
"thing": {
// references a URL
"$ref": "http://wayne-enterprises.com/things/batmobile"
},
"color": {
// references a value in an external file via an internal reference
"$ref": "#/definitions/thing/properties/colors/black-as-the-night"
}
}
} The Solution:JSON Schema $Ref Parser is a full JSON Reference and JSON Pointer implementation that crawls even the most complex JSON Schemas and gives you simple, straightforward JavaScript objects.
Example$RefParser.dereference(mySchema, (err, schema) => {
if (err) {
console.error(err);
}
else {
// `schema` is just a normal JavaScript object that contains your entire JSON Schema,
// including referenced files, combined into a single object
console.log(schema.definitions.person.properties.firstName);
}
}) Or use try {
let schema = await $RefParser.dereference(mySchema);
console.log(schema.definitions.person.properties.firstName);
}
catch(err) {
console.error(err);
} For more detailed examples, please see the API Documentation InstallationInstall using npm: npm install @apidevtools/json-schema-ref-parser UsageWhen using JSON Schema $Ref Parser in Node.js apps, you'll probably want to use CommonJS syntax: const $RefParser = require("@apidevtools/json-schema-ref-parser"); When using a transpiler such as Babel or TypeScript, or a bundler such as Webpack or Rollup, you can use ECMAScript modules syntax instead: import $RefParser from "@apidevtools/json-schema-ref-parser"; Browser supportJSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may require Babel and/or polyfills. To use JSON Schema $Ref Parser in a browser, you'll need to use a bundling tool such as Webpack, Rollup, Parcel, or Browserify. Some bundlers may require a bit of configuration, such as setting API DocumentationFull API documentation is available right here ContributingI welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request. Building/TestingTo build/test the project locally on your computer:
LicenseJSON Schema $Ref Parser is 100% free and open-source, under the MIT license. Use it however you want. This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats. Big Thanks ToThanks to these awesome companies for their support of Open Source developers |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论