-
Notifications
You must be signed in to change notification settings - Fork 317
/
generate-schema.js
30 lines (26 loc) · 1.08 KB
/
generate-schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// joi-to-json-schema currently does not support v16 of Joi (https://github.com/lightsofapollo/joi-to-json-schema/issues/57)
const { convert } = require('@koa-lite/joi-schema')
const fs = require('fs')
const { schema } = require('../lib/schema')
const inputArguments = process.argv.slice(2) || []
const jsonSchema = {
title: 'JSON schema for Release Drafter yaml files',
id: 'https://github.com/release-drafter/release-drafter/blob/master/schema.json',
$schema: 'http://json-schema.org/draft-04/schema#',
...convert(schema()),
}
exports.jsonSchema = jsonSchema
// template is only required after deep merged, should not be required in the JSON schema
// we should also remove the required field in case nothing remains after the filtering to keep draft04 compatibility
const requiredField = jsonSchema.required.filter((item) => item !== 'template')
if (requiredField.length > 0) {
jsonSchema.required = requiredField
} else {
delete jsonSchema.required
}
if (inputArguments[0] === 'print') {
fs.writeFileSync(
'./schema.json',
`${JSON.stringify(jsonSchema, undefined, 2)}\n`
)
}