Skip to content

Instantly share code, notes, and snippets.

@Dr-Emann
Last active December 17, 2015 21:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dr-Emann/5673379 to your computer and use it in GitHub Desktop.
Save Dr-Emann/5673379 to your computer and use it in GitHub Desktop.
Haxelib.json schema. Written in [json-schema](http://json-schema.org/)
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A haxelib project",
"type": "object",
"properties": {
"name": { "$ref": "#/definitions/name" },
"license": {
"description": "The open source license under which the project is licensed",
"enum": ["GPL", "LGPL", "BSD", "Public", "MIT"]
},
"tags": {
"type": "array",
"items": {
"type": "string",
"minLength": 2
},
"uniqueItems": true
},
"description": {
"type": "string",
"minLength": 2
},
"contributors": {
"type": "array",
"items": { "$ref": "#/definitions/name" },
"minItems": 1,
"uniqueItems": true
},
"releasenote": {
"type": "string",
"minLength": 2
},
"version": { "$ref": "#/definitions/semver" },
"url": {
"type": "string",
"format": "uri"
},
"dependencies": {
"type": "object",
"additionalProperties": { "$ref": "#/definitions/dependancyVersion" }
}
},
"additionalProperties": false,
"required": ["name", "license", "description", "releasenote", "contributors", "version"],
"definitions": {
"name": {
"description": "The name of a haxelib project",
"type": "string",
"minLength": 3,
"pattern": "[A-Za-z0-9_.-]{3,}"
},
"semver": {
"type": "string",
"pattern": "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-(alpha|beta|rc)(\\.([0-9]+))?)?$"
},
"dependancyVersion": {
"oneOf": [
{ "$ref": "#/definitions/semver" },
{
"type": "string",
"maxLength": 0
}
]
}
}
}
@jasononeil
Copy link

That mostly looks good. I'd say tags should have a minitems of 0. And for the "name" definition, there are reserved names: "all" and anything ending with ".hxml" or ".zip". Other than that this looks mostly correct. Do you think it would be hard to port a validator for this specification format to Haxe?

@Dr-Emann
Copy link
Author

Right, I guess it would be fine to be explicit that you have no tags. I left it out of the required attributes, but it does make sense to allow an empty array.

As for the specifics of what's allowed in a name, I think that might be outside of the scope of a schema. The schema is used to describe the structure of the JSON data file, not for functional constraints.

@Dr-Emann
Copy link
Author

Dr-Emann commented Jun 3, 2013

Made a few changes, dependencies are allowed to use empty strings to not require a specific version and the regex for a haxelib project name used - in the wrong spot (it was being interpreted as a range, instead of a literal dash.

I found a nice validator for javascript here. It looks like it wouldn't be too hard to port to Haxe, and it already supports v4 of the JSON-Schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment