Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated schema to enforce skill levels. #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ section
.skill-level
th
font-weight: $semibold-weight
padding-right: 2 * $grid-height
padding-right: $grid-height
text-align: left
width: 6.4pc;
vertical-align: top;

.block
page-break-inside: avoid
Expand Down
19 changes: 19 additions & 0 deletions data/schema-ext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Resume Schema Extension for Test Double",
"type": "object",
"properties": {
"skills": {
"type": "array",
"items": {
"type": "object",
"properties": {
"level": {
"type": "string",
"enum": ["Teaching others", "Pairing on", "Excited about"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Learned something about JSON schemas, very cool that they can be extended this way.

I like the intention behind this, making clear that we don't find much value in using "level" to rank our skills/languages etc. These specific categories don't resonate with me though, so I am glad for now that validation doesn't stop the build ;-) More specifically, they actually apply very well to all the skills I want to list on my resume, I am excited about and love to pair and teach (and learn) all of them!

I have some ideas I would like to mess with, but I'll express them in the form of a PR once I get some time to work on it.

}
}
}
}
}
}
13 changes: 8 additions & 5 deletions lib/cobbler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var debug = require('debug')
var fs = require('fs')
var CSON = require('cson')
var CSON = require('cson-parser')
var hummus = require('hummus')
var jade = require('pug')
var marked = require('marked')
Expand All @@ -9,8 +9,9 @@ var nightmare = require('nightmare')
var path = require('path')
var traverse = require('traverse')
var url = require('url')
var validator = require('z-schema')
var validateAgainstSchema = require('./validate-against-schema')
var RESUME_SCHEMA = require('resume-schema/schema.json')
var RESUME_SCHEMA_EXT = require('../data/schema-ext.json')

module.exports = {
//
Expand All @@ -35,8 +36,10 @@ module.exports = {
}
})
.then(data => {
return validator.validate(data, RESUME_SCHEMA)
.then(_ => data)
return validateAgainstSchema(RESUME_SCHEMA, data)
})
.then(data => {
return validateAgainstSchema(RESUME_SCHEMA_EXT, data)
})
.then(data => {
debug('cobbler:load')('Data: %j', data)
Expand All @@ -46,7 +49,7 @@ module.exports = {
if (err.errors) {
throw new Error([err.message].concat(
err.errors.map(validationError => {
return validationError.path + ': ' + validationError.message
return validationError.dataPath + ': ' + validationError.message
})
).join('\n'))
}
Expand Down
24 changes: 24 additions & 0 deletions lib/validate-against-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var Ajv = require('ajv')

// See https://github.com/epoberezkin/ajv#using-version-6 for an explanation
// of these settings, which are required because JSONResume uses draft-04.
var ajv = new Ajv({
allErrors: true,
schemaId: 'id'
})
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'))

function validateAgainstSchema(schema, data) {
return Promise.resolve(ajv.validate(schema, data))
.then(function (valid) {
if (!valid) {
var error = new Error('Validation failed')
error.errors = ajv.errors
throw error
}

return data
})
}

module.exports = validateAgainstSchema
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"author": "Michael Schoonmaker <[email protected]> (https://www.schoonology.com/)",
"license": "MIT",
"dependencies": {
"cson": "^4.0.0",
"debug": "~2.3.3",
"ajv": "~6.2.1",
"cson-parser": "~3.0.0",
"debug": "~3.1.0",
"hummus": "~1.0.65",
"jstransformer-sass": "~0.1.0",
"jstransformer-sass": "~1.0.0",
"marked": "~0.3.6",
"minimist": "~1.2.0",
"moment": "~2.17.0",
"nightmare": "~2.8.1",
"moment": "~2.21.0",
"nightmare": "~3.0.0",
"pug": "~2.0.0-beta6",
"resume-schema": "0.0.16",
"temp": "~0.8.3",
Expand Down