json-schema additional metadata - javascript

It is possible to add additional or custom metadata (other than title and description) to a json schema property?
Ideally I'd like to add some metadata like so:
//...
"properties": {
"contactFullName": {
"$ref": "#/definitions/fullName",
"custom": "my custom metadata here"
}
}
//...
Can you add something to definitions to allow that?

You don't have to do anything special to use additional metadata keywords. You can just use them. In JSON Schema it is not an error to include undefined keywords. Anything that doesn't have JSON Schema semantics should be quietly ignored. So, the following schema is completely valid and should not conflict with any validator implementation.
{
"title": "Foo",
"description": "All the foo you can GET",
"version": "1.0.3",
"author": "Jason Desrosiers",
"type": "object",
"properties": {
"id": { "type": "string" }
}
}

You could use the description property and put a certain structure in there that could then be interpreted and applied as needed (like JSON within a JSON schema, so to speak).

Related

How to convert json to xml usin npm packages whic is jsontoxml

I want to convert json to xml. I already have used https://www.npmjs.com/package/xml-js npm package. Its output like :
<0>
<name>Autofac</name>
<version>
<Version>4.9.0.0</Version>
<SpecialVersion/>
</version>
<ProjectName>PIWorks.Son.UI.Migrations</ProjectName>
<licenseFile>C:\PIWorks\PISon.UI\licenses\NuGet\Autofac#4.9.0LICENSE.txt</licenseFile>
<repository>https://opensource.org/licenses/mit-license.php</repository>
</0>
But I want to use https://www.npmjs.com/package/jsontoxml
When I used this packages output like this:
<System.Threading.Timer/><System.ValueTuple/><System.Xml.ReaderWriter/><System.Xml.XDocument/><WebGrease/><YUICompressor.NET/>
I cannot understand anything what I am wrong.
Its also my json:
{
"name": "Autofac",
"version": {
"Version": "4.9.0.0",
"SpecialVersion": ""
},
"repository": "https://opensource.org/licenses/mit-license.php"
}
I need a help.

How to check file format before uploading a file in container using loopback-component-storage?

I have tried this way sample code.
I can successfully upload the file, but before that I have to validate file type and allow only *.csv files.
You can use mime node module for that.
https://www.npmjs.com/package/mime
You must complement sample code as follows:
Edit server/datasources.json, add to storage datasources
the allowedContentTypes field, an array of mime types that you want support
...
"storage": {
"name": "storage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "/var/www/storage",
"maxFileSize": "52428800",
"allowedContentTypes":["text/csv", "application/vnd.ms-excel"]
}
...
This step is optional but is a good practice. The error can be handled in callback, also can add a remote hook in the container model file common/models/container.js
module.exports = function (container) {
container.afterRemoteError('upload', function (ctx, next) {
//do any with ctx.error
});
}

Node-Red Editor and Library dependencies?

I'm in the process to create my first Node-RED contribution. The node will clean an incoming object based on a sample object provided in the editor. I'm using the RED.editor and the RED.library.
I'm wondering if I need to declare a dependency in my package file. Currently it looks like this:
{
"name" : "node-red-contrib-objectcleaner",
"version" : "0.0.1",
"description" : "Removes properties from incoming (payload) object, that are not in a template object",
"dependencies": { /*Do I need anything here? */
},
"keywords": [ "node-red", "validation", "flow" ],
"node-red" : {
"nodes": {
"objectcleaner": "objectcleaner/objectcleaner.js"
}
}
}
What, if anything, goes into the dependencies? I know I will put node.js dependencies there, but do I need to list the editor/library?
You'll probably do better asking questions like this on the mailing list here:
https://groups.google.com/forum/#!forum/node-red
You shouldn't need to list Node-RED in the dependencies as this will just pull in another copy into the node_modules tree.
You should be fine just using the reference to RED object that is passed in when the node is initialised

Kartograph: Map Creation fails

