Skip to content

Commit

Permalink
fix versions schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Jun 22, 2021
1 parent 04b6c07 commit c4d6ae7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const semverRange = {
conform: require('semver').validRange,
message: 'Must be a valid SemVer range'
}
const versionIds = Object.keys(require('./all-versions'))
const versionObjs = Object.values(require('./all-versions'))
const guideTypes = ['overview', 'quick_start', 'tutorial', 'how_to', 'reference']
const featureVersions = fs.readdirSync(path.posix.join(process.cwd(), 'data/features'))
.map(file => path.basename(file, '.yml'))
Expand Down Expand Up @@ -211,8 +211,9 @@ const featureVersionsProp = {
schema.properties.versions = {
type: ['object', 'string'], // allow a '*' string to indicate all versions
required: true,
properties: versionIds.reduce((acc, versionId) => {
acc[versionId] = semverRange
properties: versionObjs.reduce((acc, versionObj) => {
acc[versionObj.plan] = semverRange
acc[versionObj.shortName] = semverRange
return acc
}, featureVersionsProp)
}
Expand Down
9 changes: 7 additions & 2 deletions tests/helpers/schemas/feature-versions-schema.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const { schema } = require('../../../lib/frontmatter')

// Copy the properties from the frontmatter schema.
const featureVersions = Object.assign({}, schema.properties.versions)
const featureVersions = {
properties: {
versions: Object.assign({}, schema.properties.versions)
}
}

// Remove the feature versions properties.
// We don't want to allow features within features! We just want pure versioning.
delete featureVersions.properties.feature
delete featureVersions.properties.versions.properties.feature

// Call it invalid if any properties other than version properties are found.
featureVersions.additionalProperties = false
featureVersions.properties.versions.additionalProperties = false

module.exports = featureVersions

0 comments on commit c4d6ae7

Please sign in to comment.