Recently I started using Kartograph. I am inexperienced in SVG, so the map creation is creating headaches for me. After initial trouble creating a world map that outlines country borders - similar to this - and a few other things(city regions and some decorating elements), my problem boils down to a undocumented - or at least I haven't found it in the docs - error. I guess it is related with my ignorance towards the kartograph.py framework.
The json file I provide Kartograph looks like that:
{
"proj": {
"id": "lonlat",
"lon0": 20,
"lat0": 0
},
"layers": {
"background": {
"special": "sea",
"charset": "latin-1",
"simplify": false
},
"graticule": {
"special": "graticule",
"charset": "latin-1",
"simplify": false,
"latitudes": 1,
"longitudes": 1,
"styles":{
"stroke-width": "0.3px"
}
},
"world":{
"src": "ne_50m_admin_0_countries.shp",
"charset": "latin-1",
"simplify": false
},
"lakes":{
"src": "Lakes.shp",
"charset": "latin-1",
"simplify": false
},
"trees":{
"src": "Trees.shp",
"charset": "latin-1",
"simplify": false
},
"depth":{
"src": "DepthContours.shp",
"charset": "latin-1",
"simplify": false
},
"cities":{
"src": "CityAreas.shp",
"charset": "latin-1",
"simplify": false
}
}
}
I know the output file will be huge and the generation will take ages, but it is just a test. I will experiment with the "simplify" option later. Much of the code in the file is based on this tutorial. Also, the empty simplify clause might not be necessary, but kartograph complained about the lack of the option, so I added it.
The command I use is this one:
kartograph world.json -o world.svg
It runs for some time(I guess, parsing all the input files etc.) before aborting. Now, the error I am facing is this one:
cli.py, in render_map()
71: K.generate(cfg, args.output, preview=args.preview, format=format, stylesheet=css) kartograph.py, in generate()
46: _map = Map(opts, self.layerCache, format=format) map.py, in __init__()
50: me.bounds_poly = me._init_bounds() map.py, in _init_bounds()
192: features = self._get_bounding_geometry() map.py, in _get_bounding_geometry()
257: charset=layer.options['charset']
get_features() got an unexpected keyword argument 'filter'
I tried looking at the file which throws the error(map.py), but I realized quickly that there's just too much interaction in the files for me to grasp things quickly.
I hope the data I provided is sufficient for someone more familiar with kartograph than me to track the error down.
UPDATE: The error is still valid. I tested it on both a MacBook Pro and an Asus Netbook now(Arch and Bodhi Linux, respectively).
Thanks in advance,
Carson
As far as I know, you can solve that problem by including a 'bounds' parameter. It is in deed very tricky, because according to the documentation (is it valid to call it 'documentation') this error should not appear, since the only required parameter is 'layers'. Also, how the bounds are defined depend apparently from the chosen projection. For your example I would use a simple polygon bounds.
I also had problems with that error. But, after many trials to set up everything, I noticed that apparently it only appears in the command-line version of Kartograph, and not when using Kartograph as a Python module in a script. I.e., try to include the json dictionary into a Python script where you import kartograph, like in the example here below.
I also put an example of filtering, for the record, because it was another thing that failed to work when using the command-line version of Kartograph.
# file: makeMap.py
from kartograph import Kartograph
K = Kartograph()
def myfilter(record):
return record['iso_a3'] in ["FRA","ITA","DEU"]
config = {
"layers": {
"mylayer": {
"src": "ne_50m_admin_0_countries.shp",
"filter": myfilter,
"attributes": {"iso_a3":"iso_a3", "name":"name", "id":"iso_a3"}
}
},
}
K.generate(config, outfile='world.svg')
Then, run the script as a Python script:
python makeMap.py

Implement js plugin for sublime text 2 using v8 plugin

I am trying to write plugins for sublime text 2 in javascript, using the v8 plugin. There is a demo javascript file called test.js, which seems to be a complete test plugin, but I can not figure out how to activate it.
Has anyone managed to write a plugin for sublime text 2 using javascript?
Is there another way to approach this? I mostly want to send text to javascript to be processed by my various libraries and then send text back.
EDIT:
I am using this project to get v8 working with sublime: https://github.com/akira-cn/sublime-v8
You can try this plugin https://github.com/akira-cn/SublimeJS
Follow example:
/** package.json **/
{
"name": "JSDemo",
"description": "demo plugin powered by SublimeJS",
"version": "0.1.0",
"author": {
"name": "akira-cn",
"email": "akira.cn#gmail.com"
},
"main": "index.js",
"licenses": [{
"type": "The MIT License",
"url": "http://www.opensource.org/licenses/mit-license.php"
}]
}
/** index.js **/
defineCommand("Hello", require("hello.command"));
/** hello.command.js **/
module.exports = function(view, edit) {
view.insert(edit, 0, "HelloWorld");
}
You can do that with node.js. Simple python wrapper should do the trick.
An example of plugin build with node.js: Sublime-HTMLPrettify

Categories